mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Merge #6754
6754: Apply environment set by build scripts r=jonas-schievink a=jonas-schievink Fixes inclusion of generated files in typenum/heapless/defmt etc. bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
dfd0626dbf
@ -88,6 +88,7 @@ pub struct PackageData {
|
|||||||
pub edition: Edition,
|
pub edition: Edition,
|
||||||
pub features: Vec<String>,
|
pub features: Vec<String>,
|
||||||
pub cfgs: Vec<CfgFlag>,
|
pub cfgs: Vec<CfgFlag>,
|
||||||
|
pub envs: Vec<(String, String)>,
|
||||||
pub out_dir: Option<AbsPathBuf>,
|
pub out_dir: Option<AbsPathBuf>,
|
||||||
pub proc_macro_dylib_path: Option<AbsPathBuf>,
|
pub proc_macro_dylib_path: Option<AbsPathBuf>,
|
||||||
}
|
}
|
||||||
@ -173,11 +174,13 @@ impl CargoWorkspace {
|
|||||||
|
|
||||||
let mut out_dir_by_id = FxHashMap::default();
|
let mut out_dir_by_id = FxHashMap::default();
|
||||||
let mut cfgs = FxHashMap::default();
|
let mut cfgs = FxHashMap::default();
|
||||||
|
let mut envs = FxHashMap::default();
|
||||||
let mut proc_macro_dylib_paths = FxHashMap::default();
|
let mut proc_macro_dylib_paths = FxHashMap::default();
|
||||||
if config.load_out_dirs_from_check {
|
if config.load_out_dirs_from_check {
|
||||||
let resources = load_extern_resources(cargo_toml, config)?;
|
let resources = load_extern_resources(cargo_toml, config)?;
|
||||||
out_dir_by_id = resources.out_dirs;
|
out_dir_by_id = resources.out_dirs;
|
||||||
cfgs = resources.cfgs;
|
cfgs = resources.cfgs;
|
||||||
|
envs = resources.env;
|
||||||
proc_macro_dylib_paths = resources.proc_dylib_paths;
|
proc_macro_dylib_paths = resources.proc_dylib_paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +208,7 @@ impl CargoWorkspace {
|
|||||||
dependencies: Vec::new(),
|
dependencies: Vec::new(),
|
||||||
features: Vec::new(),
|
features: Vec::new(),
|
||||||
cfgs: cfgs.get(&id).cloned().unwrap_or_default(),
|
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(),
|
out_dir: out_dir_by_id.get(&id).cloned(),
|
||||||
proc_macro_dylib_path: proc_macro_dylib_paths.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<PackageId, AbsPathBuf>,
|
out_dirs: FxHashMap<PackageId, AbsPathBuf>,
|
||||||
proc_dylib_paths: FxHashMap<PackageId, AbsPathBuf>,
|
proc_dylib_paths: FxHashMap<PackageId, AbsPathBuf>,
|
||||||
cfgs: FxHashMap<PackageId, Vec<CfgFlag>>,
|
cfgs: FxHashMap<PackageId, Vec<CfgFlag>>,
|
||||||
|
env: FxHashMap<PackageId, Vec<(String, String)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_extern_resources(
|
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()) {
|
for message in cargo_metadata::Message::parse_stream(output.stdout.as_slice()) {
|
||||||
if let Ok(message) = message {
|
if let Ok(message) = message {
|
||||||
match message {
|
match message {
|
||||||
Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => {
|
Message::BuildScriptExecuted(BuildScript {
|
||||||
|
package_id,
|
||||||
|
out_dir,
|
||||||
|
cfgs,
|
||||||
|
env,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
let cfgs = {
|
let cfgs = {
|
||||||
let mut acc = Vec::new();
|
let mut acc = Vec::new();
|
||||||
for cfg in cfgs {
|
for cfg in cfgs {
|
||||||
@ -341,8 +352,10 @@ pub(crate) fn load_extern_resources(
|
|||||||
if out_dir != PathBuf::default() {
|
if out_dir != PathBuf::default() {
|
||||||
let out_dir = AbsPathBuf::assert(out_dir);
|
let out_dir = AbsPathBuf::assert(out_dir);
|
||||||
res.out_dirs.insert(package_id.clone(), 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) => {
|
Message::CompilerArtifact(message) => {
|
||||||
if message.target.kind.contains(&"proc-macro".to_string()) {
|
if message.target.kind.contains(&"proc-macro".to_string()) {
|
||||||
|
@ -453,13 +453,18 @@ fn add_target_crate_root(
|
|||||||
opts.extend(pkg.cfgs.iter().cloned());
|
opts.extend(pkg.cfgs.iter().cloned());
|
||||||
opts
|
opts
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut env = Env::default();
|
let mut env = Env::default();
|
||||||
|
for (k, v) in &pkg.envs {
|
||||||
|
env.set(k, v.clone());
|
||||||
|
}
|
||||||
if let Some(out_dir) = &pkg.out_dir {
|
if let Some(out_dir) = &pkg.out_dir {
|
||||||
// NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
|
// 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()) {
|
if let Some(out_dir) = out_dir.to_str().map(|s| s.to_owned()) {
|
||||||
env.set("OUT_DIR", out_dir);
|
env.set("OUT_DIR", out_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let proc_macro =
|
let proc_macro =
|
||||||
pkg.proc_macro_dylib_path.as_ref().map(|it| proc_macro_loader(&it)).unwrap_or_default();
|
pkg.proc_macro_dylib_path.as_ref().map(|it| proc_macro_loader(&it)).unwrap_or_default();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user