@ -4,8 +4,10 @@ use binary_install::Download;
use child ;
use command ::build ::{ BuildProfile , Target } ;
use failure ::{ self , ResultExt } ;
use install ;
use manifest ::CrateData ;
use std ::path ::Path ;
use semver ;
use std ::path ::{ Path , PathBuf } ;
use std ::process ::Command ;
/// Run the `wasm-bindgen` CLI to generate bindings for the current crate's
@ -38,14 +40,21 @@ pub fn wasm_bindgen_build(
} else {
"--typescript"
} ;
let bindgen_path = bindgen . binary ( "wasm-bindgen" ) ? ;
let target_arg = match target {
Target ::Nodejs = > "--nodejs" ,
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" ,
} ;
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 )
. 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" ) ? ;
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 )
}