Skip to content

Providing path to originally selected manifest file #13484

Closed as not planned
Closed as not planned
@wmmc88

Description

@wmmc88

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-path argument). 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_metadata from within crate A's build.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 running cargo metadata cli 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_metadata in crate A's build.rs. As it stands, I need to use OUT_DIR to 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-build-scriptsArea: build.rs scriptsC-feature-requestCategory: 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 team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions