bazel-contrib / toolchains_llvm

LLVM toolchain for bazel
Apache License 2.0
283 stars 206 forks source link

Fatal error: module 'crosstool' is needed but has not been provided, and implicit use of module files is disabled #334

Closed davidzchen closed 1 month ago

davidzchen commented 2 months ago

I have a Bazel C++ repository where I am using toolchains_llvm. On macOS, it builds just fine, but on Ubuntu on WSL, I am getting the following error:

 bazel build //foo:file --verbose_failures
INFO: Analyzed target //foo:file (0 packages loaded, 0 targets configured).
ERROR: /home/dzc/.cache/bazel/_bazel_dzc/91609ad82b24e2d2bf2f015aee7bc9a4/external/com_google_absl/absl/base/BUILD.bazel:758:11: Compiling absl/base/internal/strerror.cc failed: (Exit 1): cc_wrapper.sh failed: error executing CppCompile command (from target @@com_google_absl//absl/base:strerror)
  (cd /home/dzc/.cache/bazel/_bazel_dzc/91609ad82b24e2d2bf2f015aee7bc9a4/sandbox/processwrapper-sandbox/23/execroot/_main && \
  exec env - \
    PATH='/home/dzc/.bin:/home/dzc/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/Users/david/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/david/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/david/.dotnet/tools:/home/dzc/go/bin:/usr/lib/go/bin:/home/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/lib:/home/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/history-substring-search:/home/dzc/.antigen/bundles/zsh-users/zsh-syntax-highlighting:/home/dzc/.antigen/bundles/zsh-users/zsh-completions:/home/dzc/.antigen/bundles/zsh-users/zsh-autosuggestions' \
    PWD=/proc/self/cwd \
  external/llvm_toolchain/bin/cc_wrapper.sh -U_FORTIFY_SOURCE '--target=x86_64-unknown-linux-gnu' -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign '-std=c++17' '-stdlib=libc++' -MD -MF bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/_objs/strerror/strerror.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/_objs/strerror/strerror.pic.o' -fPIC -iquote external/com_google_absl -iquote bazel-out/k8-fastbuild/bin/external/com_google_absl '-std=c++20' -Wall -Wextra -Wc++98-compat-extra-semi -Wcast-qual -Wconversion -Wdead-code-aggressive -Wfloat-overflow-conversion -Wfloat-zero-conversion -Wfor-loop-analysis -Wformat-security -Wgnu-redeclared-enum -Winfinite-recursion -Winvalid-constexpr -Wliteral-conversion -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wself-assign -Wshadow-all -Wshorten-64-to-32 -Wsign-conversion -Wstring-conversion -Wtautological-overlap-compare -Wtautological-unsigned-zero-compare -Wundef -Wuninitialized -Wunreachable-code -Wunused-comparison -Wunused-local-typedefs -Wunused-result -Wvla -Wwrite-strings -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-fdebug-prefix-map=external/llvm_toolchain_llvm/=__bazel_toolchain_llvm_repo__/' '-fmodule-name=com_google_absl//absl/base:strerror' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/strerror.cppmap' -fmodules-strict-decluse -Wprivate-header '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/llvm_toolchain/module-x86_64-linux.modulemap' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/config.cppmap' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/core_headers.cppmap' '-fmodule-map-file=bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/errno_saver.cppmap' -c external/com_google_absl/absl/base/internal/strerror.cc -o bazel-out/k8-fastbuild/bin/external/com_google_absl/absl/base/_objs/strerror/strerror.pic.o)
# Configuration: 65e079cc9605374bfc5e541e56ba82544aa2d7ae16e18af1bc83055f197d1f9e
# Execution platform: @@local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from external/com_google_absl/absl/base/internal/strerror.cc:15:
In file included from external/com_google_absl/absl/base/internal/strerror.h:18:
In file included from external/llvm_toolchain_llvm/bin/../include/c++/v1/string:519:
In file included from external/llvm_toolchain_llvm/bin/../include/c++/v1/__algorithm/max.h:12:
In file included from external/llvm_toolchain_llvm/bin/../include/c++/v1/__algorithm/comp.h:12:
external/llvm_toolchain_llvm/bin/../include/c++/v1/__config:261:14: fatal error: module 'crosstool' is needed but has not been provided, and implicit use of module files is disabled
#    include <features.h>
             ^
1 error generated.
Target //foo:file failed to build
INFO: Elapsed time: 3.589s, Critical Path: 3.24s
INFO: 10 processes: 10 internal.
ERROR: Build did NOT complete successfully

Here is the repository. I created a minimal repro case for this issue: https://github.com/davidzchen/bazel-ycm-test

Is there a misconfiguration on my part, and how do I fix this? Please let me know if there are any additional information I should provide to debug this.

jsharpe commented 1 month ago

301 observes that this issue may have been introduced in https://github.com/bazel-contrib/toolchains_llvm/pull/294 - can you try reverting that change and see if it works for you ok?

jsharpe commented 1 month ago

@fmeum - I've actually tracked this down to #280 - I'm not familiar with the process of using modules yet so not sure what the issue here is; can you take a look?

fmeum commented 1 month ago

The error goes away with --cxxopt=-std=c++17, so I suspect that clang is defaulting to C++20 modules rather than Clang modules with C++20 enabled, but Bazel only supports Clang modules. I didn't find a way to force the use of Clang modules even with C++20, but this needs to be fixed in Bazel itself.

jsharpe commented 1 month ago

So are you saying that we need to have clang module support on if using c++20? Before #280 this wasn't the case and if I back out that commit I can happily compile with c++20 (although layering_check seems broken without this as it fails to find the builtin headers in my project)

fmeum commented 1 month ago

Only if you use --features=layering_check. If I add --features=-layering_check to the reproducer, it also compiles just fine. Compiling with C++20 looks fine even with #280, it's just layering_check that is broken.

fmeum commented 1 month ago

This can be fixed with --cxxopt=-Xclang --cxxopt=-fno-cxx-modules. I will send a PR to add this to Bazel's toolchain configuration.