Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/workspace.rs')
-rw-r--r--crates/project-model/src/workspace.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 13463e9f72..8cb0e65be1 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -2,7 +2,7 @@
//! metadata` or `rust-project.json`) into representation stored in the salsa
//! database -- `CrateGraph`.
-use std::{collections::VecDeque, fmt, fs, process::Command, sync};
+use std::{collections::VecDeque, fmt, fs, process::Command, str::FromStr, sync};
use anyhow::{format_err, Context};
use base_db::{
@@ -1228,6 +1228,10 @@ fn add_target_crate_root(
let mut env = Env::default();
inject_cargo_env(pkg, &mut env);
+ if let Ok(cname) = String::from_str(cargo_name) {
+ // CARGO_CRATE_NAME is the name of the Cargo target with - converted to _, such as the name of the library, binary, example, integration test, or benchmark.
+ env.set("CARGO_CRATE_NAME", cname.replace("-", "_"));
+ }
if let Some(envs) = build_data.map(|it| &it.envs) {
for (k, v) in envs {