Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
davidzchen opened this issue May 24, 2024 · 6 comments · Fixed by #337

Comments

@davidzchen
Copy link

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
Copy link
Member

jsharpe commented Jun 5, 2024

#301 observes that this issue may have been introduced in #294 - can you try reverting that change and see if it works for you ok?

@jsharpe
Copy link
Member

jsharpe commented Jun 5, 2024

@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
Copy link
Member

fmeum commented Jun 6, 2024

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
Copy link
Member

jsharpe commented Jun 6, 2024

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
Copy link
Member

fmeum commented Jun 6, 2024

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
Copy link
Member

fmeum commented Jun 6, 2024

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

@fmeum fmeum closed this as completed in #337 Jun 6, 2024
fmeum added a commit that referenced this issue Jun 6, 2024
Otherwise Clang defaults to C++ modules with `-std=c++20`, which breaks
`layering_check`.

Fixes #334
copybara-service bot pushed a commit to bazelbuild/bazel that referenced this issue Jun 12, 2024
With `-std=c++20`, Clang defaults to using C++ modules rather than Clang modules, which can result in failures when using `layering_check` and thus `use_module_maps`.

Fixes bazel-contrib/toolchains_llvm#334

Closes #22660.

PiperOrigin-RevId: 642548168
Change-Id: Ie1dd4c482d716635f7b6c53ffd3c5d84b6aa8cc2
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Jun 12, 2024
With `-std=c++20`, Clang defaults to using C++ modules rather than Clang modules, which can result in failures when using `layering_check` and thus `use_module_maps`.

Fixes bazel-contrib/toolchains_llvm#334

Closes bazelbuild#22660.

PiperOrigin-RevId: 642548168
Change-Id: Ie1dd4c482d716635f7b6c53ffd3c5d84b6aa8cc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants