-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Providing path to originally selected manifest file #13484
Copy link
Copy link
Closed as not planned
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-propose-closeStatus: A team member has nominated this for closing, pending further input from the teamStatus: A team member has nominated this for closing, pending further input from the team
Metadata
Metadata
Assignees
Labels
A-build-scriptsArea: build.rs scriptsArea: build.rs scriptsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-propose-closeStatus: A team member has nominated this for closing, pending further input from the teamStatus: A team member has nominated this for closing, pending further input from the team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Problem
When running cargo commands like
cargo build, packages are automatically selected based off of the cargo manifest selected (either based off of the current working directory of the invocation or the--manifest-pathargument). AFAIU, a dependency graph is generated based off of this manifest and then the build is executed. By this logic, before any build-script runs, cargo already knows all of the packages that need to be built and has access to all of its manifest data. I want to access that data in one of the dependency's build.rs.I have 2 crates- crate A and crate B. crate B has a path dependency on crate A. I would like to be able to read custom metadata in crate B's manifest by using
cargo_metadatafrom within crate A'sbuild.rs. This metadata is something like a globally configured feature proposed in https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618/38. When runningcargo metadatacli command from crate B's directory, I can see the metadata in the crate B's manifest, but when getting metadata via crate A's build.rs, I cannot. If both crates existed in the same workspace, it would work, but I intend for crate A to be able to be consumed by others to use and configure via metadata in user's dependent crates.If the originally selected manifest path was provided to build scripts, I could point to that manifest when using
cargo_metadatain crate A's build.rs. As it stands, I need to useOUT_DIRto derive where the selected/root manifest of the build is, but this is fragile and does not work when the default target directory is changed by things like--target-dir(similar issue to #9661 ).Proposed Solution
A environment variable provided to builds scripts that exposes to originally selected manifest path.
Notes
seems like a similar feature request to #8148