Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the filter_target flag when gathering cargo metadata. #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cargo-geiger/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use cargo_platform::Cfg;
use krates::Builder as KratesBuilder;
use krates::Krates;
use std::path::PathBuf;
use std::process::Command;
use std::str::{self, FromStr};

pub fn get_cargo_metadata(
Expand All @@ -31,6 +32,20 @@ pub fn get_cargo_metadata(

let mut metadata_command = MetadataCommand::new();
metadata_command.manifest_path(root_manifest_path);
if !args.target_args.all_targets {
if let Some(specified_target) = args
.target_args
.target
.as_deref()
.map(|s| s.to_string())
.or_else(get_host_target)
{
metadata_command.other_options([
"--filter-platform".to_string(),
specified_target,
]);
}
}

if let Some(metadata_command_features) = match &args.features_args {
features_args if features_args.all_features => {
Expand Down Expand Up @@ -91,6 +106,23 @@ pub fn get_workspace(
Workspace::new(&root, config)
}

/// Query the installed rust compiler for the default host triple
fn get_host_target() -> Option<String> {
let rustc_output = Command::new("rustc").arg("-vV").output().ok()?;
if rustc_output.status.success() {
let output_str = String::from_utf8(rustc_output.stdout).ok()?;
for line in output_str.lines() {
if line.starts_with("host:") {
let parts: Vec<_> = line.split(" ").collect();
return parts.get(1).map(|s| s.to_string());
}
}
None
} else {
None
}
Comment on lines +120 to +123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably just do:

Suggested change
None
} else {
None
}
}
None

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it worth maybe giving a warning or something if this fails?

}

// TODO: Make a wrapper type for canonical paths and hide all mutable access.

#[cfg(test)]
Expand Down