Merge pull request #684 from rustwasm/gameldar-627-bindgen-version-error

check wasm-bindgen version if running with target web
master
Alex Crichton 6 years ago committed by GitHub
commit 2a7e6ac9ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Cargo.lock
  2. 1
      Cargo.toml
  3. 27
      src/bindgen.rs
  4. 2
      src/child.rs
  5. 34
      src/install/mod.rs
  6. 1
      src/lib.rs
  7. 4
      src/manifest/mod.rs
  8. 48
      tests/all/build.rs

1
Cargo.lock generated

@ -1987,6 +1987,7 @@ dependencies = [
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",

@ -24,6 +24,7 @@ log = "0.4.6"
openssl = { version = '0.10.11', optional = true } openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6" parking_lot = "0.6"
reqwest = "0.9.14" reqwest = "0.9.14"
semver = "0.9.0"
serde = "1.0.74" serde = "1.0.74"
serde_derive = "1.0.74" serde_derive = "1.0.74"
serde_ignored = "0.0.4" serde_ignored = "0.0.4"

@ -4,8 +4,10 @@ use binary_install::Download;
use child; use child;
use command::build::{BuildProfile, Target}; use command::build::{BuildProfile, Target};
use failure::{self, ResultExt}; use failure::{self, ResultExt};
use install;
use manifest::CrateData; use manifest::CrateData;
use std::path::Path; use semver;
use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
/// Run the `wasm-bindgen` CLI to generate bindings for the current crate's /// Run the `wasm-bindgen` CLI to generate bindings for the current crate's
@ -38,14 +40,21 @@ pub fn wasm_bindgen_build(
} else { } else {
"--typescript" "--typescript"
}; };
let bindgen_path = bindgen.binary("wasm-bindgen")?;
let target_arg = match target { let target_arg = match target {
Target::Nodejs => "--nodejs", Target::Nodejs => "--nodejs",
Target::NoModules => "--no-modules", Target::NoModules => "--no-modules",
Target::Web => "--web", Target::Web => {
if supports_web_target(&bindgen_path)? {
"--web"
} else {
bail!("Your current version of wasm-bindgen does not support the 'web' target. Please update your project to wasm-bindgen version >= 0.2.39.")
}
}
Target::Bundler => "--browser", Target::Bundler => "--browser",
}; };
let bindgen_path = bindgen.binary("wasm-bindgen")?;
let mut cmd = Command::new(bindgen_path); let mut cmd = Command::new(&bindgen_path);
cmd.arg(&wasm_path) cmd.arg(&wasm_path)
.arg("--out-dir") .arg("--out-dir")
.arg(out_dir) .arg(out_dir)
@ -70,3 +79,13 @@ pub fn wasm_bindgen_build(
child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?; child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
Ok(()) Ok(())
} }
/// Check if the `wasm-bindgen` dependency is locally satisfied.
fn supports_web_target(cli_path: &PathBuf) -> Result<bool, failure::Error> {
let cli_version = semver::Version::parse(&install::get_cli_version(
&install::Tool::WasmBindgen,
cli_path,
)?)?;
let expected_version = semver::Version::parse("0.2.39")?;
Ok(cli_version >= expected_version)
}

@ -24,7 +24,7 @@ pub fn new_command(program: &str) -> Command {
} }
} }
/// Run the given command and return its stdout. /// Run the given command and return on success.
pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> { pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> {
info!("Running {:?}", command); info!("Running {:?}", command);

@ -63,7 +63,7 @@ pub fn download_prebuilt_or_cargo_install(
} }
/// Check if the tool dependency is locally satisfied. /// Check if the tool dependency is locally satisfied.
fn check_version( pub fn check_version(
tool: &Tool, tool: &Tool,
path: &PathBuf, path: &PathBuf,
expected_version: &str, expected_version: &str,
@ -75,24 +75,24 @@ fn check_version(
expected_version.to_string() expected_version.to_string()
}; };
let v = get_cli_version(tool, path)?;
info!(
"Checking installed `{}` version == expected version: {} == {}",
tool, v, &expected_version
);
Ok(v == expected_version)
}
/// Fetches the version of a CLI tool
pub fn get_cli_version(tool: &Tool, path: &PathBuf) -> Result<String, failure::Error> {
let mut cmd = Command::new(path); let mut cmd = Command::new(path);
cmd.arg("--version"); cmd.arg("--version");
child::run_capture_stdout(cmd, tool) let stdout = child::run_capture_stdout(cmd, tool)?;
.map(|stdout| { let version = stdout.trim().split_whitespace().nth(1);
stdout match version {
.trim() Some(v) => Ok(v.to_string()),
.split_whitespace() None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.")
.nth(1) }
.map(|v| {
info!(
"Checking installed `{}` version == expected version: {} == {}",
tool, v, &expected_version
);
Ok(v == expected_version)
})
.unwrap_or(Ok(false))
})
.unwrap_or(Ok(false))
} }
/// Downloads a precompiled copy of the tool, if available. /// Downloads a precompiled copy of the tool, if available.

@ -9,6 +9,7 @@ extern crate strsim;
extern crate failure; extern crate failure;
extern crate glob; extern crate glob;
extern crate parking_lot; extern crate parking_lot;
extern crate semver;
extern crate serde; extern crate serde;
extern crate which; extern crate which;
#[macro_use] #[macro_use]

@ -368,12 +368,12 @@ impl CrateData {
.position(|pkg| pkg.name == manifest.package.name) .position(|pkg| pkg.name == manifest.package.name)
.ok_or_else(|| format_err!("failed to find package in metadata"))?; .ok_or_else(|| format_err!("failed to find package in metadata"))?;
return Ok(CrateData { Ok(CrateData {
data, data,
manifest, manifest,
current_idx, current_idx,
out_name, out_name,
}); })
} }
/// Read the `manifest_path` file and deserializes it using the toml Deserializer. /// Read the `manifest_path` file and deserializes it using the toml Deserializer.

@ -104,6 +104,54 @@ fn renamed_crate_name_works() {
fixture.wasm_pack().arg("build").assert().success(); fixture.wasm_pack().arg("build").assert().success();
} }
#[test]
fn dash_dash_web_target_has_error_on_old_bindgen() {
let fixture = utils::fixture::Fixture::new();
fixture
.readme()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
[lib]
crate-type = ["cdylib"]
name = 'bar'
[dependencies]
wasm-bindgen = "=0.2.37"
"#,
)
.file(
"src/lib.rs",
r#"
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn one() -> u32 { 1 }
"#,
)
.install_local_wasm_bindgen();
let cmd = fixture
.wasm_pack()
.arg("build")
.arg("--target")
.arg("web")
.assert()
.failure();
let output = String::from_utf8(cmd.get_output().stderr.clone()).unwrap();
assert!(
output.contains("0.2.39"),
"Output did not contain '0.2.39', output was {}",
output
);
}
#[test] #[test]
fn it_should_build_nested_project_with_transitive_dependencies() { fn it_should_build_nested_project_with_transitive_dependencies() {
let fixture = utils::fixture::transitive_dependencies(); let fixture = utils::fixture::transitive_dependencies();

Loading…
Cancel
Save