Feat: CLI wasm-bindgen-cli Installer (#3335)

* feat: wasm-bindgen-cli installer

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Miles MurgawandJonathan Kelley authored and GitHub committed 2024-12-11 11:27:11 -08:00
1 parent 3e1e7f05e7
commit ccf500c77b
10 files changed
+650 -309

No files matched your search

+23 -19
View File
@@ -1,3 +1,5 @@
use super::templates::InfoPlistData;
use crate::wasm_bindgen::WasmBindgenBuilder;
use crate::{BuildRequest, Platform};
use crate::{Result, TraceSrc};
use anyhow::Context;
@@ -10,9 +12,6 @@ use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::{sync::atomic::AtomicUsize, time::Duration};
use tokio::process::Command;
use wasm_bindgen_cli_support::Bindgen;
use super::templates::InfoPlistData;
/// The end result of a build.
///
@@ -610,22 +609,27 @@ impl AppBundle {
&& !self.build.build.release;
let start = std::time::Instant::now();
tokio::task::spawn_blocking(move || {
Bindgen::new()
.input_path(&input_path)
.web(true)
.unwrap()
.debug(keep_debug)
.demangle(keep_debug)
.keep_debug(keep_debug)
.remove_name_section(!keep_debug)
.remove_producers_section(!keep_debug)
.out_name(&name)
.generate(&bindgen_outdir)
})
.await
.context("Wasm-bindgen crashed while optimizing the wasm binary")?
.context("Failed to generate wasm-bindgen bindings")?;
let bindgen_version = self
.build
.krate
.wasm_bindgen_version()
.expect("this should have been checked by tool verification");
WasmBindgenBuilder::new(bindgen_version)
.input_path(&input_path)
.target("web")
.debug(keep_debug)
.demangle(keep_debug)
.keep_debug(keep_debug)
.remove_name_section(!keep_debug)
.remove_producers_section(!keep_debug)
.out_name(&name)
.out_dir(&bindgen_outdir)
.build()
.run()
.await
.context("Failed to generate wasm-bindgen bindings")?;
tracing::debug!(dx_src = ?TraceSrc::Bundle, "wasm-bindgen complete in {:?}", start.elapsed());
+12 -35
View File
@@ -1,7 +1,5 @@
use std::process::Stdio;
use crate::{BuildRequest, Platform, Result, RustupShow};
use anyhow::Context;
use crate::{wasm_bindgen::WasmBindgen, BuildRequest, Platform, Result, RustupShow};
use anyhow::{anyhow, Context};
use tokio::process::Command;
impl BuildRequest {
@@ -40,6 +38,7 @@ impl BuildRequest {
}
pub(crate) async fn verify_web_tooling(&self, rustup: RustupShow) -> Result<()> {
// Rust wasm32 target
if !rustup.has_wasm32_unknown_unknown() {
tracing::info!(
"Web platform requires wasm32-unknown-unknown to be installed. Installing..."
@@ -50,38 +49,16 @@ impl BuildRequest {
.await?;
}
let our_wasm_bindgen_version = wasm_bindgen_shared::version();
match self.krate.wasm_bindgen_version() {
Some(version) if version == our_wasm_bindgen_version => {
tracing::debug!("wasm-bindgen version {version} is compatible with dioxus-cli ✅");
},
Some(version) => {
tracing::warn!(
"wasm-bindgen version {version} is not compatible with the cli crate ({}). Attempting to upgrade the target wasm-bindgen crate manually...",
our_wasm_bindgen_version
);
// Wasm bindgen
let krate_bindgen_version = self.krate.wasm_bindgen_version().ok_or(anyhow!(
"failed to detect wasm-bindgen version, unable to proceed"
))?;
let output = Command::new("cargo")
.args([
"update",
"-p",
"wasm-bindgen",
"--precise",
&our_wasm_bindgen_version,
])
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.output()
.await;
match output {
Ok(output) if output.status.success() => tracing::info!("✅ wasm-bindgen updated successfully"),
Ok(output) => tracing::error!("Failed to update wasm-bindgen: {:?}", output),
Err(err) => tracing::error!("Failed to update wasm-bindgen: {err}"),
}
}
None => tracing::debug!("User is attempting a web build without wasm-bindgen detected. This is probably a bug in the dioxus-cli."),
let is_installed = WasmBindgen::verify_install(&krate_bindgen_version).await?;
if !is_installed {
WasmBindgen::install(&krate_bindgen_version)
.await
.context("failed to install wasm-bindgen-cli")?;
}
Ok(())