Skip to content

Commit

Permalink
xbuild/cargo: Pass features with --features or -F to cargo (#89)
Browse files Browse the repository at this point in the history
In order to build projects with features in `xbuild`, it has to accept
these on the command line and pass them on to the underlying `cargo`
invocation.
  • Loading branch information
MarijnS95 authored Dec 6, 2022
1 parent 2c86653 commit e1b16c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion xbuild/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub use artifact::{Artifact, CrateType};

pub struct Cargo {
package: String,
features: Vec<String>,
manifest: PathBuf,
target_dir: PathBuf,
offline: bool,
Expand All @@ -20,6 +21,7 @@ pub struct Cargo {
impl Cargo {
pub fn new(
package: Option<&str>,
features: Vec<String>,
manifest_path: Option<PathBuf>,
target_dir: Option<PathBuf>,
offline: bool,
Expand Down Expand Up @@ -52,6 +54,7 @@ impl Cargo {
});
Ok(Self {
package,
features,
manifest,
target_dir,
offline,
Expand Down Expand Up @@ -91,7 +94,13 @@ impl Cargo {
}

pub fn build(&self, target: CompileTarget, target_dir: &Path) -> Result<CargoBuild> {
CargoBuild::new(target, self.root_dir(), target_dir, self.offline)
CargoBuild::new(
target,
&self.features,
self.root_dir(),
target_dir,
self.offline,
)
}

pub fn artifact(
Expand Down Expand Up @@ -178,6 +187,7 @@ pub struct CargoBuild {
impl CargoBuild {
fn new(
target: CompileTarget,
features: &[String],
root_dir: &Path,
target_dir: &Path,
offline: bool,
Expand All @@ -200,6 +210,9 @@ impl CargoBuild {
if offline {
cmd.arg("--offline");
}
for features in features {
cmd.arg("--features").arg(features);
}
Ok(Self {
cmd,
target,
Expand Down
4 changes: 4 additions & 0 deletions xbuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,16 @@ pub struct CargoArgs {
/// Run without accessing the network
#[clap(long)]
offline: bool,
/// Space or comma separated list of features to activate
#[clap(short = 'F', long)]
features: Vec<String>,
}

impl CargoArgs {
pub fn cargo(self) -> Result<Cargo> {
Cargo::new(
self.package.as_deref(),
self.features,
self.manifest_path,
self.target_dir,
self.offline,
Expand Down

0 comments on commit e1b16c8

Please sign in to comment.