From 26b5a7688529c283ba33f2b55520c94825120a3a Mon Sep 17 00:00:00 2001 From: Xiaoyi Shi Date: Fri, 15 May 2026 05:55:09 -0700 Subject: [PATCH] crate_universe: emit build_script_env_files on rendered cargo_build_script targets Fixes #4037. #3632 added the build_script_env_files attribute to cargo_build_script and wired it into BuildScriptAttributes + a `.insert(":cargo_toml_env_vars", ...)` call in the renderer when generate_cargo_toml_env_vars is set, but did not add a matching field to the `CargoBuildScript` starlark struct that gets Serialize-d into BUILD.bazel. The inserted value is silently dropped on the way to the rendered output, so build scripts that read CARGO_PKG_* at execution time (e.g. `built`, used by rav1e) still panic with `Missing expected environment variable "CARGO_PKG_AUTHORS"`. This change adds the field and populates it from attrs.build_script_env_files in make_cargo_build_script, mirroring the existing rustc_env_files plumbing. No new attributes; the rule and macro already accept build_script_env_files, the rendered BUILD.bazel just wasn't emitting it. Reproducer: https://github.com/ashi009/rules-rust-4037-repro --- crate_universe/src/rendering.rs | 6 ++++++ crate_universe/src/utils/starlark.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/crate_universe/src/rendering.rs b/crate_universe/src/rendering.rs index 49360d78ce..b066721d5a 100644 --- a/crate_universe/src/rendering.rs +++ b/crate_universe/src/rendering.rs @@ -641,6 +641,12 @@ impl Renderer { .unwrap_or_default(), platforms, ), + build_script_env_files: SelectSet::new( + attrs + .map(|attrs| attrs.build_script_env_files.clone()) + .unwrap_or_default(), + platforms, + ), rustc_flags: SelectList::new( // In most cases, warnings in 3rd party crates are not // interesting as they're out of the control of consumers. The diff --git a/crate_universe/src/utils/starlark.rs b/crate_universe/src/utils/starlark.rs index 14ff5f8c23..849a497ae3 100644 --- a/crate_universe/src/utils/starlark.rs +++ b/crate_universe/src/utils/starlark.rs @@ -98,6 +98,8 @@ pub(crate) struct CargoBuildScript { pub(crate) aliases: SelectDict, #[serde(skip_serializing_if = "SelectDict::is_empty")] pub(crate) build_script_env: SelectDict, + #[serde(skip_serializing_if = "SelectSet::is_empty")] + pub(crate) build_script_env_files: SelectSet, #[serde(skip_serializing_if = "Data::is_empty")] pub(crate) compile_data: Data, #[serde(skip_serializing_if = "SelectDict::is_empty")]