From eeeacc4727b9263f6ad33ae08ce38c38eb52c5f3 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 7 Dec 2020 20:52:31 +0100 Subject: Apply environment set by build scripts --- crates/project_model/src/cargo_workspace.rs | 17 +++++++++++++++-- crates/project_model/src/workspace.rs | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'crates') 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 { pub edition: Edition, pub features: Vec, pub cfgs: Vec, + pub envs: Vec<(String, String)>, pub out_dir: Option, pub proc_macro_dylib_path: Option, } @@ -173,11 +174,13 @@ impl CargoWorkspace { let mut out_dir_by_id = FxHashMap::default(); let mut cfgs = FxHashMap::default(); + let mut envs = FxHashMap::default(); let mut proc_macro_dylib_paths = FxHashMap::default(); if config.load_out_dirs_from_check { let resources = load_extern_resources(cargo_toml, config)?; out_dir_by_id = resources.out_dirs; cfgs = resources.cfgs; + envs = resources.env; proc_macro_dylib_paths = resources.proc_dylib_paths; } @@ -205,6 +208,7 @@ impl CargoWorkspace { dependencies: Vec::new(), features: Vec::new(), cfgs: cfgs.get(&id).cloned().unwrap_or_default(), + envs: envs.get(&id).cloned().unwrap_or_default(), out_dir: out_dir_by_id.get(&id).cloned(), proc_macro_dylib_path: proc_macro_dylib_paths.get(&id).cloned(), }); @@ -289,6 +293,7 @@ pub(crate) struct ExternResources { out_dirs: FxHashMap, proc_dylib_paths: FxHashMap, cfgs: FxHashMap>, + env: FxHashMap>, } pub(crate) fn load_extern_resources( @@ -323,7 +328,13 @@ pub(crate) fn load_extern_resources( for message in cargo_metadata::Message::parse_stream(output.stdout.as_slice()) { if let Ok(message) = message { match message { - Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => { + Message::BuildScriptExecuted(BuildScript { + package_id, + out_dir, + cfgs, + env, + .. + }) => { let cfgs = { let mut acc = Vec::new(); for cfg in cfgs { @@ -341,8 +352,10 @@ pub(crate) fn load_extern_resources( if out_dir != PathBuf::default() { let out_dir = AbsPathBuf::assert(out_dir); res.out_dirs.insert(package_id.clone(), out_dir); - res.cfgs.insert(package_id, cfgs); + res.cfgs.insert(package_id.clone(), cfgs); } + + res.env.insert(package_id, env); } Message::CompilerArtifact(message) => { 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( opts.extend(pkg.cfgs.iter().cloned()); opts }; + let mut env = Env::default(); + for (k, v) in &pkg.envs { + env.set(k, v.clone()); + } if let Some(out_dir) = &pkg.out_dir { // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!() if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) { env.set("OUT_DIR", out_dir); } } + let proc_macro = pkg.proc_macro_dylib_path.as_ref().map(|it| proc_macro_loader(&it)).unwrap_or_default(); -- cgit v1.2.3