CARGO_PRIMARY_PACKAGE is set for dependencies inside workspace #10956
Labels
A-documenting-cargo-itself
Area: Cargo's documentation
A-rebuild-detection
Area: rebuild detection and fingerprinting
C-bug
Category: bug
Problem
The Cargo reference states:
Ref: https://doc.rust-lang.org/cargo/reference/environment-variables.html
Specifically this statement is not always true:
However, it appears the env var will be set when a crate in a workspace is being built, even when used as a dependency of another crate.
Without CARGO_PRIMARY_PACKAGE always being not set for dependencies, it is not possible to accurately detect if a crate is being built for use as a dependency or not.
Steps
See example repo: https://github.com/leighmcculloch/rustlang--cargo--issue-10956
Running the Makefile in the repo produces:
Note that in the second build and run
aaa
thinks it is primary, even when it is used as a dependency.Note that in the third build and run
aaa
knowledge of whether it is primary is unstable, because building the workspace in the final run produces a different result as the first run.Possible Solution(s)
No response
Notes
It appears that CARGO_PRIMARY_PACKAGE is also unstable. If I cd into the
B
crate directory and build,A
will be built as a dependency with the env var not set. If I then cd into the workspace directory and built all crates in the workspace, theA
crate is not rebuilt, meaning the cached built artifact forA
is inconsistent with a clean build.Version
The text was updated successfully, but these errors were encountered: