bazel-contrib / bazel-contrib/toolchains_llvm

cargo_build_script with local strategy re-serializes CC toolchain flags without the toolchain inputs

Open
#827 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
371
Forks
283
Avg merge
1d 55m
Merged PRs (30d)
25

Description

With `--strategy=CargoBuildScriptRun=local`, `cargo_build_script` passes the CC toolchain flags to `cc-rs`, which runs with a CWD outside the sandbox. The toolchain inputs are not propagated, so a flag that points at a toolchain file does not resolve.

We hit it with a force included header. The flag was `-imacros external/toolchains_llvm++llvm+llvm_toolchain/redacted_dates.h` and build scripts failed with: `fatal error: 'external/.../redacted_dates.h' file not found`

The reproducer is in the linked issue. Any target pulling a `*-sys` crate with a C build script, plus `--strategy=CargoBuildScriptRun=local`. Reported on bazel 7.5.0, rules_rust 0.70.0, on linux-x86_64 and darwin-aarch64. We did not reduce it to a rules_rust only case.

We reverted our side, so it is not urgent for us anymore. The gap stays though. `cargo_build_script_runner` does not propagate `cxx_builtin_include_files` to local strategy invocations, so the same happens with any toolchain flag that references a file.

There is a second half. Flag values that need quotes, for example `-D__DATE__="redacted"`, may lose the quotes on the way into the build script. Clang then sees a bare token and errors. We did not verify that part ourselves.

Contributor guide

Open the contributing guide

Research direction

Start by reading cargo_build_script_runner and the local CargoBuildScriptRun strategy path, then inspect the linked reproducer. Trace how cxx_builtin_include_files and quoted flag values are passed into local invocations. Done means toolchain-referenced flags resolve outside the sandbox and the reported quoting case is verified or clearly scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.