Fixing wasm-pack on non-rustup setups

master
Pierre-Étienne Meunier 7 years ago
parent 51e6351c28
commit 30d9e2bd07
  1. 1
      Cargo.toml
  2. 23
      src/build.rs
  3. 1
      src/lib.rs

@ -35,6 +35,7 @@ tar = "0.4.16"
toml = "0.4"
which = "2.0.0"
zip = "0.4.2"
tempfile = "3.0"
[dev-dependencies]
tempfile = "3"

@ -6,9 +6,12 @@ use emoji;
use failure::{Error, ResultExt};
use progressbar::Step;
use slog::Logger;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use std::fs::File;
use std::str;
use tempfile;
use PBAR;
/// Ensure that `rustc` is present and that it is >= 1.30.0
@ -55,6 +58,26 @@ fn rustc_minor_version() -> Option<u32> {
pub fn rustup_add_wasm_target(log: &Logger, step: &Step) -> Result<(), Error> {
let msg = format!("{}Adding WASM target...", emoji::TARGET);
PBAR.step(step, &msg);
// Checking wether we can already compile to wasm with the rustc
// we have in scope.
let dir = tempfile::TempDir::new()?;
let p = dir.path().join("main.rs");
{
let mut f = File::create(&p)?;
writeln!(f, "fn main(){{}}")?;
}
match Command::new("rustc")
.arg("--target")
.arg("wasm32-unknown-unknown")
.arg(p.to_str().unwrap())
.status()
{
Ok(ref e) if e.success() => return Ok(()),
_ => {}
}
// If not, using rustup to add it.
let mut cmd = Command::new("rustup");
cmd.arg("target").arg("add").arg("wasm32-unknown-unknown");
child::run(log, cmd, "rustup")

@ -26,6 +26,7 @@ extern crate slog;
extern crate slog_async;
extern crate slog_term;
extern crate tar;
extern crate tempfile;
extern crate toml;
extern crate which;
extern crate zip;

Loading…
Cancel
Save