rnburn / rules_cc_module

Rules for using C++20 modules with bazel
Apache License 2.0
41 stars 3 forks source link

"bazel build //example/..." fails with error: "could not build module 'std_config'" #15

Open SlausB opened 2 years ago

SlausB commented 2 years ago

Hello! When I do:

git clone https://github.com/rnburn/rules_cc_module
cd rules_cc_module
./ci/run_docker.sh
bazel build //example/...

build fails with error:

root@2add72a9d097:/src# bazel build //example/...
2022/03/20 07:20:11 Downloading https://releases.bazel.build/5.0.0/release/bazel-5.0.0-linux-x86_64...
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
DEBUG: Rule 'bazel_skylib' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1611945497 -0500"
DEBUG: Repository bazel_skylib instantiated at:
  /src/WORKSPACE:5:15: in <toplevel>
Repository rule git_repository defined at:
  /root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel>
INFO: Analyzed 24 targets (44 packages loaded, 463 targets configured).
INFO: Found 24 targets...
ERROR: /src/example/multi_src_module/BUILD:79:10: Action example/multi_src_module/cc_module_interface-std.o failed: (Exit 1): driver failed: error executing command bazel-out/k8-opt-exec-2B5CBBC6/bin/util/driver/driver --object_out bazel-out/k8-fastbuild/bin/example/multi_src_module/cc_module_interface-std.o --module_map ... (remaining 32 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox
error: unable to open output file '/root/.cache/clang/ModuleCache/1VEKDVQVH77C4/std_config-1LRZ8JTHCNMTQ.pcm': 'No such file or directory'
While building module 'std':
In file included from <module-includes>:2:
/usr/lib/llvm-15/bin/../include/c++/v1/ctype.h:32:10: fatal error: could not build module 'std_config'
#include <__config>
 ~~~~~~~~^
2 errors generated.
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules/bazel-out/k8-opt-exec-2B5CBBC6/bin/util/driver/driver.runfiles/com_github_rnburn_bazel_cpp20_modules/util/driver/driver.py", line 30, in <module>
    main()
  File "/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules/bazel-out/k8-opt-exec-2B5CBBC6/bin/util/driver/driver.runfiles/com_github_rnburn_bazel_cpp20_modules/util/driver/driver.py", line 24, in main
    invoke_clang(driver_args, compiler, compiler_args)
  File "/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules/bazel-out/k8-opt-exec-2B5CBBC6/bin/util/driver/driver.runfiles/com_github_rnburn_bazel_cpp20_modules/util/driver/clang.py", line 104, in invoke_clang
    make_system_module(driver_args, compiler, interface_args)
  File "/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules/bazel-out/k8-opt-exec-2B5CBBC6/bin/util/driver/driver.runfiles/com_github_rnburn_bazel_cpp20_modules/util/driver/clang.py", line 80, in make_system_module
    subprocess.run(args, check=True)
  File "/usr/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/lib/llvm-15/bin/clang', '-cc1', '-triple', 'x86_64-pc-linux-gnu', '-emit-module', '-disable-free', '-clear-ast-before-backend', '-disable-llvm-verifier', '-discard-value-names', '-main-file-name', 'std.cc', '-mrelocation-model', 'pic', '-pic-level', '2', '-pic-is-pie', '-mframe-pointer=all', '-fmath-errno', '-ffp-contract=on', '-fno-rounding-math', '-mconstructor-aliases', '-funwind-tables=2', '-target-cpu', 'x86-64', '-tune-cpu', 'generic', '-debugger-tuning=gdb', '-fcoverage-compilation-dir=/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules', '-resource-dir', '/usr/lib/llvm-15/lib/clang/15.0.0', '-iquote', '.', '-U', '_FORTIFY_SOURCE', '-internal-isystem', '/usr/lib/llvm-15/bin/../include/c++/v1', '-internal-isystem', '/usr/lib/llvm-15/lib/clang/15.0.0/include', '-internal-isystem', '/usr/local/include', '-internal-isystem', '/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include', '-internal-externc-isystem', '/usr/include/x86_64-linux-gnu', '-internal-externc-isystem', '/include', '-internal-externc-isystem', '/usr/include', '-Wall', '-Wthread-safety', '-Wself-assign', '-Wunused-but-set-parameter', '-Wno-free-nonheap-object', '-Wno-builtin-macro-redefined', '-std=c++20', '-fdeprecated-macro', '-fdebug-compilation-dir=/root/.cache/bazel/_bazel_root/f8087e59fd95af1ae29e8fcb7ff1a3dc/sandbox/linux-sandbox/26/execroot/com_github_rnburn_bazel_cpp20_modules', '-ferror-limit', '19', '-stack-protector', '1', '-fgnuc-version=4.2.1', '-fmodules', '-fimplicit-module-maps', '-fmodules-cache-path=/root/.cache/clang/ModuleCache', '/usr/lib/llvm-15/lib/clang/15.0.0/include/module.modulemap', '-fmodule-file=_Builtin_stddef_max_align_t=bazel-out/k8-fastbuild/bin/example/multi_src_module/_Builtin_stddef_max_align_t.pcm', '-fmodules-validate-system-headers', '-fcxx-exceptions', '-fexceptions', '-fcolor-diagnostics', '-faddrsig', '-D__GCC_HAVE_DWARF2_CFI_ASM=1', '-o', 'bazel-out/k8-fastbuild/bin/example/multi_src_module/std.pcm', '-x', 'c++', '-fmodule-name=std']' returned non-zero exit status 1.
INFO: Elapsed time: 6.731s, Critical Path: 0.50s
INFO: 78 processes: 47 internal, 31 linux-sandbox.
FAILED: Build did NOT complete successfully

Or as image for better colorized view: Screenshot from 2022-03-20 11-43-34

What could be the reason? Thanks in advance!

SlausB commented 2 years ago

I changed install_bazel.sh from bazelisk to apt-way described in bazel docs:

curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list

apt update
apt install -y bazel
apt full-upgrade

and now it works! Dunno what could be the reason, because on host I also use bazelisk and it works fine. Thanks again for the awesome boilerplate!

rnburn commented 2 years ago

I looked briefly at this.

It looks like clang is using the module map from /usr/lib/clang/15.0.0/include/module.modulemap (which doesn't include std_config) instead of the module map from /usr/lib/llvm-15/include/c++/v1/module.modulemap (which includes std_config).

Something must have changed in the llvm setup and where the module maps are installed.