Skip to content

Fix env/cfg set for cargo test and cargo run.#9122

Merged
bors merged 2 commits intorust-lang:masterfrom
ehuss:fix-multiple-run-custom-build
Feb 3, 2021
Merged

Fix env/cfg set for cargo test and cargo run.#9122
bors merged 2 commits intorust-lang:masterfrom
ehuss:fix-multiple-run-custom-build

Conversation

@ehuss
Copy link
Contributor

@ehuss ehuss commented Feb 2, 2021

There are some situations where a build script may need to run multiple times for the same package during the same cargo session. There was a bug in that some of the values in the Compilation struct didn't handle this case. The solution here is to be more careful about how this extra data is associated with Units, instead of assuming a package's build script only runs once.

The things that were not being handled properly:

  • Compilation::extra_env, which is the output of cargo:rustc-env in build scripts. The solution here is to use the Metadata hash which is used elsewhere for distinguishing build script outputs.
  • Compilation::cfgs, which is the output of cargo:rustc-cfg in build scripts and the features to be set, and this is only used for doctests. The solution here is to just add those --cfg flags directly in the Doctest struct.

The situations that cause a build script to be run multiple times:

  • A package needed for both the host and target. In the test here, this was accomplished with a proc-macro (which has to be host) and a cyclical dev dependency, but there are many other ways to trigger this.
  • Something built with different features (with the new feature resolver), usually due to host/target differences.
  • Something built with different profile settings, usually due to host/target differences.

Fixes #9100

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo set environment variables provided by build scripts randomly when running tests

5 participants