From 22df3debbd743416ea5c815e77af8becc45d45fa Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 13 Mar 2024 13:17:34 +0100 Subject: [PATCH 1/2] Make wasm32 buildable `wasm-pack build --no-default-features -F wasm` --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 075247357e..02a919983a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -167,6 +167,8 @@ bench = false [lib] bench = false +# cdylib is required for wasm32-unknown-unknown +crate-type = ["lib", "cdylib"] [[bench]] name = "bench" From 3519b0a86ab9a030fc6225f1bd4126f51445dedd Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 13 Mar 2024 13:25:43 +0100 Subject: [PATCH 2/2] Auto-detect wasm target `wasm-pack build --no-default-features` The wasm feature still exists for compatibility but is a no-op. --- Cargo.toml | 10 ++++++++-- src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02a919983a..be9b5a12fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,10 @@ tracing = [ ] scenechange = [] serialize = ["serde", "toml", "v_frame/serialize", "serde-big-array", "av1-grain/serialize"] -wasm = ["wasm-bindgen"] + +# Left here for compatibility reasons. +# Does not do anything, the wasm target is auto-detected. +wasm = [] # Enables debug dumping of lookahead computation results, specifically: # - i-qres.png: quarter-resolution luma planes, @@ -106,7 +109,6 @@ console = { version = "0.15", optional = true } fern = { version = "0.6", optional = true } itertools = "0.12" simd_helpers = "0.1" -wasm-bindgen = { version = "0.2.90", optional = true } nom = { version = "7.1.3", optional = true } new_debug_unreachable = "1.0.4" av1-grain = "0.2.3" @@ -155,6 +157,10 @@ rand_chacha = "0.3" [target.'cfg(any(decode_test, decode_test_dav1d))'.dependencies] system-deps = "6" +# WASM +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown", target_vendor = "unknown"))'.dependencies] +wasm-bindgen = "0.2.90" + [[bin]] name = "rav1e" required-features = ["binaries"] diff --git a/src/lib.rs b/src/lib.rs index 7575b1f118..c517aaee3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,7 +135,7 @@ mod serialize { mod wasm_bindgen { cfg_if::cfg_if! { - if #[cfg(feature="wasm")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown", target_vendor = "unknown"))] { pub use wasm_bindgen::prelude::*; } else { pub use noop_proc_macro::wasm_bindgen;