Skip to content

Commit b28b3cd

Browse files
committed
Added logic to the bindgen::cargo_install_wasm_bindgen function to check if 'wasm-bindgen' already exists in the path.
1 parent 0f01272 commit b28b3cd

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/bindgen.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
use PBAR;
21
use console::style;
32
use emoji;
4-
use std::process::Command;
3+
use std::{env, fs, process::Command};
4+
use PBAR;
5+
6+
#[cfg(target_family = "windows")]
7+
static PATH_SEP: &str = ";";
8+
9+
#[cfg(not(target_family = "windows"))]
10+
static PATH_SEP: &str = ":";
511

612
pub fn cargo_install_wasm_bindgen() {
13+
if wasm_bindgen_installed() {
14+
return;
15+
}
716
let step = format!(
817
"{} {}Installing WASM-bindgen...",
918
style("[6/7]").bold().dim(),
@@ -36,3 +45,16 @@ pub fn wasm_bindgen_build(path: &str, name: &str) {
3645
.unwrap_or_else(|e| panic!("{} failed to execute process: {}", emoji::ERROR, e));
3746
pb.finish();
3847
}
48+
49+
fn wasm_bindgen_installed() -> bool {
50+
if let Ok(path) = env::var("PATH") {
51+
path.split(PATH_SEP)
52+
.map(|p: &str| -> bool {
53+
let prog_str = format!("{}/wasm-bindgen", p);
54+
fs::metadata(prog_str).is_ok()
55+
})
56+
.fold(false, |res, b| res || b)
57+
} else {
58+
false
59+
}
60+
}

src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use PBAR;
21
use console::style;
32
use emoji;
43
use std::process::Command;
4+
use PBAR;
55

66
pub fn rustup_add_wasm_target() {
77
let step = format!(

src/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::fs::File;
22
use std::io::prelude::*;
33

4-
use PBAR;
54
use console::style;
65
use emoji;
76
use failure::Error;
87
use serde_json;
98
use toml;
9+
use PBAR;
1010

1111
#[derive(Deserialize)]
1212
struct CargoManifest {

src/readme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use console::style;
22
use failure::Error;
33
use std::fs;
44

5-
use PBAR;
65
use emoji;
6+
use PBAR;
77

88
pub fn copy_from_crate(path: &str) -> Result<(), Error> {
99
let step = format!(

0 commit comments

Comments
 (0)