diff options
-rw-r--r-- | crates/project_model/src/cargo_workspace.rs | 17 | ||||
-rw-r--r-- | crates/project_model/src/workspace.rs | 5 |
2 files changed, 20 insertions, 2 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index 50e5760b6..e6491b754 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs | |||
@@ -88,6 +88,7 @@ pub struct PackageData { | |||
88 | pub edition: Edition, | 88 | pub edition: Edition, |
89 | pub features: Vec<String>, | 89 | pub features: Vec<String>, |
90 | pub cfgs: Vec<CfgFlag>, | 90 | pub cfgs: Vec<CfgFlag>, |
91 | pub envs: Vec<(String, String)>, | ||
91 | pub out_dir: Option<AbsPathBuf>, | 92 | pub out_dir: Option<AbsPathBuf>, |
92 | pub proc_macro_dylib_path: Option<AbsPathBuf>, | 93 | pub proc_macro_dylib_path: Option<AbsPathBuf>, |
93 | } | 94 | } |
@@ -173,11 +174,13 @@ impl CargoWorkspace { | |||
173 | 174 | ||
174 | let mut out_dir_by_id = FxHashMap::default(); | 175 | let mut out_dir_by_id = FxHashMap::default(); |
175 | let mut cfgs = FxHashMap::default(); | 176 | let mut cfgs = FxHashMap::default(); |
177 | let mut envs = FxHashMap::default(); | ||
176 | let mut proc_macro_dylib_paths = FxHashMap::default(); | 178 | let mut proc_macro_dylib_paths = FxHashMap::default(); |
177 | if config.load_out_dirs_from_check { | 179 | if config.load_out_dirs_from_check { |
178 | let resources = load_extern_resources(cargo_toml, config)?; | 180 | let resources = load_extern_resources(cargo_toml, config)?; |
179 | out_dir_by_id = resources.out_dirs; | 181 | out_dir_by_id = resources.out_dirs; |
180 | cfgs = resources.cfgs; | 182 | cfgs = resources.cfgs; |
183 | envs = resources.env; | ||
181 | proc_macro_dylib_paths = resources.proc_dylib_paths; | 184 | proc_macro_dylib_paths = resources.proc_dylib_paths; |
182 | } | 185 | } |
183 | 186 | ||
@@ -205,6 +208,7 @@ impl CargoWorkspace { | |||
205 | dependencies: Vec::new(), | 208 | dependencies: Vec::new(), |
206 | features: Vec::new(), | 209 | features: Vec::new(), |
207 | cfgs: cfgs.get(&id).cloned().unwrap_or_default(), | 210 | cfgs: cfgs.get(&id).cloned().unwrap_or_default(), |
211 | envs: envs.get(&id).cloned().unwrap_or_default(), | ||
208 | out_dir: out_dir_by_id.get(&id).cloned(), | 212 | out_dir: out_dir_by_id.get(&id).cloned(), |
209 | proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), | 213 | proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), |
210 | }); | 214 | }); |
@@ -289,6 +293,7 @@ pub(crate) struct ExternResources { | |||
289 | out_dirs: FxHashMap<PackageId, AbsPathBuf>, | 293 | out_dirs: FxHashMap<PackageId, AbsPathBuf>, |
290 | proc_dylib_paths: FxHashMap<PackageId, AbsPathBuf>, | 294 | proc_dylib_paths: FxHashMap<PackageId, AbsPathBuf>, |
291 | cfgs: FxHashMap<PackageId, Vec<CfgFlag>>, | 295 | cfgs: FxHashMap<PackageId, Vec<CfgFlag>>, |
296 | env: FxHashMap<PackageId, Vec<(String, String)>>, | ||
292 | } | 297 | } |
293 | 298 | ||
294 | pub(crate) fn load_extern_resources( | 299 | pub(crate) fn load_extern_resources( |
@@ -323,7 +328,13 @@ pub(crate) fn load_extern_resources( | |||
323 | for message in cargo_metadata::Message::parse_stream(output.stdout.as_slice()) { | 328 | for message in cargo_metadata::Message::parse_stream(output.stdout.as_slice()) { |
324 | if let Ok(message) = message { | 329 | if let Ok(message) = message { |
325 | match message { | 330 | match message { |
326 | Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => { | 331 | Message::BuildScriptExecuted(BuildScript { |
332 | package_id, | ||
333 | out_dir, | ||
334 | cfgs, | ||
335 | env, | ||
336 | .. | ||
337 | }) => { | ||
327 | let cfgs = { | 338 | let cfgs = { |
328 | let mut acc = Vec::new(); | 339 | let mut acc = Vec::new(); |
329 | for cfg in cfgs { | 340 | for cfg in cfgs { |
@@ -341,8 +352,10 @@ pub(crate) fn load_extern_resources( | |||
341 | if out_dir != PathBuf::default() { | 352 | if out_dir != PathBuf::default() { |
342 | let out_dir = AbsPathBuf::assert(out_dir); | 353 | let out_dir = AbsPathBuf::assert(out_dir); |
343 | res.out_dirs.insert(package_id.clone(), out_dir); | 354 | res.out_dirs.insert(package_id.clone(), out_dir); |
344 | res.cfgs.insert(package_id, cfgs); | 355 | res.cfgs.insert(package_id.clone(), cfgs); |
345 | } | 356 | } |
357 | |||
358 | res.env.insert(package_id, env); | ||
346 | } | 359 | } |
347 | Message::CompilerArtifact(message) => { | 360 | Message::CompilerArtifact(message) => { |
348 | if message.target.kind.contains(&"proc-macro".to_string()) { | 361 | if message.target.kind.contains(&"proc-macro".to_string()) { |
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index ab5cbae11..7f4a7e56b 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs | |||
@@ -453,13 +453,18 @@ fn add_target_crate_root( | |||
453 | opts.extend(pkg.cfgs.iter().cloned()); | 453 | opts.extend(pkg.cfgs.iter().cloned()); |
454 | opts | 454 | opts |
455 | }; | 455 | }; |
456 | |||
456 | let mut env = Env::default(); | 457 | let mut env = Env::default(); |
458 | for (k, v) in &pkg.envs { | ||
459 | env.set(k, v.clone()); | ||
460 | } | ||
457 | if let Some(out_dir) = &pkg.out_dir { | 461 | if let Some(out_dir) = &pkg.out_dir { |
458 | // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() | 462 | // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() |
459 | if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) { | 463 | if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) { |
460 | env.set("OUT_DIR", out_dir); | 464 | env.set("OUT_DIR", out_dir); |
461 | } | 465 | } |
462 | } | 466 | } |
467 | |||
463 | let proc_macro = | 468 | let proc_macro = |
464 | pkg.proc_macro_dylib_path.as_ref().map(|it| proc_macro_loader(&it)).unwrap_or_default(); | 469 | pkg.proc_macro_dylib_path.as_ref().map(|it| proc_macro_loader(&it)).unwrap_or_default(); |
465 | 470 | ||