Skip to content

Commit b1577ce

Browse files
committed
add feature parsing
also some small improvements
1 parent 2f4c001 commit b1577ce

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/cargo.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ pub fn cargo_metadata_with_args(
117117
if let Some(target) = args.and_then(|a| a.target.as_ref()) {
118118
command.args(["--filter-platform", target.triple()]);
119119
}
120+
if let Some(features) = args.map(|a| &a.features) {
121+
command.args([String::from("--features"), features.join(",")]);
122+
}
120123
let output = command.output()?;
121124
let manifest: Option<CargoMetadata> =
122125
serde_json::from_slice(&output.stdout).wrap_err_with(|| {

src/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Args {
1111
pub subcommand: Option<Subcommand>,
1212
pub channel: Option<String>,
1313
pub target: Option<Target>,
14+
pub features: Vec<String>,
1415
pub target_dir: Option<PathBuf>,
1516
pub docker_in_docker: bool,
1617
pub manifest_path: Option<PathBuf>,
@@ -19,6 +20,7 @@ pub struct Args {
1920
pub fn parse(target_list: &TargetList) -> Args {
2021
let mut channel = None;
2122
let mut target = None;
23+
let mut features = Vec::new();
2224
let mut manifest_path: Option<PathBuf> = None;
2325
let mut target_dir = None;
2426
let mut sc = None;
@@ -57,6 +59,15 @@ pub fn parse(target_list: &TargetList) -> Args {
5759
.split_once('=')
5860
.map(|(_, t)| Target::from(t, target_list));
5961
all.push(arg);
62+
} else if arg == "--features" {
63+
all.push(arg);
64+
if let Some(t) = args.next() {
65+
features.push(t.clone());
66+
all.push(t);
67+
}
68+
} else if arg.starts_with("--features=") {
69+
features.extend(arg.split_once('=').map(|(_, t)| t.to_owned()));
70+
all.push(arg);
6071
} else if arg == "--target-dir" {
6172
all.push(arg);
6273
if let Some(td) = args.next() {
@@ -87,6 +98,7 @@ pub fn parse(target_list: &TargetList) -> Args {
8798
subcommand: sc,
8899
channel,
89100
target,
101+
features,
90102
target_dir,
91103
docker_in_docker,
92104
manifest_path,

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ pub(crate) fn warn_host_version_mismatch(
460460

461461
/// Parses the `Cross.toml` at the root of the Cargo project or from the
462462
/// `CROSS_CONFIG` environment variable (if any exist in either location).
463-
fn toml(root: &CargoMetadata) -> Result<Option<CrossToml>> {
463+
fn toml(metadata: &CargoMetadata) -> Result<Option<CrossToml>> {
464464
let path = match env::var("CROSS_CONFIG") {
465465
Ok(var) => PathBuf::from(var),
466-
Err(_) => root.workspace_root.join("Cross.toml"),
466+
Err(_) => metadata.workspace_root.join("Cross.toml"),
467467
};
468468

469469
if path.exists() {
@@ -476,7 +476,7 @@ fn toml(root: &CargoMetadata) -> Result<Option<CrossToml>> {
476476
Ok(Some(config))
477477
} else {
478478
// Checks if there is a lowercase version of this file
479-
if root.workspace_root.join("cross.toml").exists() {
479+
if metadata.workspace_root.join("cross.toml").exists() {
480480
eprintln!("There's a file named cross.toml, instead of Cross.toml. You may want to rename it, or it won't be considered.");
481481
}
482482
Ok(None)

src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77

88
use once_cell::sync::OnceCell;
99
use rustc_version::VersionMeta;
10-
use serde::Deserialize;
1110

1211
static WORKSPACE: OnceCell<PathBuf> = OnceCell::new();
1312

0 commit comments

Comments
 (0)