diff --git a/Cargo.lock b/Cargo.lock index ebba9c5a9..7a91b0232 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -718,6 +718,7 @@ dependencies = [ "rsx-rosetta", "serde", "serde_json", + "subprocess", "syn", "tar", "thiserror", @@ -2573,6 +2574,16 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "subprocess" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "subtle" version = "2.4.1" diff --git a/Cargo.toml b/Cargo.toml index 0c7349ba4..c52924f71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ chrono = "0.4.19" anyhow = "1.0.53" hyper = "0.14.17" indicatif = "0.17.0-rc.11" +subprocess = "0.2.9" axum = { version = "0.5.1", features = ["ws", "headers"] } tower-http = { version = "0.2.2", features = ["fs", "trace"] } diff --git a/src/builder.rs b/src/builder.rs index c6e850b58..716903fad 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -48,39 +48,48 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result { // [1] Build the .wasm module log::info!("🚅 Running build command..."); - let mut cmd = Command::new("cargo"); - cmd.current_dir(&crate_dir) + let cmd = subprocess::Exec::cmd("cargo"); + let cmd = cmd.cwd(&crate_dir) .arg("build") .arg("--target") .arg("wasm32-unknown-unknown") - .arg("--message-format=json") - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()); + .arg("--message-format=json"); - if config.release { - cmd.arg("--release"); - } - if config.verbose { - cmd.arg("--verbose"); - } + let cmd = if config.release { + cmd.arg("--release") + } else { + cmd + }; + let cmd = if config.verbose { + cmd.arg("--verbose") + } else { + cmd + }; - if quiet { - cmd.arg("--quiet"); - } + let cmd = if quiet { + cmd.arg("--quiet") + } else { + cmd + }; - if config.custom_profile.is_some() { + let cmd = if config.custom_profile.is_some() { let custom_profile = config.custom_profile.as_ref().unwrap(); - cmd.arg("--profile"); - cmd.arg(custom_profile); - } + cmd + .arg("--profile") + .arg(custom_profile) + } else { + cmd + }; - if config.features.is_some() { + let cmd = if config.features.is_some() { let features_str = config.features.as_ref().unwrap().join(" "); - cmd.arg("--features"); - cmd.arg(features_str); - } + cmd.arg("--features") + .arg(features_str) + } else { + cmd + }; - match executable { + let cmd = match executable { ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), ExecutableType::Example(name) => cmd.arg("--example").arg(name), @@ -365,7 +374,7 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<()> { Ok(()) } -fn prettier_build(mut cmd: Command) -> anyhow::Result> { +fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { let mut warning_messages: Vec = vec![]; let pb = ProgressBar::new_spinner(); @@ -377,8 +386,8 @@ fn prettier_build(mut cmd: Command) -> anyhow::Result> { ); pb.set_message("💼 Waiting to start build the project..."); - let mut command = cmd.spawn()?; - let reader = std::io::BufReader::new(command.stdout.take().unwrap()); + let stdout = cmd.stream_stdout()?; + let reader = std::io::BufReader::new(stdout); for message in cargo_metadata::Message::parse_stream(reader) { match message.unwrap() { Message::CompilerMessage(msg) => {