Commit 89beca7
Fix cargo_build_script env vars from cargo_toml_env_vars for build script execution
Problem:
Build scripts for several crates were failing when using crate_universe
with generate_cargo_toml_env_vars=True (the default). The failures
occurred because CARGO_PKG_* environment variables extracted from
Cargo.toml were not being passed to build script execution.
Affected crates included:
- rav1e 0.7.1: Its build script depends on the built crate (0.7.7),
which calls std::env::var("CARGO_PKG_AUTHORS") at runtime and panics
if the variable is missing.
- typenum 1.19.0: Build script failed with "Wrong environment file
format" because CARGO_PKG_DESCRIPTION contained embedded newlines
escaped with backslashes.
Root causes:
1. Missing build_script_env_files in CargoBuildScript:
The render_one_build_file() function in rendering.rs correctly
populates build_script_attrs.build_script_env_files with the
":cargo_toml_env_vars" target. However, the CargoBuildScript struct
in starlark.rs lacked a build_script_env_files field, so this data
was never serialized to the generated BUILD.bazel files.
Note: rustc_env_files passes env vars to rustc for compile-time
env!() macro expansion. build_script_env_files passes env vars to
the build script binary at runtime for std::env::var() access.
2. Line continuation parsing in cargo_build_script_runner:
The cargo_toml_variable_extractor correctly escapes newlines in
values using backslash continuations (e.g., "value\\nmore").
However, the build script runner's env file parser split on '\n'
without handling continuations, causing lines like " compile
time." to fail the KEY=value format check.
Fix:
1. Add build_script_env_files field to CargoBuildScript struct and
populate it from build_script_attrs in make_cargo_build_script().
2. Update the env file parser to accumulate lines ending with '\'
before splitting on '=' to extract the key-value pair.
Fixes build failures for crates whose build scripts read CARGO_PKG_*
variables at runtime, including those with multiline descriptions.1 parent ca4915c commit 89beca7
3 files changed
Lines changed: 25 additions & 3 deletions
File tree
- cargo/private/cargo_build_script_runner
- crate_universe/src
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
103 | 105 | | |
104 | | - | |
105 | | - | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
109 | 122 | | |
110 | 123 | | |
111 | 124 | | |
| |||
115 | 128 | | |
116 | 129 | | |
117 | 130 | | |
| 131 | + | |
118 | 132 | | |
119 | 133 | | |
120 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
644 | 650 | | |
645 | 651 | | |
646 | 652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
0 commit comments