Add env vars specifying the path for the dependent crate when compiling a dependency #13636
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-triage
Status: This issue is waiting on initial triage.
Problem
When building a dependency, currently it is not possible for the dependency to find the path for the dependent crate (e.g. if
foo
depends onbar
,bar
can't findfoo
's manifest).Proposed Solution
I suggest adding two new env vars to both build scripts and crates*:
CARGO_DEPNT_MANIFEST_DIR
points to the crate which directly depends on this crate (the "dependent")CARGO_TARGET_MANIFEST_DIR
points to the crate which is being built.Currently,
CARGO_TARGET_MANIFEST_DIR
can be found from a build script by looking atOUT_DIR
and then traversing up the directory tree until aCargo.toml
is found. I'm not sure ifCARGO_DEPNT_MANIFEST_DIR
can be found.*It doesn't really make sense to limit it to buildscripts. Someone may want to
include!
, and people can just set up a build script to pass it through anyways.Use case
A library may want to read a config file in the user's crate, or data from the
metadata
field ofCargo.toml
. Currently, that isn't possible. Instead, the library must use features (which are binary on/off) or env variables (which are just strings). Cargo.toml provides structured data beyond bools and strings. See #8375The text was updated successfully, but these errors were encountered: