Skip to content

Conversation

@willcl-ark
Copy link
Member

Fixes: #33859

Previously one had to read the Makefile (and various *.mk configuration
files) to see how to correctly override CC and CXX when building native
depends packages.

Detail this in README.md to make it clearer.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 18, 2025

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33902.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK hebasto, maflcko, ryanofsky

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #33593 (guix: Use UCRT runtime for Windows release binaries by hebasto)
  • #32162 (depends: Switch from multilib to platform-specific toolchains 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.

Copy link
Member

@hebasto hebasto 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. Thanks!

@willcl-ark
Copy link
Member Author

Forgot to say, very happy to drop the second commit if wanted.

To ensure both native and target use Clang:

```
make build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++
Copy link
Member

Choose a reason for hiding this comment

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

How is this better than make build_CC=clang build_CXX=clang++ CC=clang CXX=clang++?

Copy link
Member Author

Choose a reason for hiding this comment

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

They should be exactly equivalent.

I used my version as I had just described build_CC and host_CC and it would seem a little odd (to me) to exemplify with build_CC and CC, although as I re-read it now this example appears in the CC, CXX section.

I think therefore I should set make build_CC=clang build_CXX=clang++ CC=clang CXX=clang++ as the primary example for this section, and perhaps use make build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++ as an "ultimately explicit" final variation?

Copy link
Member

@hebasto hebasto Nov 19, 2025

Choose a reason for hiding this comment

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

In most situations where the compiler needs to be specified, users simply run:

make CC=clang CXX=clang++

Only in rare cases (#33902 (comment), #33902 (comment), #33902 (comment)) does this need to be extended to:

make CC=clang CXX=clang++ build_CC=clang build_CXX=clang++

Copy link
Member

Choose a reason for hiding this comment

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

Only in rare cases

I don't think wanting to build without having a GCC installation should be considered rare? Other than the clang-only Nix example linked too above, we are actively trying to make that "normal" for some of our builds, i.e #30206.

Copy link
Member

Choose a reason for hiding this comment

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

They should be exactly equivalent.

Unfortunately this isn't the case. make build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++ doesn't work properly on a machine with no g++, because Boosts CMake will still try and find g++, and fail. Arguably this is also a CMake issue that we should fix/workaround in some way, because there's no reason for Boost to try and find a compiler, when we aren't compiling anything, and only need to copy headers. In this case, you do need to use make build_CC=clang build_CXX=clang++ CC=clang CXX=clang++.

For example, on a Chimera Linux machine:

gmake build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++ -C depends/ -j12 build_TAR=gtar
gmake: Entering directory '/bitcoin/depends'
Extracting native_capnp...
/bitcoin/depends/sources/capnproto-cxx-1.2.0.tar.gz: OK
Preprocessing native_capnp...
Configuring native_capnp...
-- The CXX compiler identification is Clang 21.1.4
-- Detecting CXX compiler ABI info
<snip>
done
Configuring boost...
CMake Error at /usr/share/cmake-4.1/Modules/CMakeDetermineCXXCompiler.cmake:47 (message):
  Could not find compiler set in environment variable CXX:

  g++.

Call Stack (most recent call first):
  CMakeLists.txt:13 (project)


CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
gmake: *** [funcs.mk:344: /bitcoin/depends/aarch64-unknown-linux-musl/.boost_stamp_configured] Error 1

Using CC=clang CXX=clang++:

build_CC=clang build_CXX=clang++ CC=clang CXX=clang++ -C depends/ -j12 build_TAR=gtar
gmake: Entering directory '/bitcoin/depends'
Extracting native_capnp...
/bitcoin/depends/sources/capnproto-cxx-1.2.0.tar.gz: OK
Preprocessing native_capnp...
Configuring native_capnp...
-- The CXX compiler identification is Clang 21.1.4
<snip>
done
Configuring boost...
-- The CXX compiler identification is Clang 21.1.4
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost: using system layout: include, bin, lib/, lib//cmake

Copy link
Member Author

Choose a reason for hiding this comment

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

OK so having thought about this a bit more, my preference would be to not actually change the docs (as I have them in this PR), but to amend depends/host/default.mk to better respect when host_CC= host_CXX= have been set. I also posit that a setting of host_CC should override CC.

For depends, if I run make build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++ I expect to be able to build all host and native packages.

I also believe that if I run make build_CC=clang build_CXX=clang++ host_CC=clang host_CXX=clang++ CC=notacompiler CXX=notacompiler++, as host/build_CC/CXX have been defined and are more granular, they should be used over CC/CXX.

I think this commit here implements this, but makefile is really not my strongest suit and I could have easily not implemented what I wanted.

What are your thoughts on this approach?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that the host_$(tool) variables were ever meant to be set by users, and the same applies to build_$(tool).

(this is my understanding of the code as it was originally introduced; however, @theuni knows better)

More recently, it became clear that native packages also need a way to define their toolchains.

As #23571 didn’t gain enough support, I ended up using the "internal" build_$(tool) variables in 551e13a.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

lgtm

review ACK 17577646f77e20783ffdd9f322f85e96da2265 🌴

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 17577646f77e20783ffdd9f322f85e96da2265 🌴
b6tuB1ff+N8xGzUilBsW1CSxIOpk4gK7SE473C8JMS+vg4aU5H4YbP04c0HL3NEDxTZkxKFJBRcJ9RVAQ9t7DQ==

@DrahtBot DrahtBot requested a review from hebasto November 18, 2025 15:53
Example that may not work as expected (native tools still use GCC):

```
make CC=clang CXX=clang++
Copy link
Member

Choose a reason for hiding this comment

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

7f17cf6d6164460086afebbb0f921a7af4475bf9:

This example uses Makefile variable CC and CXX, but the section title refers to "Environment Variables". Both approaches work, of course, but the section could be made clearer.


Setting `CC` and `CXX` environment variables will override target compilers but **NOT** native tool compilers. Native tools will still use the default GCC unless explicitly overridden with `build_*` variables.

Example that may not work as expected (native tools still use GCC):
Copy link
Member

Choose a reason for hiding this comment

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

7f17cf6d6164460086afebbb0f921a7af4475bf9

This comes across as a bit discouraging and confusing. When I say “I build depends with Clang”, I’m referring to the host-specific packages. I’m not concerned about which compiler is used for the native tools, as long as they build without issues.

Copy link
Member

Choose a reason for hiding this comment

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

I’m not concerned about which compiler is used for the native tools, as long as they build without issues.

at least for me the issue was that they did not build at all, because the gcc version was ancient on OpenSuse Leap (or Alma Linux 8, ....)

Copy link
Member Author

Choose a reason for hiding this comment

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

If using something like a Nix devShell with no gcc available at all, compilation just fails too.

Copy link
Member

Choose a reason for hiding this comment

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

I’m not concerned about which compiler is used for the native tools, as long as they build without issues.

at least for me the issue was that they did not build at all, because the gcc version was ancient on OpenSuse Leap (or Alma Linux 8, ....)

The same issue occurs on NetBSD.

@DrahtBot DrahtBot requested a review from hebasto November 19, 2025 10:17

Skip the following packages if you don't intend to use the GUI and will build with [`NO_QT=1`](#dependency-options):

apt install bison g++ ninja-build pkgconf python3 xz-utils
```
apt install bison g++ ninja-build pkgconf python3 xz-utils
Copy link
Member

Choose a reason for hiding this comment

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

Other native package, not only native_qt, require g++.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but going to leave that from this PR for now.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK b1b559f83f629c7d0976c05d07cbc6ec04e84095.

@DrahtBot DrahtBot requested a review from maflcko November 19, 2025 11:38
Previously one had to read the Makefile (and various *.mk configuration
files) to see how to correctly override CC and CXX when building native
depends packages.

Detail this in README.md to make it clearer.
As we are touching the file use modern codeblock syntax throughout.
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

re-ACK 7dd714a.

@maflcko
Copy link
Member

maflcko commented Nov 19, 2025

re-ACK 7dd714a 🔔

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK 7dd714ae71fd18eda82ab4b43d4cecc047b87a2d 🔔
GdGC0CV1oagJPrWcSYTtdbnzJVbACdpgtwV3w0kHQgMB3ZEIhZNTp9Mr5d0DHvusR7eUHFQEauWPXPwpa0cUDw==

@maflcko
Copy link
Member

maflcko commented Nov 19, 2025

Could use doc: or build: prefix in title?

@willcl-ark willcl-ark changed the title Document compiler configuration for native depends packages doc: Document compiler configuration for native depends packages Nov 19, 2025
@DrahtBot DrahtBot added the Docs label Nov 19, 2025
Copy link
Member

@fanquake fanquake left a comment

Choose a reason for hiding this comment

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

@willcl-ark
Copy link
Member Author

See #33902 (comment).

As I describe here I have a commit which if host_CC is set, and** CC is unset, will set CC to host_CC (and similarly for CXX and friends).

In my opinion this would result in the expected behaviour:

  • If {var} is set, use that
  • If not check if host_{var} is set, and use that
  • Otherwise, fallback to a default

I don't see a use-case where someone purposefully setting host_{var} would ever expect {var} to take precedence for host buildilng, so don't think having both set would work "unexpectedly"?

@hebasto notes that these variables are apparently not supposed to be set by users though.

If that is the case, perhaps then instead of introducing more opinionated fallback heirarchies we should look at re-working how toolchains are defined more holistically? I don't see an obvious/clean approach not involving two sets of env vars though...

@hebasto
Copy link
Member

hebasto commented Dec 2, 2025

If that is the case, perhaps then instead of introducing more opinionated fallback heirarchies we should look at re-working how toolchains are defined more holistically? I don't see an obvious/clean approach not involving two sets of env vars though...

I agree that the depends build subsystem should accept two sets of variables: one for host/target-specific tools and another for native tools.

The naming for the former is well established (CC, CXX, etc) and it makes no senses to use anything else, as this is what developers, integration workflows and testing frameworks (such as OSS-Fuzz) expect.

For the latter, many projects use the $(tool)_FOR_BUILD pattern, which we might also adopt.

@hebasto
Copy link
Member

hebasto commented Dec 4, 2025

Previously one had to read the Makefile (and various *.mk configuration
files) to see how to correctly override CC and CXX when building native
depends packages.

I also wanted to highlight the distinction between environment variables and Makefile variables. There should be no difference in behaviour between the two when supplied by the user, provided they are recognised by the build system. But that is not currently the case. See: #29963.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 7dd714a. Nice documentation improvement.

I'm a little confused about hebasto's comments #33902 (comment) and #33902 (comment) which seem to say we should not recommend setting variables like host_CC and host_CXX because setting CC and CXX does the same thing and these are more standard. If so, would it be better for README.md to remove the host_ prefixes? I assume current version is ok given the ACKs, but this seems like something that would be good to follow up on or at least respond to.

Also fanquake's comment #33902 (comment) seems to say that setting CC/CXX works better than host_CC/host_CXX in practice? So maybe the readme should be updated to just drop the host_ prefix entirely if the host_ prefixed variables are less standard and don't work as well as the unprefixed variables.

@hebasto
Copy link
Member

hebasto commented Dec 15, 2025

I'm a little confused about hebasto's comments #33902 (comment) and #33902 (comment) which seem to say we should not recommend setting variables like host_CC and host_CXX because setting CC and CXX does the same thing and these are more standard.

Yes. That's my point.

Also fanquake's comment #33902 (comment) seems to say that setting CC/CXX works better than host_CC/host_CXX in practice? So maybe the readme should be updated to just drop the host_ prefix entirely if the host_ prefixed variables are less standard and don't work as well as the unprefixed variables.

I'll support such changes once someone proposes them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

depends: native_capnp picks system gcc, not CC/CXX

6 participants