Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Check version of wasm-bingen is compatible
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
cecton committed Dec 19, 2020
1 parent a34268f commit b7403aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ downcast-rs = "1.2.0"
futures = { version = "0.3.8" } # TODO should be optional but it's breaking for some reason
notify = "4.0.12"
once_cell = "1.5.2"
semver = "0.11"
structopt = "0.3"
tide = { version = "0.15", optional = true }
wasm-bindgen-cli-support = "0.2.68"
Expand Down
31 changes: 29 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
#![warn(missing_docs)]

use anyhow::{bail, Context, Result};
use cargo_metadata::MetadataCommand;
use cargo_metadata::{Metadata, Package};
use cargo_metadata::{Metadata, MetadataCommand, Package};
use downcast_rs::*;
use notify::RecommendedWatcher;
use once_cell::sync::OnceCell;
use semver::VersionReq;
use std::fs;
use std::path::PathBuf;
#[cfg(feature = "serve")]
Expand Down Expand Up @@ -369,8 +369,35 @@ fn build(mut profile: BuildProfile, args: &dyn BuildArgs, hooks: &Hooks) -> Resu
profile = BuildProfile::Profiling;
}

let wasm_run_package = args
.metadata()
.packages
.iter()
.find(|x| x.name == "wasm-run")
.context("could not find wasm-run in the dependencies")?;
let package = args.package();

fn get_wasm_bindgen_version(package: &Package) -> Result<&VersionReq> {
Ok(&package
.dependencies
.iter()
.find(|x| x.name.starts_with("wasm-bindgen"))
.context("could not find dependency wasm-bindgen")?
.req)
}

let our_version = get_wasm_bindgen_version(wasm_run_package)?;
let their_version = get_wasm_bindgen_version(package)?;

if their_version != our_version {
// TODO check if versionreq are compatible
bail!(
"incompatible version of wasm-bindgen detected: {} doesn't match {}",
their_version,
our_version,
);
}

let mut command = Command::new("cargo");

command
Expand Down

0 comments on commit b7403aa

Please sign in to comment.