-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cmake: Fix library ABI versioning #1270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sorry, I lost context here a bit. Can you explain again what the issue is and how it's fixed? |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a70165e..8216bad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,9 +17,9 @@ project(libsecp256k1 VERSION 0.3.2 LANGUAGES C)
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# All changes in experimental modules are treated as if they don't affect the
# interface and therefore only increase the revision.
-set(${PROJECT_NAME}_LIB_VERSION_CURRENT 2)
-set(${PROJECT_NAME}_LIB_VERSION_REVISION 2)
-set(${PROJECT_NAME}_LIB_VERSION_AGE 0)
+set(${PROJECT_NAME}_LIB_VERSION_CURRENT 3)
+set(${PROJECT_NAME}_LIB_VERSION_REVISION 0)
+set(${PROJECT_NAME}_LIB_VERSION_AGE 1)
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_EXTENSIONS OFF)
diff --git a/configure.ac b/configure.ac
index 0b555ea..acb923e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,9 +13,9 @@ define(_PKG_VERSION_IS_RELEASE, false)
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# All changes in experimental modules are treated as if they don't affect the
# interface and therefore only increase the revision.
-define(_LIB_VERSION_CURRENT, 2)
-define(_LIB_VERSION_REVISION, 2)
-define(_LIB_VERSION_AGE, 0)
+define(_LIB_VERSION_CURRENT, 3)
+define(_LIB_VERSION_REVISION, 0)
+define(_LIB_VERSION_AGE, 1)
AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_PATCH)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-dev]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1])
|
Can you add a comment that says that this emulates libtool, something like,
(quicklink here for any readers here who don't want to look it up: https://github.com/autotools-mirror/libtool/blob/1ec8fa28dcb29500d485c136db28315671ec4c3b/build-aux/ltmain.in#L7002 ) The problem I see here is that libtool's logic depends on the OS... :/ So, I think the changes here correctly emulate libtools on Linux. Have you checked this against libtool on MacOS too (including the Related: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html |
Checked. It doesn't look right. Investigating...
I've noticed this issue while working on Windows stuff :) |
To make versioning 100%-compatible with Libtool's scheme for macOS, UPD.
|
0efcf2a
to
069f9e0
Compare
Rebased on top of the #1230.
I've limited this PR to Linux platform explicitly, leaving other platforms discussion for follow ups. |
069f9e0
to
026b0ed
Compare
Thanks! Added. |
Concept ACK, but I fail to see how the current diff affects Linux only Given that you looked into this, what would you recommend for other problems? I think we could make it work on CMake 3.17+ and perhaps output a warning on lower versions (or document it somewhere else)? What about Windows? |
026b0ed
to
c6fd426
Compare
Reworked to be applied for all supported target platforms. Added a warning if the user is going to build macOS DYLIB using CMake < 3.17. |
src/CMakeLists.txt
Outdated
set_target_properties(secp256k1 PROPERTIES | ||
VERSION ${${PROJECT_NAME}_soversion}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION} | ||
) | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") | |
elseif(APPLE) |
Would this make a difference? (If not, I'm not sure if it's better ^^.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From CMake docs:
APPLE
Set to True when the target system is an Apple platform (macOS, iOS, tvOS or watchOS).
APPLE != OSX. Can we narrow this down some?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since MACHO_COMPATIBILITY_VERSION applies to all Apple platforms, I think that would actually be more correct in our case. (I guess in Core it doesn't matter that much, but for libsecp256k1 it's totally reasonable to build for embedded platforms.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated.
c6fd426
to
5a73030
Compare
Concept ACK. It's frustrating that they differ. Also, note that this is a case where a user gets worse binaries with older CMake, but I'm not sure we can do anything about that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested once more with the following diff: diff --git a/CMakeLists.txt b/CMakeLists.txt
index 91d2bed..22706d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,9 +17,9 @@ project(libsecp256k1 VERSION 0.3.2 LANGUAGES C)
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# All changes in experimental modules are treated as if they don't affect the
# interface and therefore only increase the revision.
-set(${PROJECT_NAME}_LIB_VERSION_CURRENT 2)
-set(${PROJECT_NAME}_LIB_VERSION_REVISION 2)
-set(${PROJECT_NAME}_LIB_VERSION_AGE 0)
+set(${PROJECT_NAME}_LIB_VERSION_CURRENT 1000)
+set(${PROJECT_NAME}_LIB_VERSION_REVISION 100)
+set(${PROJECT_NAME}_LIB_VERSION_AGE 10)
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_EXTENSIONS OFF)
diff --git a/configure.ac b/configure.ac
index 0b555ea..08d9b64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13,9 +13,9 @@ define(_PKG_VERSION_IS_RELEASE, false)
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# All changes in experimental modules are treated as if they don't affect the
# interface and therefore only increase the revision.
-define(_LIB_VERSION_CURRENT, 2)
-define(_LIB_VERSION_REVISION, 2)
-define(_LIB_VERSION_AGE, 0)
+define(_LIB_VERSION_CURRENT, 1000)
+define(_LIB_VERSION_REVISION, 100)
+define(_LIB_VERSION_AGE, 10)
AC_INIT([libsecp256k1],m4_join([.], _PKG_VERSION_MAJOR, _PKG_VERSION_MINOR, _PKG_VERSION_PATCH)m4_if(_PKG_VERSION_IS_RELEASE, [true], [], [-dev]),[https://github.com/bitcoin-core/secp256k1/issues],[libsecp256k1],[https://github.com/bitcoin-core/secp256k1])
On macOS:
A minor issue has been noted when cross-building for Windows. Going to address it shortly.
Let's fix and test the issue for Windows first :) |
5a73030
to
d2e4e18
Compare
Updated 5a73030 -> d2e4e18 (pr1270.05 -> pr1270.06, diff):
On Ubuntu 23.04 (with the diff from #1270 (comment)):
|
This change emulates Libtool to make sure Libtool and CMake agree on the ABI version.
d2e4e18
to
bef448f
Compare
set(${PROJECT_NAME}_windows "secp256k1") | ||
if(MSVC) | ||
set(${PROJECT_NAME}_windows "${PROJECT_NAME}") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding: Why does this need to be different on MSVC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSVC generator skips adding a "lib" prefix by default. See the item 2 in #1237 (comment) for additional details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK bef448f diff looks good and I tested on Linux
endif() | ||
set_target_properties(secp256k1 PROPERTIES | ||
ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME}_windows}" | ||
RUNTIME_OUTPUT_NAME "${${PROJECT_NAME}_windows}-${${PROJECT_NAME}_soversion}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake 3.27+ has DLL_NAME_WITH_SOVERSION
on the same purpose.
This change emulates Libtool to make sure Libtool and CMake agree on the ABI version.
To test, one needs to simulate a release with backward-compatible API changes, which means the following changes in
configure.ac
andCMakeLists.txt
:*_LIB_VERSION_CURRENT
*_LIB_VERSION_REVISION
to zero*_LIB_VERSION_AGE