rules_cc icon indicating copy to clipboard operation
rules_cc copied to clipboard

rule-based example fails with linker error for gcc

Open Synss opened this issue 8 months ago • 0 comments

Running bazel test --config=gcc //... in examples/rule_based_toolchain fails with linker errors on HEAD and 0.1.1.

Reproduction

Simply following the instruction from the README, clang is successful:

$ cd examples/rule_based_toolchain
$ bazel test //...
# ... snip ...
//:quick_test                                                   (cached) PASSED in 0.0s

Executed 0 out of 1 test: 1 test passes.

The gcc toolchain fails to find m and mvec libraries in the sysroot

$ bazel test --config=gcc //...
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Analyzing: 67 targets (0 packages loaded, 0 targets configured)
Analyzing: 67 targets (0 packages loaded, 0 targets configured)
[0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt
INFO: Analyzed 67 targets (0 packages loaded, 0 targets configured).
ERROR: /home/mlaurin/src/bazel/rules_cc.git/examples/rule_based_toolchain/dynamic_answer/BUILD.bazel:34:18: Linking dynamic_answer/libshared_library.so failed: (Exit 1): x86_64-linux-g++.br_real failed: error executing CppLink command (from target //dynamic_answer:shared_library) external/_main~_repo_rules~gcc-linux-x86_64/bin/x86_64-linux-g++.br_real '--sysroot=external/_main~_repo_rules~gcc-linux-x86_64/x86_64-buildroot-linux-gnu/sysroot' -o ... (remaining 6 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/home/mlaurin/.cache/bazel/_bazel_mlaurin/be2a613b4744d0c5f527027df03074c5/external/_main~_repo_rules~gcc-linux-x86_64/bin/../lib/gcc/x86_64-buildroot-linux-gnu/13.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld: cannot find /lib64/libm.so.6: No such file or directory
/home/mlaurin/.cache/bazel/_bazel_mlaurin/be2a613b4744d0c5f527027df03074c5/external/_main~_repo_rules~gcc-linux-x86_64/bin/../lib/gcc/x86_64-buildroot-linux-gnu/13.3.0/../../../../x86_64-buildroot-linux-gnu/bin/ld: cannot find /lib64/libmvec.so.1: No such file or directory
collect2: error: ld returned 1 exit status
INFO: Elapsed time: 0.393s, Critical Path: 0.21s
INFO: 9 processes: 9 internal.
ERROR: Build did NOT complete successfully
//:quick_test                                                         NO STATUS

Executed 0 out of 1 test: 1 was skipped.

More info

Adding --sandbox_debug and searching for the libraries in the corresponding sandbox directory does find them

$ find . -name 'libm.so.6'
./execroot/_main/external/_main~_repo_rules~gcc-linux-x86_64/x86_64-buildroot-linux-gnu/sysroot/lib64/libm.so.6
./execroot/_main/external/_main~_repo_rules~gcc-linux-x86_64/x86_64-buildroot-linux-gnu/sysroot/lib/libm.so.6
$ find . -name 'libmvec.so.1'
./execroot/_main/external/_main~_repo_rules~gcc-linux-x86_64/x86_64-buildroot-linux-gnu/sysroot/lib64/libmvec.so.1
./execroot/_main/external/_main~_repo_rules~gcc-linux-x86_64/x86_64-buildroot-linux-gnu/sysroot/lib/libmvec.so.1

I also tried adding lib64 to the glob patterns in gcc.BUILD like so

diff --git a/examples/rule_based_toolchain/toolchains/gcc/gcc.BUILD b/examples/rule_based_toolchain/toolchains/gcc/gcc.BUILD
index 479a370..b3508bc 100644
--- a/examples/rule_based_toolchain/toolchains/gcc/gcc.BUILD
+++ b/examples/rule_based_toolchain/toolchains/gcc/gcc.BUILD
@@ -27,6 +27,7 @@ directory(
     name = "toolchain_root",
     srcs = glob([
         "lib/**",
+        "lib64/**",
         "x86_64-buildroot-linux-gnu/include/**",
     ]),
 )
@@ -56,6 +57,7 @@ filegroup(
     name = "linker_builtins",
     data = glob([
         "bin/*ld*",
+        "lib64/**/*.so*",
         "lib/**/*.a",
         "lib/**/*.so*",
         "lib/**/*.o",

but that didn't help.

Another error on HEAD

Note that this is reproducible on HEAD but there, the cc_make_variable feature triggers another error

Error in fail: @@//static_answer:answer: $(EXAMPLE_SUBSTITUTION) not defined

which is trivially avoided by commenting out copts like so

diff --git a/examples/rule_based_toolchain/static_answer/BUILD.bazel b/examples/rule_based_toolchain/static_answer/BUILD.bazel
index bc6d221..3c89a50 100644
--- a/examples/rule_based_toolchain/static_answer/BUILD.bazel
+++ b/examples/rule_based_toolchain/static_answer/BUILD.bazel
@@ -20,7 +20,6 @@ cc_library(
     name = "answer",
     srcs = ["static_answer.cc"],
     hdrs = ["public/static_answer.h"],
-    copts = ["$(EXAMPLE_SUBSTITUTION)"],
     includes = ["public"],
     linkstatic = True,
     visibility = ["//visibility:private"],

Synss avatar Apr 09 '25 16:04 Synss