-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: avoid inserting duplicate dylib_path_envvar
when calling cargo run
recursively
#14464
Conversation
tests/testsuite/build.rs
Outdated
if std::env::var("SUB").is_ok() {{ | ||
let paths = match std::env::var_os("{}") {{ | ||
Some(var) => std::env::split_paths(&var).collect(), | ||
None => Vec::new(), | ||
}}; | ||
let first = paths.first().unwrap(); | ||
assert!(paths.iter().skip(1).any(|p| p == first )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test for the sympton rather than the specific detail? In this case, its an extra rebuild
This issue seems need more exploration, thanks for your in advance review. |
b7c1880
to
1166084
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this approach didn't work is pretty much due to #10358. When Cargo computes fingerprint for a Unit
of work, it asks env::var
which doesn't contain LIBRARY_PATH
or PATH
because that is set by Cargo. rerun-if-env-changed
only captures environment variables set by users via shell like MY_VAR=1 cargo build
. Variables added by Cargo only available when consulting the Command
struct of the build script execution via Command::get_envs
(like what has done in f91dc78).
As a consequence, if you open the fingerprint JSON file of the build script execution (normally at target/debug/.fingerprint/foo-559e30894cda9925/run-build-script-build-script-build.json
), you'll see
{
"rustc": 11851488446658826000,
// ...
"local": [
{
"RerunIfEnvChanged": {
"var": "DYLD_FALLBACK_LIBRARY_PATH",
"val": null
}
}
],
"rustflags": [],
// ...
}
which shows that Cargo failed to capture the initial library search path set by itself.
There is another way to observe this bug: set the LEVEL
env var in the test to a higher number like 5. Any subsequent Cargo invocation after the first one should be fresh. Before doing this verification you need to change std::env!("LEVEL")
to std::env::var!("LEVEL")
because the former will be captured by rustc dep-info, which trigger a rebuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before doing this verification you need to change std::env!("LEVEL") to std::env::var!("LEVEL") because the former will be captured by rustc dep-info, which trigger a rebuild.
I didn't expect such a difference.
I decide to to get the "LEVEL"
from the command line argument.
ed49366
to
f5bf972
Compare
search_path
into dylib_path_envvar
if the program call into cargo
inversely.dylib_path_envvar
when calling cargo run
recursively
Thanks! @bors r+ |
☀️ Test successful - checks-actions |
Update cargo 8 commits in ad074abe3a18ce8444c06f962ceecfd056acfc73..15fbd2f607d4defc87053b8b76bf5038f2483cf4 2024-10-04 18:18:15 +0000 to 2024-10-08 21:08:11 +0000 - initial version of checksum based freshness (rust-lang/cargo#14137) - feat: Add custom completer for completing registry name (rust-lang/cargo#14656) - Document build-plan as being deprecated (rust-lang/cargo#14657) - fix(complete): Don't complete files for any value (rust-lang/cargo#14653) - Add more SAT resolver tests (rust-lang/cargo#14614) - fix: avoid inserting duplicate `dylib_path_envvar` when calling `cargo run` recursively (rust-lang/cargo#14464) - chore(deps): bump gix-path from 0.10.9 to 0.10.11 (rust-lang/cargo#14489) - improve error reporting when feature not found in `activated_features` (rust-lang/cargo#14647) --- This also adds three license exceptions to Cargo. * arrayref — BSD-2-Clause * blake3 — CC0-1.0 OR Apache-2.0 OR Apache-2.0 WITH LLVM-exception * constant_time_eq — CC0-1.0 OR MIT-0 OR Apache-2.0 These exceptions were added to rustc in rust-lang#126930, so should be fine for Cargo as well.
What does this PR try to resolve?
If the current program started by
cargo run
recursively call intocargo run
, the secondcargo run
will insertsearch_path
intodylib_path_envvar
again.Fixes #14194
How should we test and review this PR?
The first commit adds the test to reflect the issue. The first call to
cargo run
stores the dylib search path env var to a file. Subsequent calls verify that env var remains the same.The second commit fixes the behavior by checking if env vars in
search_path
are a prefix of the slice of env vars indylib_path_envvar
.