Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jul 16, 2024

From CMake docs:

When the CMAKE_SYSTEM_NAME variable is set explicitly to enable cross compiling then the value of CMAKE_SYSTEM_VERSION must also be set explicitly to specify the target system version.

This PR is split from #30454 and improves the current depends build subsystem.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 16, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK pablomartin4btc, vasild
Concept ACK theuni

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30712 (fuzz: Add missing fuzz targets to cmake build by maflcko)
  • #30685 (build: Mark x86_64-linux-gnu release binaries as CET-enabled by hebasto)
  • #30454 (build: Introduce CMake-based build system by hebasto)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@hebasto
Copy link
Member Author

hebasto commented Jul 16, 2024

It is a part of upfront PR'ed commits from #30454, as suggested by @fanquake offline.

cc @theuni @TheCharlatan @ryanofsky

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

My Guix build:

x86_64
460732347ffc71500f84d1174f6a6011b887681e82fc1704c1187cb1701bf9af  guix-build-5ff8074361e9/output/aarch64-linux-gnu/SHA256SUMS.part
b084b5371e3acff1850c8f3234299f99c3635fd497919f28407acaee27322877  guix-build-5ff8074361e9/output/aarch64-linux-gnu/bitcoin-5ff8074361e9-aarch64-linux-gnu-debug.tar.gz
9f0f40cb3510197338efca2c7423fb7615a34a8b21a90c500c7fa45898875a9d  guix-build-5ff8074361e9/output/aarch64-linux-gnu/bitcoin-5ff8074361e9-aarch64-linux-gnu.tar.gz
b571a25f1cf2c5f282342667823cdb5ed632e4b549361a46853414987091b1ce  guix-build-5ff8074361e9/output/arm-linux-gnueabihf/SHA256SUMS.part
758328c887a3b1233ff96c6ca867ad1e05cfbde376b17197ef69318307e19b9f  guix-build-5ff8074361e9/output/arm-linux-gnueabihf/bitcoin-5ff8074361e9-arm-linux-gnueabihf-debug.tar.gz
6628127da8fa423f23af5171f2e03b9afce5f579a08c4416de0cc8302fe841b6  guix-build-5ff8074361e9/output/arm-linux-gnueabihf/bitcoin-5ff8074361e9-arm-linux-gnueabihf.tar.gz
ead35c171f2b8a00d7755a8a18811ef3ee0567952b42c8a0de0a5647cd566a34  guix-build-5ff8074361e9/output/arm64-apple-darwin/SHA256SUMS.part
b872260bf88b6affc5c53fd0d0fa1aac7edb458902358cf64a6117dd0ecc29e0  guix-build-5ff8074361e9/output/arm64-apple-darwin/bitcoin-5ff8074361e9-arm64-apple-darwin-unsigned.tar.gz
443ff94fa3129b7e54ed58291d06fa708e812aa3b07937f9b8b9bcac9d93538c  guix-build-5ff8074361e9/output/arm64-apple-darwin/bitcoin-5ff8074361e9-arm64-apple-darwin-unsigned.zip
0c84027d40ee433eaf064f5198a6eaf01ade9cd5c75cc6534c8dc1ecedb89bd1  guix-build-5ff8074361e9/output/arm64-apple-darwin/bitcoin-5ff8074361e9-arm64-apple-darwin.tar.gz
9853a449e72c2e2b641b9f976d50b2d72a4a07876c25ba75812667a37366014a  guix-build-5ff8074361e9/output/dist-archive/bitcoin-5ff8074361e9.tar.gz
aee54f6d0e991040a02bd81d98d6034be922492dacd8275e6857a350be1628a1  guix-build-5ff8074361e9/output/powerpc64-linux-gnu/SHA256SUMS.part
9a9de9a7cd9fdd78552f59ffd812831e508b9c9a98125c8117168ad620f54eb5  guix-build-5ff8074361e9/output/powerpc64-linux-gnu/bitcoin-5ff8074361e9-powerpc64-linux-gnu-debug.tar.gz
4ce3ba8f2684bdf3c0821448f79b30bdc7cd6f30b6d403eb1a156b3cbaab8f88  guix-build-5ff8074361e9/output/powerpc64-linux-gnu/bitcoin-5ff8074361e9-powerpc64-linux-gnu.tar.gz
7feb0a0f3a830929dca504284478d0ab77cde22312fc695bdd4052a093084104  guix-build-5ff8074361e9/output/riscv64-linux-gnu/SHA256SUMS.part
f62b2b2d9a407bcef69a714fad8141f360da3edf05a431017f88157b2da4b916  guix-build-5ff8074361e9/output/riscv64-linux-gnu/bitcoin-5ff8074361e9-riscv64-linux-gnu-debug.tar.gz
385007a5fa879d508e3802c2034920125ec292c8f2385cc9c76eba0081fe5426  guix-build-5ff8074361e9/output/riscv64-linux-gnu/bitcoin-5ff8074361e9-riscv64-linux-gnu.tar.gz
2d03dd96e90c66c4ae9f75bf799da63132df7738bdac8f1c5b32cc2627d9344a  guix-build-5ff8074361e9/output/x86_64-apple-darwin/SHA256SUMS.part
6970c1003c5a635155dc2385169e4ac099a188cf448f55abaa82b94c8eaf961b  guix-build-5ff8074361e9/output/x86_64-apple-darwin/bitcoin-5ff8074361e9-x86_64-apple-darwin-unsigned.tar.gz
528a2da62a4312663de96166b82c37d361767eacc4c6e492d07282373110d2f1  guix-build-5ff8074361e9/output/x86_64-apple-darwin/bitcoin-5ff8074361e9-x86_64-apple-darwin-unsigned.zip
1ec8dc814de841757fdc45eb028d9df13f1b6f8e05f01642d76539920e16b400  guix-build-5ff8074361e9/output/x86_64-apple-darwin/bitcoin-5ff8074361e9-x86_64-apple-darwin.tar.gz
3691ba37e116c794860e7693c8b0f81e171319cc1e15f8cfc37a8336f1631dc1  guix-build-5ff8074361e9/output/x86_64-linux-gnu/SHA256SUMS.part
e0811eb91bfe9661e9dd7fb5fb2848729b7295db5237a9cff39e4fc2add46bf2  guix-build-5ff8074361e9/output/x86_64-linux-gnu/bitcoin-5ff8074361e9-x86_64-linux-gnu-debug.tar.gz
d9c2e29dd11f700b7ea1477e3c7564baf613ebdc5aa97e7ea6530d5115d5e95b  guix-build-5ff8074361e9/output/x86_64-linux-gnu/bitcoin-5ff8074361e9-x86_64-linux-gnu.tar.gz
1e0a09cd5edaf1c1613c75fc978170b5166a2e6a2009bec48591f85626a7b908  guix-build-5ff8074361e9/output/x86_64-w64-mingw32/SHA256SUMS.part
0c2dbb9553e81f0e30778be60e7b17b4727ded5518161e90b539ba5069052474  guix-build-5ff8074361e9/output/x86_64-w64-mingw32/bitcoin-5ff8074361e9-win64-debug.zip
f255226d5ecd3cfccfaa2b1f2c2ec98da015e47ddb08ef15339d6ea3fb9eb8ab  guix-build-5ff8074361e9/output/x86_64-w64-mingw32/bitcoin-5ff8074361e9-win64-setup-unsigned.exe
755903863b08594bba9ac52bb2a7e2e87ee077d0e8f777e7d9e768147fa9ce03  guix-build-5ff8074361e9/output/x86_64-w64-mingw32/bitcoin-5ff8074361e9-win64-unsigned.tar.gz
aa3cceab8c14f99d278ee628193ca9b3ff51343a658dcbc7dd141ebeac8e2ae3  guix-build-5ff8074361e9/output/x86_64-w64-mingw32/bitcoin-5ff8074361e9-win64.zip

@fanquake
Copy link
Member

What change in behaviour should be expected here?

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

What change in behaviour should be expected here?

For example, when building for macOS, the CMAKE_SYSTEM_VERSION value is used to define DARWIN_MAJOR_VERSION and DARWIN_MINOR_VERSION, which in turn affect the default build options.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, but we need more docs here.

  • I can't tell (even from looking at the CMake docs) what macOS should be set to and why you've chosen this value
  • I can only assume that the Linux value means "minimum kernel version" for the sake of kernel headers, but I don't see that in the docs either
  • Agree with @fanquake that it's not clear how this affects our other version vars. Which take precedence?

@@ -82,3 +82,6 @@ darwin_debug_CFLAGS=-O1 -g
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)

darwin_cmake_system_name=Darwin
# Darwin version, which corresponds to OSX_MIN_VERSION.
# See https://en.wikipedia.org/wiki/Darwin_(operating_system)
darwin_cmake_system_version=20.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where/how does CMake translate this to OSX_MIN_VERSION? Ideally we'd compose these somehow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where/how does CMake translate this to OSX_MIN_VERSION?

#30465 (comment):

... the CMAKE_SYSTEM_VERSION value is used to define DARWIN_MAJOR_VERSION and DARWIN_MINOR_VERSION...

It happens here:

# Darwin versions:
#   6.x == Mac OSX 10.2 (Jaguar)
#   7.x == Mac OSX 10.3 (Panther)
#   8.x == Mac OSX 10.4 (Tiger)
#   9.x == Mac OSX 10.5 (Leopard)
#  10.x == Mac OSX 10.6 (Snow Leopard)
#  11.x == Mac OSX 10.7 (Lion)
#  12.x == Mac OSX 10.8 (Mountain Lion)
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")

The chosen Darwin version 20.1 is associated with macOS 11.0:

OSX_MIN_VERSION=11.0

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit 6f9db1e
(master)
commit 73d4f33
(master and this pull)
SHA256SUMS.part 0d8cdb8c3167d4ff... 8e4a4b356e59fda3...
*-aarch64-linux-gnu-debug.tar.gz 40810c3e1935a80b... ba8611bde5454684...
*-aarch64-linux-gnu.tar.gz a4fe14ae14ad890b... 6866758249529fea...
*-arm-linux-gnueabihf-debug.tar.gz 321a865df293fb6a... 998fe87ec8278b25...
*-arm-linux-gnueabihf.tar.gz 97b9853189f57dc2... bdc7603d6c6db965...
*-arm64-apple-darwin-unsigned.tar.gz c3634e5d58dab037... 1888316c7e9c716e...
*-arm64-apple-darwin-unsigned.zip 45eb299b483de565... 3a43b515e5cf1f19...
*-arm64-apple-darwin.tar.gz 58c4513ff47d194f... e007a93066e02255...
*-powerpc64-linux-gnu-debug.tar.gz d954d21fce228c04... 0a443c861ae1db42...
*-powerpc64-linux-gnu.tar.gz b19e53cd361b804c... b4af9cfcd2bcf8c3...
*-riscv64-linux-gnu-debug.tar.gz fb68432434179030... 4e58a7b9045e096f...
*-riscv64-linux-gnu.tar.gz dc48cf50146c184a... 3c96a620bc40928e...
*-x86_64-apple-darwin-unsigned.tar.gz 229550ad3bebb1f5... 9751e1979e674ca6...
*-x86_64-apple-darwin-unsigned.zip 6078c435cbadd475... 128caa3bdbf7c4fc...
*-x86_64-apple-darwin.tar.gz e312cbdc559398da... a8fb27b7f5b39502...
*-x86_64-linux-gnu-debug.tar.gz d2089a6f223c00a4... f995f09f6e4eb194...
*-x86_64-linux-gnu.tar.gz 61af1710cb2143b9... c0dee5036e29693c...
*.tar.gz 131b6f2f5a3d17f2... e5c993c39d9a42fe...
guix_build.log 4f000735ce4f4184... 5fa6ddfb579b91ea...
guix_build.log.diff c96729dea80f71b2...

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

Concept ACK, but we need more docs here.

  • I can't tell (even from looking at the CMake docs) what macOS should be set to and why you've chosen this value

  • I can only assume that the Linux value means "minimum kernel version" for the sake of kernel headers, but I don't see that in the docs either

  • Agree with @fanquake that it's not clear how this affects our other version vars. Which take precedence?

I agree that the documentation is not comprehensive.

As for CMAKE_SYSTEM_VERSION value for Linux, I rely on the fact that its value is picked from uname output for native builds:

$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.22)
project(test LANGUAGES NONE)
message("${CMAKE_SYSTEM_VERSION}")
$ cmake -B build
6.8.0-38-generic
-- Configuring done (0.0s)
-- Generating done (0.0s)
...
$ uname -r
6.8.0-38-generic

However, I assume that the CMAKE_SYSTEM_VERSION is not used by the current CMake implementation for Linux builds.

@hebasto
Copy link
Member Author

hebasto commented Jul 17, 2024

Here is the previous discussion on this topic: hebasto#3 (comment).

In particular, @ryanofsky noted:

I think this doc is overgeneralizing. If you look at https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html you can see this variable only has meaning when cross compiling for windows and android

@fanquake
Copy link
Member

you can see this variable only has meaning when cross compiling for windows and android

Given, for example, that if you cross-compile for macOS, with this PR, you end up with different linker flags, this clearly has effect outside of Windows and Android.

@hebasto
Copy link
Member Author

hebasto commented Jul 26, 2024

Here is an opinion of a CMake maintainer from Professional CMake: A Practical Guide 18th Edition:

The CMAKE_SYSTEM_VERSION variable has different meanings depending on what CMAKE_SYSTEM_NAME is set
to. ... if CMAKE_SYSTEM_NAME is set to Android, then CMAKE_SYSTEM_VERSION will typically be interpreted
as the default Android API version and must be a positive integer. For other system names, it is not
unusual to see CMAKE_SYSTEM_VERSION set to something arbitrary like 1, or to not be set at all.
...
CMAKE_SYSTEM_PROCESSOR and CMAKE_SYSTEM_VERSION are not particularly meaningful for Apple
platforms and usually remain unset.

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5ff8074

As a reference, this was tested in hebasto/pull/125 (not triggering cross-compiling unnecessarily) and macOS cross build CI (hebasto/pull/94) is running with it since.

@DrahtBot DrahtBot requested a review from theuni August 2, 2024 15:11
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5ff8074 the changes look ok.

I just wonder, why the change to depends/funcs.mk is not in hebasto/cmake-staging, but is in this PR?

@hebasto
Copy link
Member Author

hebasto commented Aug 14, 2024

I just wonder, why the change to depends/funcs.mk is not in hebasto/cmake-staging, but is in this PR?

All changes to depends/funcs.mk from this PR must be ported to hebasto/cmake-staging.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@hebasto hebasto closed this Aug 28, 2024
@fanquake
Copy link
Member

Concept ACK, but we need more docs here.
I can't tell (even from looking at the CMake docs) what macOS should be set to and why you've chosen this value
I can only assume that the Linux value means "minimum kernel version" for the sake of kernel headers, but I don't see that in the docs either
Agree with @fanquake that it's not clear how this affects our other version vars. Which take precedence?

Where did this get followed up on?

@bitcoin bitcoin locked and limited conversation to collaborators Aug 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: ⭐ Prerequisites
Development

Successfully merging this pull request may close these issues.

7 participants