From ccf500c77bb2f3a73adad684721a53acdfc384e4 Mon Sep 17 00:00:00 2001 From: Miles Murgaw Date: Wed, 11 Dec 2024 14:27:11 -0500 Subject: [PATCH] Feat: CLI `wasm-bindgen-cli` Installer (#3335) * feat: wasm-bindgen-cli installer --------- Co-authored-by: Jonathan Kelley --- Cargo.lock | 403 +++++++++++---------------- Cargo.toml | 2 - packages/cli/Cargo.toml | 4 +- packages/cli/src/build/bundle.rs | 42 +-- packages/cli/src/build/verify.rs | 47 +--- packages/cli/src/main.rs | 4 +- packages/cli/src/profiles.rs | 1 - packages/cli/src/slog.rs | 1 - packages/cli/src/tooling.rs | 1 - packages/cli/src/wasm_bindgen.rs | 454 +++++++++++++++++++++++++++++++ 10 files changed, 650 insertions(+), 309 deletions(-) delete mode 100644 packages/cli/src/profiles.rs delete mode 100644 packages/cli/src/slog.rs delete mode 100644 packages/cli/src/tooling.rs create mode 100644 packages/cli/src/wasm_bindgen.rs diff --git a/Cargo.lock b/Cargo.lock index fb0955122e..df95080510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,9 +234,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "anymap2" @@ -773,9 +773,9 @@ dependencies = [ [[package]] name = "atk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" +checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" dependencies = [ "atk-sys", "glib", @@ -784,9 +784,9 @@ dependencies = [ [[package]] name = "atk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" +checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" dependencies = [ "glib-sys", "gobject-sys", @@ -882,7 +882,7 @@ dependencies = [ "aws-sdk-sts", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.60.7", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -940,9 +940,9 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.4.3" +version = "1.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10d5c055aa540164d9561a0e2e74ad30f0dcf7393c3a92f6733ddf9c5762468" +checksum = "b5ac934720fbb46206292d2c75b57e67acfc56fe7dfd34fb9a02334af08409ea" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -966,9 +966,9 @@ dependencies = [ [[package]] name = "aws-sdk-s3" -version = "1.64.0" +version = "1.65.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35fe5e7f71b1cc6274e905d3bcc7daf94099ac2d4cba83447ffb959b5b27b3c1" +checksum = "d3ba2c5c0f2618937ce3d4a5ad574b86775576fa24006bcb3128c6e2cbf3c34e" dependencies = [ "aws-credential-types", "aws-runtime", @@ -977,7 +977,7 @@ dependencies = [ "aws-smithy-checksums", "aws-smithy-eventstream", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -1000,15 +1000,15 @@ dependencies = [ [[package]] name = "aws-sdk-sso" -version = "1.49.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09677244a9da92172c8dc60109b4a9658597d4d298b188dd0018b6a66b410ca4" +checksum = "05ca43a4ef210894f93096039ef1d6fa4ad3edfabb3be92b80908b9f2e4b4eab" dependencies = [ "aws-credential-types", "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -1022,15 +1022,15 @@ dependencies = [ [[package]] name = "aws-sdk-ssooidc" -version = "1.50.0" +version = "1.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fea2f3a8bb3bd10932ae7ad59cc59f65f270fc9183a7e91f501dc5efbef7ee" +checksum = "abaf490c2e48eed0bb8e2da2fb08405647bd7f253996e0f93b981958ea0f73b0" dependencies = [ "aws-credential-types", "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", @@ -1044,15 +1044,15 @@ dependencies = [ [[package]] name = "aws-sdk-sts" -version = "1.50.0" +version = "1.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ada54e5f26ac246dc79727def52f7f8ed38915cb47781e2a72213957dc3a7d5" +checksum = "b68fde0d69c8bfdc1060ea7da21df3e39f6014da316783336deff0a9ec28f4bf" dependencies = [ "aws-credential-types", "aws-runtime", "aws-smithy-async", "aws-smithy-http", - "aws-smithy-json", + "aws-smithy-json 0.61.1", "aws-smithy-query", "aws-smithy-runtime", "aws-smithy-runtime-api", @@ -1067,9 +1067,9 @@ dependencies = [ [[package]] name = "aws-sigv4" -version = "1.2.5" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5619742a0d8f253be760bfbb8e8e8368c69e3587e4637af5754e488a611499b1" +checksum = "7d3820e0c08d0737872ff3c7c1f21ebbb6693d832312d6152bf18ef50a5471c2" dependencies = [ "aws-credential-types", "aws-smithy-eventstream", @@ -1082,7 +1082,7 @@ dependencies = [ "hex", "hmac", "http 0.2.12", - "http 1.1.0", + "http 1.2.0", "once_cell", "p256 0.11.1", "percent-encoding", @@ -1167,6 +1167,15 @@ dependencies = [ "aws-smithy-types", ] +[[package]] +name = "aws-smithy-json" +version = "0.61.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4e69cc50921eb913c6b662f8d909131bb3e6ad6cb6090d3a39b66fc5c52095" +dependencies = [ + "aws-smithy-types", +] + [[package]] name = "aws-smithy-query" version = "0.60.7" @@ -1179,9 +1188,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.7.3" +version = "1.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be28bd063fa91fd871d131fc8b68d7cd4c5fa0869bea68daca50dcb1cbd76be2" +checksum = "9f20685047ca9d6f17b994a07f629c813f08b5bce65523e47124879e60103d45" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -1214,7 +1223,7 @@ dependencies = [ "aws-smithy-types", "bytes", "http 0.2.12", - "http 1.1.0", + "http 1.2.0", "pin-project-lite", "tokio", "tracing", @@ -1232,7 +1241,7 @@ dependencies = [ "bytes-utils", "futures-core", "http 0.2.12", - "http 1.1.0", + "http 1.2.0", "http-body 0.4.6", "http-body 1.0.1", "http-body-util", @@ -1310,7 +1319,7 @@ dependencies = [ "base64 0.22.1", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "hyper 1.5.1", @@ -1363,7 +1372,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "mime", @@ -1387,7 +1396,7 @@ dependencies = [ "fastrand", "futures-util", "headers", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "mime", @@ -1419,7 +1428,7 @@ dependencies = [ "arc-swap", "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "hyper 1.5.1", @@ -1429,7 +1438,7 @@ dependencies = [ "rustls-pemfile 2.2.0", "rustls-pki-types", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tower 0.4.13", "tower-service", ] @@ -1451,7 +1460,7 @@ dependencies = [ "forwarded-header-value", "futures", "hmac", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "rand 0.8.5", "serde", @@ -1481,7 +1490,7 @@ dependencies = [ "chrono", "dashmap", "futures", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "serde", "tokio", @@ -2120,9 +2129,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" dependencies = [ "jobserver", "libc", @@ -2203,9 +2212,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -2266,9 +2275,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -2276,9 +2285,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -2301,9 +2310,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "cmac" @@ -2605,18 +2614,18 @@ dependencies = [ [[package]] name = "const_format" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" dependencies = [ "const_format_proc_macros", ] [[package]] name = "const_format_proc_macros" -version = "0.2.33" +version = "0.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" dependencies = [ "proc-macro2", "quote", @@ -3471,6 +3480,7 @@ dependencies = [ "dirs", "env_logger 0.11.5", "escargot", + "flate2", "futures-channel", "futures-util", "handlebars", @@ -3501,6 +3511,7 @@ dependencies = [ "serde_json", "strum 0.26.3", "syn 2.0.90", + "tar", "tauri-bundler", "tauri-utils", "tempfile", @@ -3519,8 +3530,6 @@ dependencies = [ "uuid", "walkdir", "walrus", - "wasm-bindgen-cli-support", - "wasm-bindgen-shared", "wasm-opt", ] @@ -3830,7 +3839,7 @@ dependencies = [ "futures-channel", "futures-util", "generational-box", - "http 1.1.0", + "http 1.2.0", "hyper 1.5.1", "hyper-rustls 0.27.3", "once_cell", @@ -3942,7 +3951,7 @@ name = "dioxus-isrg" version = "0.6.0" dependencies = [ "chrono", - "http 1.1.0", + "http 1.2.0", "lru 0.12.5", "rustc-hash 1.1.0", "thiserror 1.0.69", @@ -4764,15 +4773,15 @@ checksum = "a2a2b11eda1d40935b26cf18f6833c526845ae8c41e58d09af6adeb6f0269183" [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fdeflate" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c6f4c64c1d33a3111c4466f7365ebdcc37c5bd1ea0d62aae2e3d722aacbedb" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" dependencies = [ "simd-adler32", ] @@ -5018,7 +5027,7 @@ dependencies = [ "dioxus-fullstack", "dioxus-web", "execute", - "http 1.1.0", + "http 1.2.0", "serde", "sqlx", "tokio", @@ -5215,9 +5224,9 @@ dependencies = [ [[package]] name = "gdk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" +checksum = "d9f245958c627ac99d8e529166f9823fb3b838d1d41fd2b297af3075093c2691" dependencies = [ "cairo-rs", "gdk-pixbuf", @@ -5256,9 +5265,9 @@ dependencies = [ [[package]] name = "gdk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" +checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", @@ -5273,9 +5282,9 @@ dependencies = [ [[package]] name = "gdkwayland-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a90fbf5c033c65d93792192a49a8efb5bb1e640c419682a58bb96f5ae77f3d4a" +checksum = "140071d506d223f7572b9f09b5e155afbd77428cd5cc7af8f2694c41d98dfe69" dependencies = [ "gdk-sys", "glib-sys", @@ -5287,9 +5296,9 @@ dependencies = [ [[package]] name = "gdkx11" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2ea8a4909d530f79921290389cbd7c34cb9d623bfe970eaae65ca5f9cd9cce" +checksum = "3caa00e14351bebbc8183b3c36690327eb77c49abc2268dd4bd36b856db3fbfe" dependencies = [ "gdk", "gdkx11-sys", @@ -5301,9 +5310,9 @@ dependencies = [ [[package]] name = "gdkx11-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee8f00f4ee46cad2939b8990f5c70c94ff882c3028f3cc5abf950fa4ab53043" +checksum = "6e2e7445fe01ac26f11601db260dd8608fe172514eb63b3b5e261ea6b0f4428d" dependencies = [ "gdk-sys", "glib-sys", @@ -5495,7 +5504,7 @@ dependencies = [ "bstr", "gix-path", "libc", - "thiserror 2.0.3", + "thiserror 2.0.6", ] [[package]] @@ -5598,7 +5607,7 @@ dependencies = [ "gix-trace", "home", "once_cell", - "thiserror 2.0.3", + "thiserror 2.0.6", ] [[package]] @@ -5788,7 +5797,7 @@ dependencies = [ "futures-core", "futures-sink", "gloo-utils", - "http 1.1.0", + "http 1.2.0", "js-sys", "pin-project", "serde", @@ -5978,9 +5987,9 @@ dependencies = [ [[package]] name = "gtk" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" +checksum = "fd56fb197bfc42bd5d2751f4f017d44ff59fbb58140c6b49f9b3b2bdab08506a" dependencies = [ "atk", "cairo-rs", @@ -5999,9 +6008,9 @@ dependencies = [ [[package]] name = "gtk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" +checksum = "8f29a1c21c59553eb7dd40e918be54dccd60c52b049b75119d5d96ce6b624414" dependencies = [ "atk-sys", "cairo-sys-rs", @@ -6017,9 +6026,9 @@ dependencies = [ [[package]] name = "gtk3-macros" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" +checksum = "52ff3c5b21f14f0736fed6dcfc0bfb4225ebf5725f3c0209edeec181e4d73e9d" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro-error", @@ -6058,7 +6067,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", + "http 1.2.0", "indexmap 2.7.0", "slab", "tokio", @@ -6177,7 +6186,7 @@ dependencies = [ "base64 0.21.7", "bytes", "headers-core", - "http 1.1.0", + "http 1.2.0", "httpdate", "mime", "sha1", @@ -6189,7 +6198,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54b4a22553d4242c49fddb9ba998a99962b5cc6f22cb5a3482bec22522403ce4" dependencies = [ - "http 1.1.0", + "http 1.2.0", ] [[package]] @@ -6325,9 +6334,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" dependencies = [ "bytes", "fnv", @@ -6352,7 +6361,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http 1.2.0", ] [[package]] @@ -6363,7 +6372,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "pin-project-lite", ] @@ -6432,7 +6441,7 @@ dependencies = [ "futures-channel", "futures-util", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "httparse", "httpdate", @@ -6466,7 +6475,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", - "http 1.1.0", + "http 1.2.0", "hyper 1.5.1", "hyper-util", "log", @@ -6474,7 +6483,7 @@ dependencies = [ "rustls-native-certs 0.8.1", "rustls-pki-types", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tower-service", "webpki-roots 0.26.7", ] @@ -6516,7 +6525,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "hyper 1.5.1", "pin-project-lite", @@ -7268,9 +7277,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "konst" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65f00fb3910881e52bf0850ae2a82aea411488a557e1c02820ceaa60963dce3" +checksum = "298ddf99f06a97c1ecd0e910932662b7842855046234b0d0376d35d93add087f" dependencies = [ "const_panic", "konst_kernel", @@ -7279,9 +7288,9 @@ dependencies = [ [[package]] name = "konst_kernel" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "599c1232f55c72c7fc378335a3efe1c878c92720838c8e6a4fd87784ef7764de" +checksum = "e4b1eb7788f3824c629b1116a7a9060d6e898c358ebff59070093d51103dcc3c" dependencies = [ "typewit", ] @@ -7418,9 +7427,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.167" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "libfuzzer-sys" @@ -8065,7 +8074,7 @@ dependencies = [ "bytes", "encoding_rs", "futures-util", - "http 1.1.0", + "http 1.2.0", "httparse", "memchr", "mime", @@ -9065,20 +9074,20 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" +checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 1.0.69", + "thiserror 2.0.6", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d214365f632b123a47fd913301e14c946c61d1c183ee245fa76eb752e59a02dd" +checksum = "816518421cfc6887a0d62bf441b6ffb4536fcc926395a69e1a85852d4363f57e" dependencies = [ "pest", "pest_generator", @@ -9086,9 +9095,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb55586734301717aea2ac313f50b2eb8f60d2fc3dc01d190eefa2e625f60c4e" +checksum = "7d1396fd3a870fc7838768d171b4616d5c91f6cc25e377b673d714567d99377b" dependencies = [ "pest", "pest_meta", @@ -9099,9 +9108,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.14" +version = "2.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75da2a70cf4d9cb76833c990ac9cd3923c9a8905a8929789ce347c84564d03d" +checksum = "e1e58089ea25d717bfd31fb534e4f3afcc2cc569c70de3e239778991ea3b7dea" dependencies = [ "once_cell", "pest", @@ -9455,9 +9464,9 @@ dependencies = [ [[package]] name = "png" -version = "0.17.14" +version = "0.17.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0" +checksum = "b67582bd5b65bdff614270e2ea89a1cf15bef71245cc1e5f7ea126977144211d" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -9802,7 +9811,7 @@ dependencies = [ "rustc-hash 2.1.0", "rustls 0.23.19", "socket2", - "thiserror 2.0.3", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -9821,7 +9830,7 @@ dependencies = [ "rustls 0.23.19", "rustls-pki-types", "slab", - "thiserror 2.0.3", + "thiserror 2.0.6", "tinyvec", "tracing", "web-time", @@ -9829,9 +9838,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +checksum = "52cd4b1eff68bf27940dd39811292c49e007f4d0b4c357358dc9b0197be6b527" dependencies = [ "cfg_aliases 0.2.1", "libc", @@ -10253,7 +10262,7 @@ dependencies = [ "futures-core", "futures-util", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "hyper 1.5.1", @@ -10280,7 +10289,7 @@ dependencies = [ "system-configuration 0.6.1", "tokio", "tokio-native-tls", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tokio-util", "tower-service", "url", @@ -10539,15 +10548,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -10923,9 +10932,9 @@ checksum = "f97841a747eef040fcd2e7b3b9a220a7205926e60488e673d9e4926d27772ce5" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] @@ -10966,9 +10975,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -11095,7 +11104,7 @@ dependencies = [ "dashmap", "futures", "gloo-net", - "http 1.1.0", + "http 1.2.0", "http-body-util", "hyper 1.5.1", "inventory", @@ -13762,11 +13771,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.6", ] [[package]] @@ -13782,9 +13791,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312" dependencies = [ "proc-macro2", "quote", @@ -13824,9 +13833,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa 1.0.14", @@ -13847,9 +13856,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -13901,9 +13910,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.1" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "bytes", @@ -13961,20 +13970,19 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ "rustls 0.23.19", - "rustls-pki-types", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -14011,9 +14019,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -14158,7 +14166,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", "http-range-header", @@ -14357,7 +14365,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.1.0", + "http 1.2.0", "httparse", "log", "rand 0.8.5", @@ -14379,7 +14387,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.1.0", + "http 1.2.0", "httparse", "log", "native-tls", @@ -14398,7 +14406,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 1.1.0", + "http 1.2.0", "httparse", "log", "rand 0.8.5", @@ -14446,9 +14454,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "typewit" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51dbd25812f740f45e2a9769f84711982e000483b13b73a8a1852e092abac8c" +checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0" dependencies = [ "typewit_proc_macros", ] @@ -14663,9 +14671,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.10.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" dependencies = [ "base64 0.22.1", "log", @@ -14908,40 +14916,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-cli-support" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533e5315f66ba7a1c0b9731b1f6606a6fb7fc6d800eff4d5e43d48567f137203" -dependencies = [ - "anyhow", - "base64 0.22.1", - "log", - "rustc-demangle", - "serde", - "serde_json", - "tempfile", - "unicode-ident", - "walrus", - "wasm-bindgen-externref-xform", - "wasm-bindgen-multi-value-xform", - "wasm-bindgen-shared", - "wasm-bindgen-threads-xform", - "wasm-bindgen-wasm-conventions", - "wasm-bindgen-wasm-interpreter", -] - -[[package]] -name = "wasm-bindgen-externref-xform" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e71a35edea8d70380465025fcd6fb5376c9f2b5dacb2bc515bce5575e0ff0a2c" -dependencies = [ - "anyhow", - "walrus", - "wasm-bindgen-wasm-conventions", -] - [[package]] name = "wasm-bindgen-futures" version = "0.4.49" @@ -14978,17 +14952,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-multi-value-xform" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58d05670395e140f246c9fd6f59ca75da67030121e1679031089aa71309d0ee5" -dependencies = [ - "anyhow", - "walrus", - "wasm-bindgen-wasm-conventions", -] - [[package]] name = "wasm-bindgen-shared" version = "0.2.99" @@ -15020,42 +14983,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "wasm-bindgen-threads-xform" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e66a90d904cc4ff44f48e8ac3f606a42ecfda5cbe336e89b315127fe02952" -dependencies = [ - "anyhow", - "walrus", - "wasm-bindgen-wasm-conventions", -] - -[[package]] -name = "wasm-bindgen-wasm-conventions" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3523d0794bca5434b5e05d8cd7498ff7c6f2c86a4e5d790e35a3bd8e29c1351b" -dependencies = [ - "anyhow", - "leb128", - "log", - "walrus", - "wasmparser 0.212.0", -] - -[[package]] -name = "wasm-bindgen-wasm-interpreter" -version = "0.2.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d94f86fcc9c75aac4823f9cbf156ff37e3e8f4ebc1ccff2785e045efd9aeee1" -dependencies = [ - "anyhow", - "log", - "walrus", - "wasm-bindgen-wasm-conventions", -] - [[package]] name = "wasm-encoder" version = "0.214.0" @@ -15118,20 +15045,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wasmparser" -version = "0.212.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d28bc49ba1e5c5b61ffa7a2eace10820443c4b7d1c0b144109261d14570fdf8" -dependencies = [ - "ahash 0.8.11", - "bitflags 2.6.0", - "hashbrown 0.14.5", - "indexmap 2.7.0", - "semver 1.0.23", - "serde", -] - [[package]] name = "wasmparser" version = "0.214.0" @@ -15875,7 +15788,7 @@ dependencies = [ "gdkx11", "gtk", "html5ever", - "http 1.1.0", + "http 1.2.0", "javascriptcore-rs", "jni", "kuchikiki", @@ -15993,9 +15906,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" +checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" [[package]] name = "xmlparser" @@ -16220,7 +16133,7 @@ dependencies = [ "flate2", "indexmap 2.7.0", "memchr", - "thiserror 2.0.3", + "thiserror 2.0.6", "zopfli", ] diff --git a/Cargo.toml b/Cargo.toml index 2f13f023cd..f1ea28d571 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -168,8 +168,6 @@ futures-channel = "0.3.21" futures-util = { version = "0.3", default-features = false } rustc-hash = "1.1.0" wasm-bindgen = "0.2.99" -wasm-bindgen-cli-support = "0.2.99" -wasm-bindgen-shared = "0.2.99" wasm-bindgen-futures = "0.4.42" js-sys = "0.3.76" web-sys = { version = "0.3.76", default-features = false } diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index b289d70d4f..bbdb12c5bc 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -27,8 +27,6 @@ dioxus-dx-wire-format = { workspace = true } clap = { workspace = true, features = ["derive", "cargo"] } convert_case = { workspace = true } thiserror = { workspace = true } -wasm-bindgen-cli-support = { workspace = true } -wasm-bindgen-shared = { workspace = true } uuid = { version = "1.3.0", features = ["v4"] } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } @@ -120,6 +118,8 @@ strum = { version = "0.26.3", features = ["derive"] } tauri-utils = { workspace = true } tauri-bundler = { workspace = true } include_dir = "0.7.4" +flate2 = "1.0.35" +tar = "0.4.43" [build-dependencies] built = { version = "=0.7.4", features = ["git2"] } diff --git a/packages/cli/src/build/bundle.rs b/packages/cli/src/build/bundle.rs index fb43e922dc..6ff3e8dddb 100644 --- a/packages/cli/src/build/bundle.rs +++ b/packages/cli/src/build/bundle.rs @@ -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()); diff --git a/packages/cli/src/build/verify.rs b/packages/cli/src/build/verify.rs index 4ff5e07ef1..8488526d60 100644 --- a/packages/cli/src/build/verify.rs +++ b/packages/cli/src/build/verify.rs @@ -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 - ); - - 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}"), - } + // Wasm bindgen + let krate_bindgen_version = self.krate.wasm_bindgen_version().ok_or(anyhow!( + "failed to detect wasm-bindgen version, unable to proceed" + ))?; - } - 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(()) diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index 011d4e90ec..3f92e9d0f5 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -15,12 +15,10 @@ mod filemap; mod logging; mod metadata; mod platform; -mod profiles; mod rustup; mod serve; mod settings; -mod slog; -mod tooling; +mod wasm_bindgen; pub(crate) use build::*; pub(crate) use cli::*; diff --git a/packages/cli/src/profiles.rs b/packages/cli/src/profiles.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/packages/cli/src/profiles.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/cli/src/slog.rs b/packages/cli/src/slog.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/packages/cli/src/slog.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/cli/src/tooling.rs b/packages/cli/src/tooling.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/packages/cli/src/tooling.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/cli/src/wasm_bindgen.rs b/packages/cli/src/wasm_bindgen.rs new file mode 100644 index 0000000000..436689661f --- /dev/null +++ b/packages/cli/src/wasm_bindgen.rs @@ -0,0 +1,454 @@ +use anyhow::{anyhow, Context}; +use flate2::read::GzDecoder; +use std::{ + path::{Path, PathBuf}, + process::Stdio, +}; +use tar::Archive; +use tempfile::TempDir; +use tokio::{fs, process::Command}; + +pub(crate) struct WasmBindgen { + version: String, + input_path: PathBuf, + out_dir: PathBuf, + out_name: String, + target: String, + debug: bool, + keep_debug: bool, + demangle: bool, + remove_name_section: bool, + remove_producers_section: bool, +} + +impl WasmBindgen { + pub async fn run(&self) -> anyhow::Result<()> { + let binary = Self::final_binary(&self.version).await?; + + let mut args = Vec::new(); + + // Target + args.push("--target"); + args.push(&self.target); + + // Options + if self.debug { + args.push("--debug"); + } + + if !self.demangle { + args.push("--no-demangle"); + } + + if self.keep_debug { + args.push("--keep-debug"); + } + + if self.remove_name_section { + args.push("--remove-name-section"); + } + + if self.remove_producers_section { + args.push("--remove-producers-section"); + } + + // Out name + args.push("--out-name"); + args.push(&self.out_name); + + // Out dir + let out_dir = self + .out_dir + .to_str() + .expect("input_path should be valid utf8"); + + args.push("--out-dir"); + args.push(out_dir); + + // Input path + let input_path = self + .input_path + .to_str() + .expect("input_path should be valid utf8"); + args.push(input_path); + + // Run bindgen + Command::new(binary) + .args(args) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .await?; + + Ok(()) + } + + /// Verify that the required wasm-bindgen version is installed. + pub async fn verify_install(version: &str) -> anyhow::Result { + let binary_name = Self::installed_bin_name(version); + let path = Self::install_dir().await?.join(binary_name); + Ok(path.exists()) + } + + /// Install the specified wasm-bingen version. + /// + /// This will overwrite any existing wasm-bindgen binaries of the same version. + /// + /// This will attempt to install wasm-bindgen from: + /// 1. Direct GitHub release download. + /// 2. `cargo binstall` if installed. + /// 3. Compile from source with `cargo install`. + pub async fn install(version: &str) -> anyhow::Result<()> { + tracing::info!("Installing wasm-bindgen-cli@{version}..."); + + // Attempt installation from GitHub + if let Err(e) = Self::install_github(version).await { + tracing::error!("Failed to install wasm-bindgen-cli@{version}: {e}"); + } else { + tracing::info!("wasm-bindgen-cli@{version} was successfully installed from GitHub."); + return Ok(()); + } + + // Attempt installation from binstall. + if let Err(e) = Self::install_binstall(version).await { + tracing::error!("Failed to install wasm-bindgen-cli@{version}: {e}"); + tracing::info!("Failed to install prebuilt binary for wasm-bindgen-cli@{version}. Compiling from source instead. This may take a while."); + } else { + tracing::info!( + "wasm-bindgen-cli@{version} was successfully installed from cargo-binstall." + ); + return Ok(()); + } + + // Attempt installation from cargo. + Self::install_cargo(version) + .await + .context("failed to install wasm-bindgen-cli from cargo")?; + + tracing::info!("wasm-bindgen-cli@{version} was successfully installed from source."); + + Ok(()) + } + + /// Try installing wasm-bindgen-cli from GitHub. + async fn install_github(version: &str) -> anyhow::Result<()> { + tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from GitHub"); + + let url = git_install_url(version) + .ok_or_else(|| anyhow!("no available GitHub binary for wasm-bindgen-cli@{version}"))?; + + // Get the final binary location. + let final_binary = Self::final_binary(version).await?; + + // Download then extract wasm-bindgen-cli. + let bytes = reqwest::get(url).await?.bytes().await?; + + // Unpack the first tar entry to the final binary location + Archive::new(GzDecoder::new(bytes.as_ref())) + .entries()? + .find(|entry| { + entry + .as_ref() + .map(|e| { + e.path_bytes() + .ends_with(Self::downloaded_bin_name().as_bytes()) + }) + .unwrap_or(false) + }) + .context("Failed to find entry")?? + .unpack(&final_binary) + .context("failed to unpack wasm-bindgen-cli binary")?; + + Ok(()) + } + + /// Try installing wasm-bindgen-cli through cargo-binstall. + async fn install_binstall(version: &str) -> anyhow::Result<()> { + tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from cargo-binstall"); + + let package = Self::cargo_bin_name(version); + let tempdir = TempDir::new()?; + + // Run install command + Command::new("cargo") + .args([ + "binstall", + &package, + "--no-confirm", + "--force", + "--no-track", + "--install-path", + ]) + .arg(tempdir.path()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .await?; + + fs::copy( + tempdir.path().join(Self::downloaded_bin_name()), + Self::final_binary(version).await?, + ) + .await?; + + Ok(()) + } + + /// Try installing wasm-bindgen-cli from source using cargo install. + async fn install_cargo(version: &str) -> anyhow::Result<()> { + tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from cargo-install"); + let package = Self::cargo_bin_name(version); + let tempdir = TempDir::new()?; + + // Run install command + Command::new("cargo") + .args([ + "install", + &package, + "--bin", + "wasm-bindgen", + "--no-track", + "--force", + "--root", + ]) + .arg(tempdir.path()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .await + .context("failed to install wasm-bindgen-cli from cargo-install")?; + + tracing::info!("Copying into path: {}", tempdir.path().display()); + + // copy the wasm-bindgen out of the tempdir to the final location + fs::copy( + tempdir.path().join("bin").join(Self::downloaded_bin_name()), + Self::final_binary(version).await?, + ) + .await + .context("failed to copy wasm-bindgen binary")?; + + Ok(()) + } + + /// Get the installation directory for the wasm-bindgen executable. + async fn install_dir() -> anyhow::Result { + let bindgen_dir = dirs::data_local_dir() + .expect("user should be running on a compatible operating system") + .join("dioxus/wasm-bindgen/"); + + fs::create_dir_all(&bindgen_dir).await?; + + Ok(bindgen_dir) + } + + /// Get the name of a potentially installed wasm-bindgen binary. + fn installed_bin_name(version: &str) -> String { + let mut name = format!("wasm-bindgen-{version}"); + if cfg!(windows) { + name = format!("{name}.exe"); + } + name + } + + /// Get the crates.io package name of wasm-bindgen-cli. + fn cargo_bin_name(version: &str) -> String { + format!("wasm-bindgen-cli@{version}") + } + + async fn final_binary(version: &str) -> Result { + let installed_name = Self::installed_bin_name(version); + let install_dir = Self::install_dir().await?; + Ok(install_dir.join(installed_name)) + } + + fn downloaded_bin_name() -> &'static str { + if cfg!(windows) { + "wasm-bindgen.exe" + } else { + "wasm-bindgen" + } + } +} + +/// Get the GitHub installation URL for wasm-bindgen if it exists. +fn git_install_url(version: &str) -> Option { + let platform = if cfg!(all(target_os = "windows", target_arch = "x86_64")) { + "x86_64-pc-windows-msvc" + } else if cfg!(all(target_os = "linux", target_arch = "x86_64")) { + "x86_64-unknown-linux-musl" + } else if cfg!(all(target_os = "linux", target_arch = "aarch64")) { + "aarch64-unknown-linux-gnu" + } else if cfg!(all(target_os = "macos", target_arch = "x86_64")) { + "x86_64-apple-darwin" + } else if cfg!(all(target_os = "macos", target_arch = "aarch64")) { + "aarch64-apple-darwin" + } else { + return None; + }; + + Some(format!("https://github.com/rustwasm/wasm-bindgen/releases/download/{version}/wasm-bindgen-{version}-{platform}.tar.gz")) +} + +/// A builder for WasmBindgen options. +pub(crate) struct WasmBindgenBuilder { + version: String, + input_path: PathBuf, + out_dir: PathBuf, + out_name: String, + target: String, + debug: bool, + keep_debug: bool, + demangle: bool, + remove_name_section: bool, + remove_producers_section: bool, +} + +impl WasmBindgenBuilder { + pub fn new(version: String) -> Self { + Self { + version, + input_path: PathBuf::new(), + out_dir: PathBuf::new(), + out_name: String::new(), + target: String::new(), + debug: true, + keep_debug: true, + demangle: true, + remove_name_section: false, + remove_producers_section: false, + } + } + + pub fn build(self) -> WasmBindgen { + WasmBindgen { + version: self.version, + input_path: self.input_path, + out_dir: self.out_dir, + out_name: self.out_name, + target: self.target, + debug: self.debug, + keep_debug: self.keep_debug, + demangle: self.demangle, + remove_name_section: self.remove_name_section, + remove_producers_section: self.remove_producers_section, + } + } + + pub fn input_path(self, input_path: &Path) -> Self { + Self { + input_path: input_path.to_path_buf(), + ..self + } + } + + pub fn out_dir(self, out_dir: &Path) -> Self { + Self { + out_dir: out_dir.to_path_buf(), + ..self + } + } + + pub fn out_name(self, out_name: &str) -> Self { + Self { + out_name: out_name.to_string(), + ..self + } + } + + pub fn target(self, target: &str) -> Self { + Self { + target: target.to_string(), + ..self + } + } + + pub fn debug(self, debug: bool) -> Self { + Self { debug, ..self } + } + + pub fn keep_debug(self, keep_debug: bool) -> Self { + Self { keep_debug, ..self } + } + + pub fn demangle(self, demangle: bool) -> Self { + Self { demangle, ..self } + } + + pub fn remove_name_section(self, remove_name_section: bool) -> Self { + Self { + remove_name_section, + ..self + } + } + + pub fn remove_producers_section(self, remove_producers_section: bool) -> Self { + Self { + remove_producers_section, + ..self + } + } +} + +#[cfg(test)] +mod test { + use super::*; + const VERSION: &str = "0.2.99"; + + /// Test the github installer. + #[tokio::test] + async fn test_github_install() { + reset_test().await; + WasmBindgen::install_github(VERSION).await.unwrap(); + test_verify_install().await; + verify_installation().await; + } + + /// Test the cargo installer. + #[tokio::test] + async fn test_cargo_install() { + reset_test().await; + WasmBindgen::install_cargo(VERSION).await.unwrap(); + test_verify_install().await; + verify_installation().await; + } + + // CI doesn't have binstall. + // Test the binstall installer + // #[tokio::test] + // async fn test_binstall_install() { + // reset_test().await; + // WasmBindgen::install_binstall(VERSION).await.unwrap(); + // test_verify_install().await; + // verify_installation().await; + // } + + /// Helper to test `WasmBindgen::verify_install` after an installation. + async fn test_verify_install() { + // Test install verification + let is_installed = WasmBindgen::verify_install(VERSION).await.unwrap(); + assert!( + is_installed, + "wasm-bingen install verification returned false after installation" + ); + } + + /// Helper to test that the installed binary actually exists. + async fn verify_installation() { + let path = WasmBindgen::install_dir().await.unwrap(); + let name = WasmBindgen::installed_bin_name(VERSION); + let binary = path.join(name); + assert!( + binary.exists(), + "wasm-bindgen binary doesn't exist after installation" + ); + } + + /// Delete the installed binary. The temp folder should be automatically deleted. + async fn reset_test() { + let path = WasmBindgen::install_dir().await.unwrap(); + let name = WasmBindgen::installed_bin_name(VERSION); + let binary = path.join(name); + let _ = fs::remove_file(binary).await; + } +}