-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Clobbering of environment variables during recursive invocations of cargo #15350
Comments
Could you provide more details on the use case and what kind of environment variables you are needing access to that you lose? If you could provide a complete but minimal reproduction case, that would be a big help. |
The environment variable is The use case is that we don't want to require By specifying |
Ok, so by The solution is relatively simple. The use case is reasonable but the solution seems relatively niche and I wonder if there are other, longer term ways of resolving it and what that means for the short term. For example, we want to find ways to migrate project config to manifests (#12738) which includes aliases. We have artifact dependencies as a way for build scripts to run dependencies (and maybe even be build scripts, see #14903). If that was also applied to aliases / tasks / having runnable dependencies, then maybe there is a way for us to do similar for runners. The runner would then be accessing a binary and running it directly, rather than calling Unsure how well the name communicates the intent, especially if we add other flags like |
Yeah, you basically have the problem spot-on. I was thinking the other way around, that cargo The other alternative was to specify Edit: |
Prefixing what cargo sets, and not what it inherits, feels like a cleaner approach. The challenge with this is that there are a lot of helper libraries for build scripts that will read the variables directly and it would be a major shift in the ecosystem to get them to support custom environment variables. This will be exacerbated by #14903 which would mean project's may no longer have a Since the intent is to access the parent process's cargo variables, this gets weird if the parent process also set an env prefix. Now you don't have a commonly accepted term to look up. |
Indeed, I think either approach would seem to work fine though (ignoring all the build script issues), I just meant when I was thinking of the name But prefix-what-we-inherit is probably the most backwards compatible |
The reproducer that you asked for https://github.com/ratmice/cargo_issue_15350.git It isn't the minimalist but is decently small, since it depends on e.g. wasmtime and the wasm32- wasip2 target. |
FWIW, On the project I was working on it has been decided that That said, I had two ideas the avoid the entire environment variable clobbering: One is based upon crate-type: If we had a crate-type Second option is similar, except instead of being based on a crate type, it adds a new command
Where I think this last option manages to side-step a lot of problems with the fewest number of new concepts. |
Problem
sometimes it would be convenient to do things like
cargo run
within.cargo/config.toml
So that you can avoid a separate install process for the test runner.
The caveat of this is that
cargo run
overwrites a bunch of environment variables that initially set by the cargo process that invoked the runner.Proposed Solution
For cases such as this it would be nice to have an
cargo run --env-var-prefix foo_ -p my_runner
this would then set variables like
foo_OUT_DIR
etc.Perhaps a better way would be to just have a rarely used Cargo.toml field to specify an env var prefix, so
my_runner/Cargo.toml
can use that, it would then be expected thatmy_runner/build.rs
take part inunderstanding that this crate always uses that env prefix. That seems more acceptable to me anyways.
Notes
No response
The text was updated successfully, but these errors were encountered: