Skip to content

Conversation

@yanok
Copy link
Contributor

@yanok yanok commented Dec 5, 2025

There are two commits:

  • the first one is a very naive approach, just setting the CC variable to whatever the toolchain says is the compiler binary. This is clearly not enough for all cases, for example this doesn't work with toolchains_llvm for me.
  • the second one tries to be more sophisticated, also getting the compiler options from the cc_toolchain.

None of them are perfect, since the compiler options have to be filtered, also I haven't yet tested if it works on all platforms and whether cross-compilation works (not sure if it worked before this PR though, probably not).

Maybe we invert the direction here and instead of trying to give D compiler the correct way to call CC, try to link using the standard cc_common.link action, adding the standard D libraries to the inputs.

yanok added 3 commits December 4, 2025 17:33
Use `find_cpp_toolchain` from bazel_tools to find the current cc
toolchain and use the compiler from it for linking.

This is a bit naive, since we might need to add more flags to it.
But it seems to be enough with the local toolchain from rules_cc.
Try to be smarter about linking: use the cc_toolchain to get the
linking flags, filter some flags out and then pass the result
to the D compiler.

This works slightly better, allowing to use `toolchains_llvm` bazel
module.
@yanok yanok changed the title Use CC toolchain for linking Use CC toolchain for linking (updated branch name for CI) Dec 5, 2025
yanok added 2 commits December 5, 2025 17:02
It seems like we need to also depend on
`@rules_cc//cc:find_cc_toolchain_bzl`, which is a transitive dependency
of `@bazel_tools//tools/cpp:toolchain_utils.bzl`.
@yanok
Copy link
Contributor Author

yanok commented Dec 5, 2025

Ok, so it fails on Windows consistently, since DMD doesn't support -Xcc on Windows. We can disable passing the flags on Windows and hope it will work :) Personally, I don't care about Windows :)

Another error seems to be about missing transitive bzl dependency...

Copy link
Collaborator

@dcarp dcarp left a comment

Choose a reason for hiding this comment

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

Thanks!

@dcarp dcarp merged commit f21487d into bazel-contrib:main Dec 7, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants