Skip to content

Commit b338824

Browse files
Merge pull request #5 from walkingeyerobot/yfyang
Expand emscripten support to supporting JS imported closures.
2 parents ca2bc14 + c3a0e58 commit b338824

File tree

4 files changed

+214
-83
lines changed

4 files changed

+214
-83
lines changed

.cargo/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
[target.'cfg(target_arch = "wasm32")']
22
runner = 'cargo run -p wasm-bindgen-cli --bin wasm-bindgen-test-runner --'
3+
4+
[build]
5+
[target.'cfg(all(target_arch = "wasm32", target_os = "emscripten"))']
6+
rustflags = [
7+
"-Cllvm-args=-enable-emscripten-cxx-exceptions=0",
8+
"-Clink-arg=-Wno-undefined",
9+
"-Crelocation-model=static",
10+
]

crates/cli-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
tempfile = "3.0"
2424
walrus = { version = "0.23", features = ['parallel'] }
25+
regex = "1"
2526
wasm-bindgen-externref-xform = { path = '../externref-xform', version = '=0.2.100' }
2627
wasm-bindgen-multi-value-xform = { path = '../multi-value-xform', version = '=0.2.100' }
2728
wasm-bindgen-shared = { path = "../shared", version = '=0.2.100' }

crates/cli-support/src/js/binding.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl<'a, 'b> Builder<'a, 'b> {
130130
debug_name: &str,
131131
ret_ty_override: &Option<String>,
132132
ret_desc: &Option<String>,
133+
import_deps: &mut Vec<String>,
133134
) -> Result<JsFunction, Error> {
134135
if self
135136
.cx
@@ -194,6 +195,7 @@ impl<'a, 'b> Builder<'a, 'b> {
194195
&instr.instr,
195196
&mut self.log_error,
196197
&self.constructor,
198+
import_deps,
197199
)?;
198200
}
199201

@@ -727,6 +729,7 @@ fn instruction(
727729
instr: &Instruction,
728730
log_error: &mut bool,
729731
constructor: &Option<String>,
732+
import_deps: &mut Vec<String>,
730733
) -> Result<(), Error> {
731734
fn wasm_to_string_enum(name: &str, index: &str) -> String {
732735
// e.g. ["a","b","c"][someIndex]
@@ -807,7 +810,7 @@ fn instruction(
807810
}
808811

809812
// Call the function through an export of the underlying module.
810-
let call = invoc.invoke(js.cx, &args, &mut js.prelude, log_error)?;
813+
let call = invoc.invoke(js.cx, &args, &mut js.prelude, log_error, import_deps)?;
811814

812815
// And then figure out how to actually handle where the call
813816
// happens. This is pretty conditional depending on the number of
@@ -1637,6 +1640,7 @@ impl Invocation {
16371640
args: &[String],
16381641
prelude: &mut String,
16391642
log_error: &mut bool,
1643+
import_deps: &mut Vec<String>,
16401644
) -> Result<String, Error> {
16411645
match self {
16421646
Invocation::Core { id, .. } => {
@@ -1656,7 +1660,8 @@ impl Invocation {
16561660
if cx.import_never_log_error(import) {
16571661
*log_error = false;
16581662
}
1659-
cx.invoke_import(import, kind, args, variadic, prelude)
1663+
let ret = cx.invoke_import(import, kind, args, variadic, prelude, import_deps);
1664+
return ret
16601665
}
16611666
}
16621667
}

0 commit comments

Comments
 (0)