7464: Export `CARGO` for proc. macros r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/7462

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-01-27 13:26:18 +00:00 committed by GitHub
commit e3204c528b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,7 +175,7 @@ fn is_dylib(path: &Path) -> bool {
/// Should be synced with <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates>
fn inject_cargo_env(package: &cargo_metadata::Package, env: &mut Vec<(String, String)>) {
// FIXME: Missing variables:
// CARGO, CARGO_PKG_HOMEPAGE, CARGO_CRATE_NAME, CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
// CARGO_PKG_HOMEPAGE, CARGO_CRATE_NAME, CARGO_BIN_NAME, CARGO_BIN_EXE_<name>
let mut manifest_dir = package.manifest_path.clone();
manifest_dir.pop();
@ -183,6 +183,9 @@ fn inject_cargo_env(package: &cargo_metadata::Package, env: &mut Vec<(String, St
env.push(("CARGO_MANIFEST_DIR".into(), cargo_manifest_dir.into()));
}
// Not always right, but works for common cases.
env.push(("CARGO".into(), "cargo".into()));
env.push(("CARGO_PKG_VERSION".into(), package.version.to_string()));
env.push(("CARGO_PKG_VERSION_MAJOR".into(), package.version.major.to_string()));
env.push(("CARGO_PKG_VERSION_MINOR".into(), package.version.minor.to_string()));