Skip to content

PR #756 -imacros redacted_dates.h breaks rules_rust cargo_build_script with --strategy=CargoBuildScriptRun=local #771

Description

@jayakasadev

Summary

PR #756 injects -imacros external/toolchains_llvm++llvm+llvm_toolchain/redacted_dates.h into unfiltered_compile_flags. The path is sandbox-relative, which is fine for normal cc_library/cc_binary actions but breaks consumers that re-serialize toolchain flags into out-of-sandbox compiler invocations.

The most common surface: rules_rust cargo_build_script actions invoking cc-rs when --strategy=CargoBuildScriptRun=local is set. cc-rs calls cc_wrapper.sh with the toolchain's flags but resolves CWD outside the sandbox where external/... paths don't exist.

Reproducer

Any Rust target whose dep graph pulls a *-sys crate with a C build script (ring, libtcmalloc-sys, snmalloc-sys, etc.) plus:

# .bazelrc
build:linux --strategy=CargoBuildScriptRun=local

(--strategy=CargoBuildScriptRun=local is the recommended workaround for the libtcmalloc-sys sandbox-symlink issue, per rules_rust discussion.)

Failure

cargo:warning=<built-in>:1:19: fatal error: 'external/toolchains_llvm++llvm+llvm_toolchain/redacted_dates.h' file not found
cargo:warning=    1 | #__include_macros "external/toolchains_llvm++llvm+llvm_toolchain/redacted_dates.h"
cargo:warning=      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cargo:warning=1 error generated.

Reproduces on darwin-aarch64 + linux-x86_64. v1.8.0 (just released) carries PR #756, so every consumer that bumps past v1.7.0 is affected.

Cause

toolchain/internal/configure.bzl:841:

redacted_dates_path = "external/{}/redacted_dates.h".format(rctx.name),

The sandbox-relative path is correct for in-sandbox actions but unusable for any consumer that doesn't have cxx_builtin_include_files in its runfiles. rules_rust cargo_build_script_runner doesn't propagate cxx_builtin_include_files to local-strategy invocations.

PR #756's docstring foresaw this: "tools that re-serialize the toolchain's compile flags into their own build scripts (rules_foreign_cc make/cmake builds, embedded compiler-flag strings) drop the quotes" — the new -imacros form doesn't have the quote-loss bug but instead has an analogous file-path-loss bug for the same class of consumers.

Proposed fixes (pick one)

  1. Feature flag: Add a `disable_date_redaction` toolchain feature (default off). Consumers can enable it to skip the -imacros redacted_dates_path block. Smallest API surface; opt-in; ships immediately.
  2. Bazel-resolved absolute path: redacted_dates_path = str(rctx.path("redacted_dates.h")). Bakes machine-specific path into config — breaks remote execution cache.
  3. Restore -D__DATE__="redacted": revert PR Redact date macros via -imacros header instead of -D on command line #756. Trades cargo_build_script bug for rules_foreign_cc quote-loss bug.
  4. Bazel runfile path propagation: cooperate with rules_rust to propagate cxx_builtin_include_files to local-strategy cargo_build_script. Out of scope here.

Happy to send a PR implementing option 1 (disable_date_redaction feature) if maintainers want.

Environment

  • bazel 7.5.0
  • toolchains_llvm `332d6856` (current HEAD, v1.8.0 + 4 commits)
  • rules_rust 0.70.0
  • LLVM 21.1.8 / 20.1.8 (darwin-aarch64)
  • macOS 26.4 + Ubuntu 24.04 Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions