bazelbuild / examples

Examples for Bazel
http://bazel.build
Apache License 2.0
800 stars 497 forks source link

cpp-tutorial/stage1 bazel build looks for compiler in wrong /tmp path #394

Open WaiTsun-Yeung opened 6 months ago

WaiTsun-Yeung commented 6 months ago

Hello!

I was trying to build cpp-tutorial/stage1 on Ubuntu 22.04 with a bazel binary installed from the Bazel's apt repository, and it returned the following error:

(base) user@computer:/media/user/drive/repositories/bazel_examples/cpp-tutorial/stage1$ bazel build //main:hello-world --verbose_failures
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:hello-world (69 packages loaded, 6451 targets configured).
ERROR: /media/user/drive/repositories/bazel_examples/cpp-tutorial/stage1/main/BUILD:3:10: Compiling main/hello-world.cc failed: (Exit 127): gcc failed: error executing CppCompile command (from target //main:hello-world) 
  (cd /home/user/.cache/bazel/_bazel_user/57a42fc2a5495574ce64c6e247ef67dd/sandbox/linux-sandbox/1/execroot/_main && \
  exec env - \
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    PWD=/proc/self/cwd \
  external/gcc_toolchain_x86_64/bin/gcc -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/k8-fastbuild/bin/main/_objs/hello-world/hello-world.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/main/_objs/hello-world/hello-world.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools --sysroot external/sysroot_x86_64/ -no-canonical-prefixes -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-fdiagnostics-color=always' -nostdinc -nostdinc++ -Bexternal/gcc_toolchain_x86_64/bin -isystemexternal/sysroot_x86_64//include/c++/10.3.0 -isystemexternal/sysroot_x86_64//include/c++/10.3.0/x86_64-linux -isystemexternal/sysroot_x86_64//lib/gcc/x86_64-linux/10.3.0/include-fixed -isystemexternal/sysroot_x86_64//lib/gcc/x86_64-linux/10.3.0/include -isystemexternal/sysroot_x86_64//usr/include -c main/hello-world.cc -o bazel-out/k8-fastbuild/bin/main/_objs/hello-world/hello-world.pic.o)
# Configuration: 957e8b61236b28eb7e242f1293c1f3119632cdff86140ed1fb6bf77ff4547bca
# Execution platform: @@local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/gcc_toolchain_x86_64/bin/gcc: line 45: /tmp/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-gcc: No such file or directory
Target //main:hello-world failed to build
INFO: Elapsed time: 127.229s, Critical Path: 0.18s
INFO: 5 processes: 5 internal.
ERROR: Build did NOT complete successfully

I checked the bazel cache folder and found both

but I had trouble figuring out how to direct the build to reach the latter path.

Any help will be very much appreciated!

prasad-shirodkar commented 2 months ago

Relates to https://github.com/bazelbuild/bazel/issues/20533