Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install the exact wasm-bindgen-cli version matching the wasm-bindgen version #208

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,27 @@ pub fn build(args: &BuildArgs) -> anyhow::Result<()> {
}

pub(crate) fn ensure_web_setup() -> anyhow::Result<()> {
// The resolved dependency graph is needed to ensure the `wasm-bindgen-cli` version matches
// exactly the `wasm-bindgen` version
let metadata = cargo::metadata::metadata()?;

let wasm_bindgen_version = metadata
.packages
.iter()
.find(|package| package.name == "wasm-bindgen")
BD103 marked this conversation as resolved.
Show resolved Hide resolved
.map(|package| package.version.to_string())
.ok_or_else(|| anyhow::anyhow!("Failed to find wasm-bindgen"))?;

// `wasm32-unknown-unknown` compilation target
rustup::install_target_if_needed("wasm32-unknown-unknown")?;
// `wasm-bindgen-cli` for bundling
cargo::install::if_needed(wasm_bindgen::PROGRAM, wasm_bindgen::PACKAGE, true, false)?;
cargo::install::if_needed(
wasm_bindgen::PROGRAM,
wasm_bindgen::PACKAGE,
Some(&wasm_bindgen_version),
true,
false,
)?;

Ok(())
}
11 changes: 8 additions & 3 deletions src/external_cli/cargo/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn is_installed(program: &str) -> bool {
pub(crate) fn if_needed(
program: &str,
package: &str,
package_version: Option<&str>,
ask_user: bool,
hidden: bool,
) -> anyhow::Result<bool> {
DaAlbrecht marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -42,15 +43,19 @@ pub(crate) fn if_needed(
let mut cmd = Command::new(super::program());
cmd.arg("install").arg(package);

if let Some(version) = package_version {
cmd.arg("--version").arg(version);
}

let status = if hidden {
cmd.output()?.status
} else {
cmd.status()?
};

if !status.success() {
Err(anyhow::anyhow!("Failed to install `{program}`."))
} else {
if status.success() {
Ok(true)
} else {
Err(anyhow::anyhow!("Failed to install `{program}`."))
}
}
Loading