Skip to content

Commit

Permalink
add feature parsing
Browse files Browse the repository at this point in the history
also some small improvements
  • Loading branch information
Emilgardis committed May 20, 2022
1 parent a9ed4ae commit 5b5c31a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CargoMetadata> =
serde_json::from_slice(&output.stdout).wrap_err_with(|| {
Expand Down
12 changes: 12 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Args {
pub subcommand: Option<Subcommand>,
pub channel: Option<String>,
pub target: Option<Target>,
pub features: Vec<String>,
pub target_dir: Option<PathBuf>,
pub docker_in_docker: bool,
pub manifest_path: Option<PathBuf>,
Expand All @@ -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<PathBuf> = None;
let mut target_dir = None;
let mut sc = None;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -87,6 +98,7 @@ pub fn parse(target_list: &TargetList) -> Args {
subcommand: sc,
channel,
target,
features,
target_dir,
docker_in_docker,
manifest_path,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<CrossToml>> {
fn toml(metadata: &CargoMetadata) -> Result<Option<CrossToml>> {
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() {
Expand All @@ -476,7 +476,7 @@ fn toml(root: &CargoMetadata) -> Result<Option<CrossToml>> {
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)
Expand Down
1 change: 0 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

use once_cell::sync::OnceCell;
use rustc_version::VersionMeta;
use serde::Deserialize;

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

Expand Down

0 comments on commit 5b5c31a

Please sign in to comment.