Skip to content

Commit ccf500c

Browse files
DogeDarkjkelleyrtp
andauthoredDec 11, 2024
Feat: CLI wasm-bindgen-cli Installer (DioxusLabs#3335)
* feat: wasm-bindgen-cli installer --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
1 parent 3e1e7f0 commit ccf500c

File tree

10 files changed

+650
-309
lines changed

10 files changed

+650
-309
lines changed
 

‎Cargo.lock

+158-245
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ futures-channel = "0.3.21"
168168
futures-util = { version = "0.3", default-features = false }
169169
rustc-hash = "1.1.0"
170170
wasm-bindgen = "0.2.99"
171-
wasm-bindgen-cli-support = "0.2.99"
172-
wasm-bindgen-shared = "0.2.99"
173171
wasm-bindgen-futures = "0.4.42"
174172
js-sys = "0.3.76"
175173
web-sys = { version = "0.3.76", default-features = false }

‎packages/cli/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ dioxus-dx-wire-format = { workspace = true }
2727
clap = { workspace = true, features = ["derive", "cargo"] }
2828
convert_case = { workspace = true }
2929
thiserror = { workspace = true }
30-
wasm-bindgen-cli-support = { workspace = true }
31-
wasm-bindgen-shared = { workspace = true }
3230
uuid = { version = "1.3.0", features = ["v4"] }
3331
serde = { workspace = true, features = ["derive"] }
3432
serde_json = { workspace = true }
@@ -120,6 +118,8 @@ strum = { version = "0.26.3", features = ["derive"] }
120118
tauri-utils = { workspace = true }
121119
tauri-bundler = { workspace = true }
122120
include_dir = "0.7.4"
121+
flate2 = "1.0.35"
122+
tar = "0.4.43"
123123

124124
[build-dependencies]
125125
built = { version = "=0.7.4", features = ["git2"] }

‎packages/cli/src/build/bundle.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use super::templates::InfoPlistData;
2+
use crate::wasm_bindgen::WasmBindgenBuilder;
13
use crate::{BuildRequest, Platform};
24
use crate::{Result, TraceSrc};
35
use anyhow::Context;
@@ -10,9 +12,6 @@ use std::path::{Path, PathBuf};
1012
use std::pin::Pin;
1113
use std::{sync::atomic::AtomicUsize, time::Duration};
1214
use tokio::process::Command;
13-
use wasm_bindgen_cli_support::Bindgen;
14-
15-
use super::templates::InfoPlistData;
1615

1716
/// The end result of a build.
1817
///
@@ -610,22 +609,27 @@ impl AppBundle {
610609
&& !self.build.build.release;
611610

612611
let start = std::time::Instant::now();
613-
tokio::task::spawn_blocking(move || {
614-
Bindgen::new()
615-
.input_path(&input_path)
616-
.web(true)
617-
.unwrap()
618-
.debug(keep_debug)
619-
.demangle(keep_debug)
620-
.keep_debug(keep_debug)
621-
.remove_name_section(!keep_debug)
622-
.remove_producers_section(!keep_debug)
623-
.out_name(&name)
624-
.generate(&bindgen_outdir)
625-
})
626-
.await
627-
.context("Wasm-bindgen crashed while optimizing the wasm binary")?
628-
.context("Failed to generate wasm-bindgen bindings")?;
612+
613+
let bindgen_version = self
614+
.build
615+
.krate
616+
.wasm_bindgen_version()
617+
.expect("this should have been checked by tool verification");
618+
619+
WasmBindgenBuilder::new(bindgen_version)
620+
.input_path(&input_path)
621+
.target("web")
622+
.debug(keep_debug)
623+
.demangle(keep_debug)
624+
.keep_debug(keep_debug)
625+
.remove_name_section(!keep_debug)
626+
.remove_producers_section(!keep_debug)
627+
.out_name(&name)
628+
.out_dir(&bindgen_outdir)
629+
.build()
630+
.run()
631+
.await
632+
.context("Failed to generate wasm-bindgen bindings")?;
629633

630634
tracing::debug!(dx_src = ?TraceSrc::Bundle, "wasm-bindgen complete in {:?}", start.elapsed());
631635

‎packages/cli/src/build/verify.rs

+12-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use std::process::Stdio;
2-
3-
use crate::{BuildRequest, Platform, Result, RustupShow};
4-
use anyhow::Context;
1+
use crate::{wasm_bindgen::WasmBindgen, BuildRequest, Platform, Result, RustupShow};
2+
use anyhow::{anyhow, Context};
53
use tokio::process::Command;
64

75
impl BuildRequest {
@@ -40,6 +38,7 @@ impl BuildRequest {
4038
}
4139

4240
pub(crate) async fn verify_web_tooling(&self, rustup: RustupShow) -> Result<()> {
41+
// Rust wasm32 target
4342
if !rustup.has_wasm32_unknown_unknown() {
4443
tracing::info!(
4544
"Web platform requires wasm32-unknown-unknown to be installed. Installing..."
@@ -50,38 +49,16 @@ impl BuildRequest {
5049
.await?;
5150
}
5251

53-
let our_wasm_bindgen_version = wasm_bindgen_shared::version();
54-
match self.krate.wasm_bindgen_version() {
55-
Some(version) if version == our_wasm_bindgen_version => {
56-
tracing::debug!("wasm-bindgen version {version} is compatible with dioxus-cli ✅");
57-
},
58-
Some(version) => {
59-
tracing::warn!(
60-
"wasm-bindgen version {version} is not compatible with the cli crate ({}). Attempting to upgrade the target wasm-bindgen crate manually...",
61-
our_wasm_bindgen_version
62-
);
63-
64-
let output = Command::new("cargo")
65-
.args([
66-
"update",
67-
"-p",
68-
"wasm-bindgen",
69-
"--precise",
70-
&our_wasm_bindgen_version,
71-
])
72-
.stderr(Stdio::piped())
73-
.stdout(Stdio::piped())
74-
.output()
75-
.await;
76-
77-
match output {
78-
Ok(output) if output.status.success() => tracing::info!("✅ wasm-bindgen updated successfully"),
79-
Ok(output) => tracing::error!("Failed to update wasm-bindgen: {:?}", output),
80-
Err(err) => tracing::error!("Failed to update wasm-bindgen: {err}"),
81-
}
52+
// Wasm bindgen
53+
let krate_bindgen_version = self.krate.wasm_bindgen_version().ok_or(anyhow!(
54+
"failed to detect wasm-bindgen version, unable to proceed"
55+
))?;
8256

83-
}
84-
None => tracing::debug!("User is attempting a web build without wasm-bindgen detected. This is probably a bug in the dioxus-cli."),
57+
let is_installed = WasmBindgen::verify_install(&krate_bindgen_version).await?;
58+
if !is_installed {
59+
WasmBindgen::install(&krate_bindgen_version)
60+
.await
61+
.context("failed to install wasm-bindgen-cli")?;
8562
}
8663

8764
Ok(())

‎packages/cli/src/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ mod filemap;
1515
mod logging;
1616
mod metadata;
1717
mod platform;
18-
mod profiles;
1918
mod rustup;
2019
mod serve;
2120
mod settings;
22-
mod slog;
23-
mod tooling;
21+
mod wasm_bindgen;
2422

2523
pub(crate) use build::*;
2624
pub(crate) use cli::*;

‎packages/cli/src/profiles.rs

-1
This file was deleted.

‎packages/cli/src/slog.rs

-1
This file was deleted.

‎packages/cli/src/tooling.rs

-1
This file was deleted.

‎packages/cli/src/wasm_bindgen.rs

+454
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.