Skip to content

Commit

Permalink
add an option to pass an arbitrary set of arguments to cargo build
Browse files Browse the repository at this point in the history
  • Loading branch information
torkve committed Dec 16, 2018
1 parent 51e6351 commit 7c005a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn cargo_build_wasm(
path: &Path,
profile: BuildProfile,
step: &Step,
extra_options: &Vec<String>,
) -> Result<(), Error> {
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
PBAR.step(step, &msg);
Expand All @@ -91,6 +92,7 @@ pub fn cargo_build_wasm(
}
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.args(extra_options);
child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?;
Ok(())
}
Expand Down
14 changes: 13 additions & 1 deletion src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Build {
pub out_dir: PathBuf,
pub bindgen: Option<Download>,
pub cache: Cache,
pub extra_options: Vec<String>,
}

/// The `BuildMode` determines which mode of initialization we are running, and
Expand Down Expand Up @@ -119,6 +120,10 @@ pub struct BuildOptions {
#[structopt(long = "out-dir", short = "d", default_value = "pkg")]
/// Sets the output directory with a relative path.
pub out_dir: String,

#[structopt(last = true)]
/// List of extra options to pass to `cargo build`
extra_options: Vec<String>,
}

type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>;
Expand Down Expand Up @@ -151,6 +156,7 @@ impl Build {
out_dir,
bindgen: None,
cache: Cache::new()?,
extra_options: build_opts.extra_options,
})
}

Expand Down Expand Up @@ -255,7 +261,13 @@ impl Build {

fn step_build_wasm(&mut self, step: &Step, log: &Logger) -> Result<(), Error> {
info!(&log, "Building wasm...");
build::cargo_build_wasm(log, &self.crate_path, self.profile, step)?;
build::cargo_build_wasm(
log,
&self.crate_path,
self.profile,
step,
&self.extra_options,
)?;

info!(
&log,
Expand Down

0 comments on commit 7c005a0

Please sign in to comment.