Skip to content

Need to disable modules when using a different stdlib #510

@samkellett

Description

@samkellett

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++"},
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions