Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use anyhow::{anyhow, bail, Context, Result};
use cargo_manifest::{Manifest, Product, StringOrBool, Value};

use std::collections::HashSet;
use std::ffi::OsString;
use std::fs::{DirBuilder, File};
use std::path::Path;
Expand All @@ -23,6 +24,8 @@ pub struct Args {
pub arch: Option<String>,
/// The absolute path to the Cargo.toml file. Currently the --manifest-path option is not implemented.
pub manifest_path: PathBuf,
/// Features that were active when compiling
pub features: HashSet<String>,
}

/// Wrapper around [`Args`] that can also indicate the --help flag.
Expand Down Expand Up @@ -79,13 +82,22 @@ impl ArgsOrHelp {
.context("Package manifest does not exist")?
};

let features = match args.values_from_str("--features") {
Ok(features) => features,
Err(pico_args::Error::MissingArgument) => Default::default(),
Err(err) => return Err(err.into()),
}
.into_iter()
.collect();

let res = Args {
install_base,
build_base,
forwarded_args,
profile,
arch,
manifest_path,
features,
};

Ok(ArgsOrHelp::Args(res))
Expand Down Expand Up @@ -230,6 +242,7 @@ pub fn install_binaries(
package_name: &str,
profile: &str,
arch: Option<&str>,
features: &HashSet<String>,
binaries: &[Product],
) -> Result<()> {
let src_dir = if let Some(arch) = arch {
Expand All @@ -244,6 +257,17 @@ pub fn install_binaries(
}
// Copy binaries
for binary in binaries {
let missing_feature = binary
.required_features
.iter()
.any(|feature| !features.contains(feature));
if missing_feature {
// The build directory will not contain this binary because one of
// its required features is missing. We should skip our attempt to
// install it.
continue;
}

let name = binary
.name
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn fallible_main() -> Result<bool> {
package_name,
&args.profile,
args.arch.as_deref(),
&args.features,
// Unwrap is safe since complete_from_path() has been called
&manifest.bin,
)?;
Expand Down
Loading