add an option to pass an arbitrary set of arguments to cargo build

master
Vsevolod Velichko 6 years ago
parent 4cd77901c3
commit 669c43d853
  1. 2
      src/build.rs
  2. 15
      src/command/build.rs

@ -68,6 +68,7 @@ pub fn cargo_build_wasm(
path: &Path, path: &Path,
profile: BuildProfile, profile: BuildProfile,
step: &Step, step: &Step,
extra_options: &Vec<String>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE); let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
PBAR.step(step, &msg); PBAR.step(step, &msg);
@ -91,6 +92,7 @@ pub fn cargo_build_wasm(
} }
} }
cmd.arg("--target").arg("wasm32-unknown-unknown"); cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.args(extra_options);
child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?;
Ok(()) Ok(())
} }

@ -31,6 +31,7 @@ pub struct Build {
pub out_dir: PathBuf, pub out_dir: PathBuf,
pub bindgen: Option<Download>, pub bindgen: Option<Download>,
pub cache: Cache, pub cache: Cache,
pub extra_options: Vec<String>,
} }
/// The `BuildMode` determines which mode of initialization we are running, and /// The `BuildMode` determines which mode of initialization we are running, and
@ -120,6 +121,10 @@ pub struct BuildOptions {
#[structopt(long = "out-dir", short = "d", default_value = "pkg")] #[structopt(long = "out-dir", short = "d", default_value = "pkg")]
/// Sets the output directory with a relative path. /// Sets the output directory with a relative path.
pub out_dir: String, pub out_dir: String,
#[structopt(last = true)]
/// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>,
} }
impl Default for BuildOptions { impl Default for BuildOptions {
@ -135,6 +140,7 @@ impl Default for BuildOptions {
release: false, release: false,
profiling: false, profiling: false,
out_dir: String::new(), out_dir: String::new(),
extra_options: Vec::new(),
} }
} }
} }
@ -175,6 +181,7 @@ impl Build {
out_dir, out_dir,
bindgen: None, bindgen: None,
cache: Cache::new()?, cache: Cache::new()?,
extra_options: build_opts.extra_options,
}) })
} }
@ -283,7 +290,13 @@ impl Build {
fn step_build_wasm(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { fn step_build_wasm(&mut self, step: &Step, log: &Logger) -> Result<(), Error> {
info!(&log, "Building wasm..."); 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!( info!(
&log, &log,

Loading…
Cancel
Save