diff --git a/src/cargo.rs b/src/cargo.rs index 9cd902880..bc6e23463 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -117,6 +117,9 @@ pub fn cargo_metadata_with_args( if let Some(target) = args.and_then(|a| a.target.as_ref()) { command.args(["--filter-platform", target.triple()]); } + if let Some(features) = args.map(|a| &a.features) { + command.args([String::from("--features"), features.join(",")]); + } let output = command.output()?; let manifest: Option = serde_json::from_slice(&output.stdout).wrap_err_with(|| { diff --git a/src/cli.rs b/src/cli.rs index 91c0c83f0..cab6db39a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,6 +11,7 @@ pub struct Args { pub subcommand: Option, pub channel: Option, pub target: Option, + pub features: Vec, pub target_dir: Option, pub docker_in_docker: bool, pub manifest_path: Option, @@ -19,6 +20,7 @@ pub struct Args { pub fn parse(target_list: &TargetList) -> Args { let mut channel = None; let mut target = None; + let mut features = Vec::new(); let mut manifest_path: Option = None; let mut target_dir = None; let mut sc = None; @@ -57,6 +59,15 @@ pub fn parse(target_list: &TargetList) -> Args { .split_once('=') .map(|(_, t)| Target::from(t, target_list)); all.push(arg); + } else if arg == "--features" { + all.push(arg); + if let Some(t) = args.next() { + features.push(t.clone()); + all.push(t); + } + } else if arg.starts_with("--features=") { + features.extend(arg.split_once('=').map(|(_, t)| t.to_owned())); + all.push(arg); } else if arg == "--target-dir" { all.push(arg); if let Some(td) = args.next() { @@ -87,6 +98,7 @@ pub fn parse(target_list: &TargetList) -> Args { subcommand: sc, channel, target, + features, target_dir, docker_in_docker, manifest_path, diff --git a/src/main.rs b/src/main.rs index 7afacba91..32e40e837 100644 --- a/src/main.rs +++ b/src/main.rs @@ -460,10 +460,10 @@ pub(crate) fn warn_host_version_mismatch( /// Parses the `Cross.toml` at the root of the Cargo project or from the /// `CROSS_CONFIG` environment variable (if any exist in either location). -fn toml(root: &CargoMetadata) -> Result> { +fn toml(metadata: &CargoMetadata) -> Result> { let path = match env::var("CROSS_CONFIG") { Ok(var) => PathBuf::from(var), - Err(_) => root.workspace_root.join("Cross.toml"), + Err(_) => metadata.workspace_root.join("Cross.toml"), }; if path.exists() { @@ -476,7 +476,7 @@ fn toml(root: &CargoMetadata) -> Result> { Ok(Some(config)) } else { // Checks if there is a lowercase version of this file - if root.workspace_root.join("cross.toml").exists() { + if metadata.workspace_root.join("cross.toml").exists() { eprintln!("There's a file named cross.toml, instead of Cross.toml. You may want to rename it, or it won't be considered."); } Ok(None) diff --git a/src/tests.rs b/src/tests.rs index 4554db9f9..c6f9bf0e1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -7,7 +7,6 @@ use std::{ use once_cell::sync::OnceCell; use rustc_version::VersionMeta; -use serde::Deserialize; static WORKSPACE: OnceCell = OnceCell::new();