bazel-contrib / bazel-contrib/rules_foreign_cc
meson is incompatible with toolchains_llvm
- Dominant language
- Starlark
- Stars
- 737
- Forks
- 270
- PR merge metrics
- No merged PRs in 30d
Description
```shell
bazel build //third_party/cc/cairo --sandbox_debug --verbose_failures
INFO: Invocation ID: 57840238-22c7-432c-b10a-627a34fc26b3
INFO: Streaming build results to: http://localhost:8080/invocation/57840238-22c7-432c-b10a-627a34fc26b3
INFO: Analyzed target //third_party/cc/cairo:cairo (1 packages loaded, 242 targets configured).
ERROR: /Users/xiaoyishi/Projects/repo/third_party/cc/pixman/BUILD.bazel:3:6: Foreign Cc - Meson: Building pixman failed: (Exit 1): sandbox-exec failed: error executing CcMesonMakeRule command
(cd /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__ && \
exec env - \
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin \
TMPDIR=/var/folders/67/vhyv_gwn0pjd0fjm5jxd_6fh0000gn/T/ \
/usr/bin/sandbox-exec -f /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/sandbox.sb /var/tmp/_bazel_xiaoyishi/install/fd0e803cd377e5d6c999b9f309de8848/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/stats.out' /bin/bash -c bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/wrapper_build_script.sh)
rules_foreign_cc: Build failed!
rules_foreign_cc: Printing build logs:
_____ BEGIN BUILD LOGS _____
Bazel external C/C++ Rules. Building library pixman
Environment:______________
BUILD_SCRIPT=bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/build_script.sh
EXT_BUILD_ROOT=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__
BUILD_LOG=bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/Meson.log
PWD=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__
BUILD_WRAPPER_SCRIPT=bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/wrapper_build_script.sh
TMPDIR=/var/folders/67/vhyv_gwn0pjd0fjm5jxd_6fh0000gn/T/
EXT_BUILD_DEPS=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.ext_build_deps
BUILD_TMPDIR=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir
SHLVL=3
ZERO_AR_DATE=1
INSTALLDIR=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman
PATH=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
_=/usr/bin/env
__________________________
The Meson build system
Version: 1.5.1
Source dir: /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/pixman
Build dir: /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir
Build type: native build
Project name: pixman
Project version: 0.43.4
../../../../../../../external/pixman/meson.build:21:0: ERROR: Compiler /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain/bin/cc_wrapper.sh cannot compile programs.
A full log can be found at /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir/meson-logs/meson-log.txt
_____ END BUILD LOGS _____
rules_foreign_cc: Build wrapper script location: bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/wrapper_build_script.sh
rules_foreign_cc: Build script location: bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/build_script.sh
rules_foreign_cc: Build log location: bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman_foreign_cc/Meson.log
rules_foreign_cc: Keeping these below directories for debug, but note that the directories inside a sandbox
rules_foreign_cc: are still cleaned unless you specify the --sandbox_debug Bazel command line flag.
rules_foreign_cc: Build Dir: /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir
rules_foreign_cc: Deps Dir: /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.ext_build_deps
Target //third_party/cc/cairo:cairo failed to build
INFO: Elapsed time: 27.830s, Critical Path: 19.09s
INFO: 7 processes: 7 internal.
ERROR: Build did NOT complete successfully
INFO: Streaming build results to: http://localhost:8080/invocation/57840238-22c7-432c-b10a-627a34fc26b3
```
Manually invoking the build script with -v revealed this:
```shell
/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain/bin/cc_wrapper.sh sanitycheckc.c -o sanitycheckc.exe -Wl,-S -mmacosx-version-min=15.2 -no-canonical-prefixes -fobjc-link-runtime --target=aarch64-apple-macosx -lm -no-canonical-prefixes -headerpad_max_install_names -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/lib -lc++ -lc++abi -Bdynamic -Lexternal/llvm_toolchain_llvm/lib -Bstatic -lunwind --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -v
clang version 17.0.6
Target: aarch64-apple-macosx
Thread model: posix
InstalledDir: /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/bin
"/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/bin/clang" -cc1 -triple arm64-apple-macosx15.2.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -dumpdir sanitycheckc.exe- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sanitycheckc.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +aes -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +lse -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sha2 -target-feature +sha3 -target-feature +neon -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-abi darwinpcs -debugger-tuning=lldb -target-linker-version 1015.7 -v -fcoverage-compilation-dir=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir/meson-private -resource-dir /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/lib/clang/17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/local/include -internal-isystem /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/lib/clang/17/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include -fdebug-compilation-dir=/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin/third_party/cc/pixman/pixman.build_tmpdir/meson-private -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/67/vhyv_gwn0pjd0fjm5jxd_6fh0000gn/T/sanitycheckc-d7046f.o -x c sanitycheckc.c
clang -cc1 version 17.0.6 based upon LLVM 17.0.6 default target arm64-apple-darwin24.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/lib/clang/17/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -lto_library /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -headerpad_max_install_names -platform_version macos 15.2.0 15.2.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -o sanitycheckc.exe -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/lib -Lexternal/llvm_toolchain_llvm/lib /var/folders/67/vhyv_gwn0pjd0fjm5jxd_6fh0000gn/T/sanitycheckc-d7046f.o -S -lm -lc++ -lc++abi -lunwind -framework Foundation -lobjc -lSystem /private/var/tmp/_bazel_xiaoyishi/79c76c5b4224312419386af2e6f9c092/sandbox/darwin-sandbox/516/execroot/__main__/external/llvm_toolchain_llvm/lib/clang/17/lib/darwin/libclang_rt.osx.a
ld: warning: search path 'external/llvm_toolchain_llvm/lib' not found
ld: library 'unwind' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
The failure is due to toolchain_llvm configuring `-L` with a relative path for `libunwind`, and the build script `cd`ed into a non-exec root working directory for compilation.
This has not been an issue with `make` and other tools, and the relevant path conversion has been made in routines like `get_make_env_vars`, but meson is not using them. As a result, fix for https://github.com/bazel-contrib/rules_foreign_cc/issues/1271 is also not applied to meson.
Contributor guide
Research direction
Reproduce the reported Bazel build for //third_party/cc/cairo and inspect the Meson integration alongside the mentioned get_make_env_vars routines. Compare how Meson and make handle the toolchain_llvm library path; done means pixman and cairo build successfully with toolchains_llvm without the relative libunwind path failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100