From 4d4e4f3909358bb5abdc3c3de0640d1b4ff444fe Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 10 Jun 2019 11:40:36 -0700 Subject: [PATCH] Fix problems with build-wasm command * Check that docker is on the PATH before trying to run it * Don't try to use id(1) if using docker on windows * Add error message if neither emcc nor docker are available Fixes #358 --- cli/src/wasm.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cli/src/wasm.rs b/cli/src/wasm.rs index af335625..976aa0fa 100644 --- a/cli/src/wasm.rs +++ b/cli/src/wasm.rs @@ -25,7 +25,7 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu if !force_docker && Command::new("emcc").output().is_ok() { command = Command::new("emcc"); command.current_dir(&language_dir); - } else { + } else if Command::new("docker").output().is_ok() { command = Command::new("docker"); command.args(&["run", "--rm"]); @@ -46,16 +46,20 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu // Get the current user id so that files created in the docker container will have // the same owner. - let user_id_output = Command::new("id") - .arg("-u") - .output() - .map_err(Error::wrap(|| "Failed to get get current user id {}"))?; - let user_id = String::from_utf8_lossy(&user_id_output.stdout); - let user_id = user_id.trim(); - command.args(&["--user", user_id]); + if cfg!(unix) { + let user_id_output = Command::new("id") + .arg("-u") + .output() + .map_err(Error::wrap(|| "Failed to get get current user id"))?; + let user_id = String::from_utf8_lossy(&user_id_output.stdout); + let user_id = user_id.trim(); + command.args(&["--user", user_id]); + } // Run `emcc` in a container using the `emscripten-slim` image command.args(&["trzeci/emscripten-slim", "emcc"]); + } else { + return Error::err("You must have either emcc or docker on your PATH to run this command".to_string()); } command.args(&[