How to force @nixpkgs_foreign_cc//:make_nix_impl to be the preferred toolchain? #447
-
So I have load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")
load("@rules_nixpkgs_cc//:foreign_cc.bzl", "nixpkgs_foreign_cc_configure")
nixpkgs_cc_configure(
attribute_path = "clang_16",
repository = "@nixpkgs",
)
nixpkgs_foreign_cc_configure(
repository = "@nixpkgs",
) However, when I try to build something with Make or CMake, the toolchains from
I tried a combination of This is obviously not the most elegant solution, so I'm trying to figure out if there is a way to somehow, maybe, attach a constraint to all my build targets, and have it so that only the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Apparently adding the toolchains via the command line helps, e.g. in
This is because, according to the documented toolchain resolution order:
This still does not disable the built toolchains, but the ones provided by the |
Beta Was this translation helpful? Give feedback.
-
If you use rules_nixpkgs/testing/cc/MODULE.bazel Line 37 in 21c4ea4 Once we have module extensions for toolchains (#183) this should become easier. |
Beta Was this translation helpful? Give feedback.
-
The problem with the |
Beta Was this translation helpful? Give feedback.
-
To follow up on this, currently I'm using the This works for targeting the host architecture, but doesn't seem to work when cross compiling, because the @nixpkgs_foreign_cc_toolchain is not compatible with the target (exec) env. It probably should be, though, since the foreign toolchains, like CMake, Configure/Make, etc. can work, usually, just fine with a different underlying CC toolchain that would target a different platform, in my case, a WebAssembly target. It should be possible to e.g. use the Emscripten CC toolchain, or create a Wasi/Wasix toolchain, and use that as the CC toolchain, but keep using the same foreign CC toolchain. In any case, the only downside is that I get a duplicate copy of the foreign CC toolchains, and the ones in rules_foreign_cc are built by default, so on first run my compiles are a bit slower as I need to bootstrap everything. Once the cache is warmed up, it is usually fine though. |
Beta Was this translation helpful? Give feedback.
Apparently adding the toolchains via the command line helps, e.g. in
.bazelrc
:This is because, according to the documented toolchain resolution order:
This still does not disable the built toolchains, but the ones provided by the
@nixpkgs_foreign_cc_toolchain
repo will be prefer…