Skip to content

Commit d30deb5

Browse files
Merge pull request #19751 from VictorArcium/env-var-cargo-manifest-path
Support environment variable CARGO_MANIFEST_PATH.
2 parents d7e977a + 32e09de commit d30deb5

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

crates/ide-completion/src/completions/env_vars.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
const CARGO_DEFINED_VARS: &[(&str, &str)] = &[
1414
("CARGO", "Path to the cargo binary performing the build"),
1515
("CARGO_MANIFEST_DIR", "The directory containing the manifest of your package"),
16+
("CARGO_MANIFEST_PATH", "The path to the manifest of your package"),
1617
("CARGO_PKG_VERSION", "The full version of your package"),
1718
("CARGO_PKG_VERSION_MAJOR", "The major version of your package"),
1819
("CARGO_PKG_VERSION_MINOR", "The minor version of your package"),

crates/project-model/src/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) fn inject_cargo_package_env(env: &mut Env, package: &PackageData) {
1818

1919
let manifest_dir = package.manifest.parent();
2020
env.set("CARGO_MANIFEST_DIR", manifest_dir.as_str());
21+
env.set("CARGO_MANIFEST_PATH", package.manifest.as_str());
2122

2223
env.set("CARGO_PKG_VERSION", package.version.to_string());
2324
env.set("CARGO_PKG_VERSION_MAJOR", package.version.major.to_string());

crates/project-model/test_data/output/cargo_hello_world_project_model.txt

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"CARGO": "$CARGO$",
5353
"CARGO_CRATE_NAME": "hello_world",
5454
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
55+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
5556
"CARGO_PKG_AUTHORS": "",
5657
"CARGO_PKG_DESCRIPTION": "",
5758
"CARGO_PKG_HOMEPAGE": "",
@@ -136,6 +137,7 @@
136137
"CARGO": "$CARGO$",
137138
"CARGO_CRATE_NAME": "hello_world",
138139
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
140+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
139141
"CARGO_PKG_AUTHORS": "",
140142
"CARGO_PKG_DESCRIPTION": "",
141143
"CARGO_PKG_HOMEPAGE": "",
@@ -220,6 +222,7 @@
220222
"CARGO": "$CARGO$",
221223
"CARGO_CRATE_NAME": "an_example",
222224
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
225+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
223226
"CARGO_PKG_AUTHORS": "",
224227
"CARGO_PKG_DESCRIPTION": "",
225228
"CARGO_PKG_HOMEPAGE": "",
@@ -304,6 +307,7 @@
304307
"CARGO": "$CARGO$",
305308
"CARGO_CRATE_NAME": "it",
306309
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
310+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
307311
"CARGO_PKG_AUTHORS": "",
308312
"CARGO_PKG_DESCRIPTION": "",
309313
"CARGO_PKG_HOMEPAGE": "",
@@ -384,6 +388,7 @@
384388
"CARGO": "$CARGO$",
385389
"CARGO_CRATE_NAME": "libc",
386390
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
391+
"CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
387392
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
388393
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
389394
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",

crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"CARGO": "$CARGO$",
5353
"CARGO_CRATE_NAME": "hello_world",
5454
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
55+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
5556
"CARGO_PKG_AUTHORS": "",
5657
"CARGO_PKG_DESCRIPTION": "",
5758
"CARGO_PKG_HOMEPAGE": "",
@@ -136,6 +137,7 @@
136137
"CARGO": "$CARGO$",
137138
"CARGO_CRATE_NAME": "hello_world",
138139
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
140+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
139141
"CARGO_PKG_AUTHORS": "",
140142
"CARGO_PKG_DESCRIPTION": "",
141143
"CARGO_PKG_HOMEPAGE": "",
@@ -220,6 +222,7 @@
220222
"CARGO": "$CARGO$",
221223
"CARGO_CRATE_NAME": "an_example",
222224
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
225+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
223226
"CARGO_PKG_AUTHORS": "",
224227
"CARGO_PKG_DESCRIPTION": "",
225228
"CARGO_PKG_HOMEPAGE": "",
@@ -304,6 +307,7 @@
304307
"CARGO": "$CARGO$",
305308
"CARGO_CRATE_NAME": "it",
306309
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
310+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
307311
"CARGO_PKG_AUTHORS": "",
308312
"CARGO_PKG_DESCRIPTION": "",
309313
"CARGO_PKG_HOMEPAGE": "",
@@ -384,6 +388,7 @@
384388
"CARGO": "$CARGO$",
385389
"CARGO_CRATE_NAME": "libc",
386390
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
391+
"CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
387392
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
388393
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
389394
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",

crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"CARGO": "$CARGO$",
5252
"CARGO_CRATE_NAME": "hello_world",
5353
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
54+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
5455
"CARGO_PKG_AUTHORS": "",
5556
"CARGO_PKG_DESCRIPTION": "",
5657
"CARGO_PKG_HOMEPAGE": "",
@@ -134,6 +135,7 @@
134135
"CARGO": "$CARGO$",
135136
"CARGO_CRATE_NAME": "hello_world",
136137
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
138+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
137139
"CARGO_PKG_AUTHORS": "",
138140
"CARGO_PKG_DESCRIPTION": "",
139141
"CARGO_PKG_HOMEPAGE": "",
@@ -217,6 +219,7 @@
217219
"CARGO": "$CARGO$",
218220
"CARGO_CRATE_NAME": "an_example",
219221
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
222+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
220223
"CARGO_PKG_AUTHORS": "",
221224
"CARGO_PKG_DESCRIPTION": "",
222225
"CARGO_PKG_HOMEPAGE": "",
@@ -300,6 +303,7 @@
300303
"CARGO": "$CARGO$",
301304
"CARGO_CRATE_NAME": "it",
302305
"CARGO_MANIFEST_DIR": "$ROOT$hello-world",
306+
"CARGO_MANIFEST_PATH": "$ROOT$hello-world/Cargo.toml",
303307
"CARGO_PKG_AUTHORS": "",
304308
"CARGO_PKG_DESCRIPTION": "",
305309
"CARGO_PKG_HOMEPAGE": "",
@@ -380,6 +384,7 @@
380384
"CARGO": "$CARGO$",
381385
"CARGO_CRATE_NAME": "libc",
382386
"CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
387+
"CARGO_MANIFEST_PATH": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98/Cargo.toml",
383388
"CARGO_PKG_AUTHORS": "The Rust Project Developers",
384389
"CARGO_PKG_DESCRIPTION": "Raw FFI bindings to platform libraries like libc.\n",
385390
"CARGO_PKG_HOMEPAGE": "https://github.com/rust-lang/libc",

0 commit comments

Comments
 (0)