Skip to content

add emscripten support #4443

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ba825c3
allow emscripten
walkingeyerobot Dec 2, 2024
af0c20a
setup emscripten mode, this is tested with building --target=emscripten
google-yfyang Dec 23, 2024
c956845
setup emscripten mode, this is tested with building --target=emscripten
google-yfyang Dec 23, 2024
4bef9f5
setup emscripten mode, this is tested with building --target=emscripten
google-yfyang Dec 23, 2024
f798c1d
When targeting Emscripten, generate pre.js and library_wbg.js separat…
google-yfyang Jan 13, 2025
31e00db
Merge the two generated .js into one
google-yfyang Feb 11, 2025
ca2bc14
Merge pull request #4 from walkingeyerobot/yfyang
walkingeyerobot Feb 12, 2025
c3a0e58
Expand emscripten support to importing JS closures
google-yfyang Feb 20, 2025
b338824
Merge pull request #5 from walkingeyerobot/yfyang
walkingeyerobot Feb 21, 2025
948df4b
Add the necessary emscripten test mode.
google-yfyang Feb 24, 2025
d7adaf0
Merge pull request #6 from walkingeyerobot/yfyang
walkingeyerobot Feb 27, 2025
718b6fe
run cargo fmt
walkingeyerobot Feb 27, 2025
9130158
fix CI errors in wasm-bindgen
google-yfyang Mar 4, 2025
5c89b09
Get futures to work with emscripten mode
google-yfyang Mar 12, 2025
b4f6ec0
Merge pull request #7 from walkingeyerobot/yfyang
walkingeyerobot Mar 13, 2025
79892c4
Get futures to work with emscripten mode
google-yfyang Mar 12, 2025
5af1192
handle wasmExports better
walkingeyerobot Mar 14, 2025
57f3ffb
Merge pull request #8 from walkingeyerobot/mitchfoley
google-yfyang Mar 17, 2025
c398c44
update wasmparser
walkingeyerobot Mar 17, 2025
63c503c
Formatting and updating a few tests.
google-yfyang Mar 17, 2025
5d4984d
Update the license files.
google-yfyang Mar 19, 2025
6a67004
Expose more globals for emscripten
google-yfyang Apr 11, 2025
c93ca36
Merge pull request #9 from walkingeyerobot/yfyang
walkingeyerobot Apr 17, 2025
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
10 changes: 10 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[target.'cfg(target_arch = "wasm32")']
runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --'

[build]

[target.'cfg(all(target_arch = "wasm32", target_os = "emscripten"))']
rustflags = [
"-Cllvm-args=-enable-emscripten-cxx-exceptions=0",
"-Clink-arg=-sERROR_ON_UNDEFINED_SYMBOLS=0",
"-Clink-arg=-Wno-undefined",
"-Crelocation-model=static",
]
830 changes: 830 additions & 0 deletions 0001-Add-additional-licenses-to-futures-and-web-sys-crate.patch

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions crates/backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TryToTokens for ast::Program {
let prefix_json_bytes = syn::LitByteStr::new(&prefix_json_bytes, Span::call_site());

(quote! {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
#[automatically_derived]
const _: () = {
use #wasm_bindgen::__rt::{flat_len, flat_byte_slices};
Expand Down Expand Up @@ -281,12 +281,12 @@ impl ToTokens for ast::Struct {
let ptr = #wasm_bindgen::convert::IntoWasmAbi::into_abi(value);

#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
extern "C" {
fn #new_fn(ptr: u32) -> u32;
}

#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten"))))]
unsafe fn #new_fn(_: u32) -> u32 {
panic!("cannot convert to JsValue outside of the Wasm target")
}
Expand All @@ -298,7 +298,7 @@ impl ToTokens for ast::Struct {
}
}

#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
Expand Down Expand Up @@ -388,12 +388,12 @@ impl ToTokens for ast::Struct {
let idx = #wasm_bindgen::convert::IntoWasmAbi::into_abi(&value);

#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
extern "C" {
fn #unwrap_fn(ptr: u32) -> u32;
}

#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten"))))]
unsafe fn #unwrap_fn(_: u32) -> u32 {
panic!("cannot convert from JsValue outside of the Wasm target")
}
Expand Down Expand Up @@ -501,7 +501,7 @@ impl ToTokens for ast::StructField {
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
#[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")), no_mangle)]
#[cfg_attr(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")), no_mangle)]
#[doc(hidden)]
pub unsafe extern "C" fn #getter(js: u32)
-> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi>
Expand Down Expand Up @@ -540,7 +540,7 @@ impl ToTokens for ast::StructField {
let (args, names) = splat(wasm_bindgen, &Ident::new("val", rust_name.span()), &abi);

(quote! {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
Expand Down Expand Up @@ -847,7 +847,7 @@ impl TryToTokens for ast::Export {
#wasm_bindgen::__wbindgen_coverage! {
#(#attrs)*
#[cfg_attr(
all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")),
all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")),
export_name = #export_name,
)]
pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> {
Expand Down Expand Up @@ -1124,11 +1124,11 @@ impl ToTokens for ast::ImportType {
impl JsCast for #rust_name {
fn instanceof(val: &JsValue) -> bool {
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
extern "C" {
fn #instanceof_shim(val: u32) -> u32;
}
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten"))))]
unsafe fn #instanceof_shim(_: u32) -> u32 {
panic!("cannot check instanceof on non-wasm targets");
}
Expand Down Expand Up @@ -1838,12 +1838,12 @@ fn static_init(wasm_bindgen: &syn::Path, ty: &syn::Type, shim_name: &Ident) -> T
};
quote! {
#[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
extern "C" {
fn #shim_name() -> #abi_ret;
}

#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten"))))]
unsafe fn #shim_name() -> #abi_ret {
panic!("cannot access imported statics on non-wasm targets")
}
Expand Down Expand Up @@ -1888,7 +1888,7 @@ impl<T: ToTokens> ToTokens for Descriptor<'_, T> {
let attrs = &self.attrs;
let wasm_bindgen = &self.wasm_bindgen;
(quote! {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
#[automatically_derived]
const _: () = {
#wasm_bindgen::__wbindgen_coverage! {
Expand Down Expand Up @@ -1916,14 +1916,14 @@ fn extern_fn(
abi_ret: TokenStream,
) -> TokenStream {
quote! {
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))]
#[cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten")))]
#(#attrs)*
#[link(wasm_import_module = "__wbindgen_placeholder__")]
extern "C" {
fn #import_name(#(#abi_arguments),*) -> #abi_ret;
}

#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none", target_os = "emscripten"))))]
unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret {
#(
drop(#abi_argument_names);
Expand Down
1 change: 1 addition & 0 deletions crates/cli-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ version = "0.2.100"
anyhow = "1.0"
base64 = "0.22"
log = "0.4"
regex = "1"
rustc-demangle = "0.1.13"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Loading
Loading