Skip to content

Commit cf75194

Browse files
authored
Account for features when trying to install binaries (#26)
* Account for features when trying to install binaries Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * more stylish Signed-off-by: Michael X. Grey <greyxmike@gmail.com> --------- Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
1 parent 94f4cb2 commit cf75194

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use anyhow::{anyhow, bail, Context, Result};
44
use cargo_manifest::{Manifest, Product, StringOrBool, Value};
55

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

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

85+
let features = match args.values_from_str("--features") {
86+
Ok(features) => features,
87+
Err(pico_args::Error::MissingArgument) => Default::default(),
88+
Err(err) => return Err(err.into()),
89+
}
90+
.into_iter()
91+
.collect();
92+
8293
let res = Args {
8394
install_base,
8495
build_base,
8596
forwarded_args,
8697
profile,
8798
arch,
8899
manifest_path,
100+
features,
89101
};
90102

91103
Ok(ArgsOrHelp::Args(res))
@@ -230,6 +242,7 @@ pub fn install_binaries(
230242
package_name: &str,
231243
profile: &str,
232244
arch: Option<&str>,
245+
features: &HashSet<String>,
233246
binaries: &[Product],
234247
) -> Result<()> {
235248
let src_dir = if let Some(arch) = arch {
@@ -244,6 +257,17 @@ pub fn install_binaries(
244257
}
245258
// Copy binaries
246259
for binary in binaries {
260+
let missing_feature = binary
261+
.required_features
262+
.iter()
263+
.any(|feature| !features.contains(feature));
264+
if missing_feature {
265+
// The build directory will not contain this binary because one of
266+
// its required features is missing. We should skip our attempt to
267+
// install it.
268+
continue;
269+
}
270+
247271
let name = binary
248272
.name
249273
.as_ref()

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn fallible_main() -> Result<bool> {
7979
package_name,
8080
&args.profile,
8181
args.arch.as_deref(),
82+
&args.features,
8283
// Unwrap is safe since complete_from_path() has been called
8384
&manifest.bin,
8485
)?;

0 commit comments

Comments
 (0)