toolchains_llvm icon indicating copy to clipboard operation
toolchains_llvm copied to clipboard

Need to disable modules when using a different stdlib

Open samkellett opened this issue 6 months ago • 1 comments

The toolchain will pass in -Xclang -fno-cxx-modules already when using a recent enough LLVM however it only does this when stdlib == builtin-libc++. We've found that we need to do this when using GCC's libstdc++ as well.

It's easy enough for us to workaround by passing them in ourselves but perhaps the code in question (linked below) should be lifted out of stdlib conditional?

            # With C++20, Clang defaults to using C++ rather than Clang modules,
            # which breaks Bazel's `use_module_maps` feature, which is used by
            # `layering_check`. Since Bazel doesn't support C++ modules yet, it
            # is safe to disable them globally until the toolchain shipped by
            # Bazel sets this flag on `use_module_maps`.
            # https://github.com/llvm/llvm-project/commit/0556138624edf48621dd49a463dbe12e7101f17d
            cxx_flags.append("-Xclang")
            cxx_flags.append("-fno-cxx-modules")

https://github.com/bazel-contrib/toolchains_llvm/blob/d4592c5dcd/toolchain/cc_toolchain_config.bzl#L252

Our workaround:

llvm.toolchain(
    cxx_flags = {"linux-x86_64": [
        "-Xclang",
        "-fno-cxx-modules",
    ]},
    llvm_version = "20.1.2",
    stdlib = {"linux-x86_64": "stdc++"},
)

samkellett avatar Jun 19 '25 13:06 samkellett

Makes sense. Could you send a PR?

fmeum avatar Jun 19 '25 19:06 fmeum