Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
e9bf8a0
first pass at a hack
walkingeyerobot Dec 23, 2024
135405f
oops
walkingeyerobot Dec 23, 2024
e5b67a7
wasm bindgen setting
walkingeyerobot Dec 23, 2024
6732eec
link in actual js output by wasm-bindgen
walkingeyerobot Jan 13, 2025
1708fdf
don't try to predict the wasm filename
walkingeyerobot Jan 29, 2025
5f3feae
address code review comments
walkingeyerobot Jan 29, 2025
8ff4580
switch to single file js for bindgen
walkingeyerobot Feb 13, 2025
44d0f55
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Feb 20, 2025
836fbe6
minor cleanup
walkingeyerobot Feb 21, 2025
2debab9
first test
walkingeyerobot Feb 24, 2025
ea4eab0
only avoid stripping if wasm bindgen is enabled
walkingeyerobot Mar 11, 2025
d7faa6b
remove irrelevant comment; going to solve this a different way
walkingeyerobot Mar 11, 2025
cb281cb
Make HEAP_DATA_VIEW available for wasm-bindgen regardless of endianness
google-yfyang Mar 12, 2025
2843e36
Automatically infer what symbols to export for wasm-bindgen
googlewalt Mar 13, 2025
26cd774
Remove hack not to export system libraries
googlewalt Mar 13, 2025
cfc9b11
Merge pull request #1 from googlewalt/linkargs
walkingeyerobot Mar 13, 2025
c2dfc91
wasm bindgen now uses the 'env' property instead of its own 'wbg'
walkingeyerobot Mar 17, 2025
4196290
with newer rustc, there appears to be a bunch of anon symbols that we…
walkingeyerobot Mar 24, 2025
8c08d8e
pass --keep-debug to wasm-bindgen always.
walkingeyerobot Apr 28, 2025
50e8795
Merge branch 'branch-405' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
09992ae
Merge branch 'branch-406' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
126f551
Merge branch 'branch-407' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
c779002
Merge branch 'branch-408' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
8e5fd0a
Merge branch 'branch-409' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
feaf9be
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
50b600f
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot May 21, 2025
50c4fe1
Get typescript with wasm-bindgen to work
google-yfyang Jun 4, 2025
24be666
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Jun 12, 2025
fe3db01
don't do big endian stuff with bindgen stuff unless explicitly asked to
walkingeyerobot Jun 24, 2025
6d1c5ff
make typescript work with emscripten (part2)
google-yfyang Jun 25, 2025
9c92122
Merge pull request #2 from walkingeyerobot/yfyang
walkingeyerobot Jun 25, 2025
3be75f2
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Aug 18, 2025
4e8aab6
Merge branch 'wbg-walkingeyerobot' of github.com:walkingeyerobot/emsc…
walkingeyerobot Aug 18, 2025
20839d5
Merge tag '4.0.15' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
95c89b5
Merge tag '4.0.16' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
65fca2a
Merge tag '4.0.17' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
e40e789
Merge tag '4.0.18' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
45c8c8f
Merge tag '4.0.19' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
11855f5
Merge tag '4.0.20' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
24d681b
Merge tag '4.0.21' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
2ef1305
Merge tag '4.0.22' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
dfd65cf
Merge tag '4.0.23' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
fe99e55
Merge tag '5.0.0' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
1c74e70
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Jan 26, 2026
79a4af7
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Feb 17, 2026
9627ee3
add missing import glob
walkingeyerobot Feb 18, 2026
cba2609
Merge tag '5.0.2' into wbg-walkingeyerobot
walkingeyerobot Apr 2, 2026
d56b37f
Merge tag '5.0.3' into wbg-walkingeyerobot
walkingeyerobot Apr 2, 2026
64f0dad
Merge tag '5.0.4' into wbg-walkingeyerobot
walkingeyerobot Apr 2, 2026
e146085
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Apr 2, 2026
44d3059
remove unneeded --target flag
walkingeyerobot Apr 2, 2026
1b72851
update docs
walkingeyerobot Apr 2, 2026
afebddc
fix python warnings
walkingeyerobot Apr 2, 2026
80d0b67
python lint fix
walkingeyerobot Apr 2, 2026
3cd3b31
more python lint fixes
walkingeyerobot Apr 2, 2026
68eb9b2
use wasm-bindgen for testing properly
walkingeyerobot Apr 17, 2026
2b1c672
Merge tag '5.0.6' into wbg-walkingeyerobot
walkingeyerobot Apr 17, 2026
d229aaf
Merge remote-tracking branch 'upstream/main' into wbg-walkingeyerobot
walkingeyerobot Apr 17, 2026
e55a8a1
fix the test once and for all
walkingeyerobot Apr 18, 2026
bc3a3f0
...once and for all
walkingeyerobot Apr 18, 2026
bf9d095
ONCE AND FOR ALL
walkingeyerobot Apr 18, 2026
6029dd7
ok maybe I'm a little lost
walkingeyerobot Apr 18, 2026
c082ea1
my hopes have never been higher, and yet...
walkingeyerobot Apr 18, 2026
78b0a55
this one for sure
walkingeyerobot Apr 18, 2026
1925b05
I should probably go to bed
walkingeyerobot Apr 18, 2026
b009b61
don't require rust
walkingeyerobot Apr 18, 2026
2b591ee
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 18, 2026
4b27565
this appears to work now
walkingeyerobot Apr 19, 2026
a739374
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 19, 2026
5cc0091
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 20, 2026
094743a
prevent export renaming for wasm-bindgen test
walkingeyerobot Apr 22, 2026
ebd53fe
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 22, 2026
076abcb
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 24, 2026
dc705f4
fix an error where strings were being appended instead of LinkFlag ob…
walkingeyerobot Apr 24, 2026
06cf81a
python lint fixes
walkingeyerobot Apr 24, 2026
f19ae01
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 24, 2026
b804a48
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 27, 2026
298d746
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot Apr 29, 2026
7898c9d
fix bad merge on my part
walkingeyerobot Apr 29, 2026
389f901
how did this not fail earlier
walkingeyerobot Apr 29, 2026
aa7bcc2
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 5, 2026
3f38afd
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 5, 2026
2ae5656
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 9, 2026
067c6c8
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 12, 2026
4661535
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 13, 2026
13b5ce7
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 14, 2026
aa92019
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 15, 2026
d96723a
remove the WASM_BINDGEN config var
walkingeyerobot May 22, 2026
e9488b9
revert unrelated change
walkingeyerobot May 22, 2026
311eba5
code review fixes
walkingeyerobot May 22, 2026
a8aac50
revert the need for HEAP_DATA_VIEW
walkingeyerobot May 27, 2026
c279e12
code review fixes
walkingeyerobot May 27, 2026
6c64bc7
Merge branch 'main' into wbg-walkingeyerobot
walkingeyerobot May 27, 2026
d93502c
ruff fix
walkingeyerobot May 27, 2026
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
1 change: 1 addition & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ function getWasmImports() {
#else // MINIFY_WASM_IMPORTED_MODULES
'env': wasmImports,
'{{{ WASI_MODULE_NAME }}}': wasmImports,
'wbg': wasmImports,
#endif // MINIFY_WASM_IMPORTED_MODULES
#if SPLIT_MODULE
'placeholder': new Proxy({}, splitModuleProxyHandler),
Expand Down
4 changes: 4 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,10 @@ var LEGACY_RUNTIME = false;
// [link]
var SIGNATURE_CONVERSIONS = [];

// Run wasm-bindgen and integrate the rust-exported symbols into the rest of Emscripten's JS output.
// [link]
var WASM_BINDGEN = 0;

// For renamed settings the format is:
// [OLD_NAME, NEW_NAME]
// For removed settings (which now effectively have a fixed value and can no
Expand Down
21 changes: 21 additions & 0 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,27 @@ def run_wasm_opt(infile, outfile=None, args=[], **kwargs): # noqa
return run_binaryen_command('wasm-opt', infile, outfile, args=args, **kwargs)


def run_wasm_bindgen(infile, outfile=None, args=[], **kwargs): # noqa
if not os.path.exists(infile):
exit_with_error('wasm-bindgen: wasm file not found (%s).' % infile)
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated

cmd = config.WASM_BINDGEN + [
infile,
'--target',
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated
'emscripten',
'--keep-lld-exports',
'--out-dir',
get_emscripten_temp_dir() + '/wbg_out'
]
ret = check_call(cmd).stdout
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated
new_wasm_file = get_emscripten_temp_dir() + '/wbg_out/' + os.path.basename(infile).split('.')[0] + '.wasm'
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated
if outfile == None:
outfile = infile
check_call(['cp', new_wasm_file, infile])
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated

return ret


def save_intermediate(src, dst):
if DEBUG:
dst = 'emcc-%02d-%s' % (save_intermediate.counter, dst)
Expand Down
4 changes: 4 additions & 0 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CACHE = None
PORTS = None
COMPILER_WRAPPER = None
WASM_BINDGEN = None

# Set by init()
EM_CONFIG = None
Expand All @@ -58,6 +59,7 @@ def fix_js_engine(old, new):
def normalize_config_settings():
global CACHE, PORTS, LLVM_ADD_VERSION, CLANG_ADD_VERSION, CLOSURE_COMPILER
global NODE_JS, NODE_JS_TEST, V8_ENGINE, JS_ENGINES, SPIDERMONKEY_ENGINE, WASM_ENGINES
global WASM_BINDGEN

# EM_CONFIG stuff
if not JS_ENGINES:
Expand All @@ -75,6 +77,7 @@ def normalize_config_settings():
JS_ENGINES = [listify(engine) for engine in JS_ENGINES]
WASM_ENGINES = [listify(engine) for engine in WASM_ENGINES]
CLOSURE_COMPILER = listify(CLOSURE_COMPILER)
WASM_BINDGEN = listify(WASM_BINDGEN)
if not CACHE:
CACHE = path_from_root('cache')
if not PORTS:
Expand Down Expand Up @@ -124,6 +127,7 @@ def parse_config_file():
'CACHE',
'PORTS',
'COMPILER_WRAPPER',
'WASM_BINDGEN',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid the new config setting completely and just rely on wasm-bindgen being in the PATH when a user added -sWASM_BINDGEN.

This is what we do for tsc I believe. I'm loath to add more config setting if we can possibly avoid it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

)

# Only propagate certain settings from the config file.
Expand Down
10 changes: 6 additions & 4 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,11 @@ def finalize_wasm(infile, outfile, js_syms):
if not need_name_section:
strip_sections += ['name']

if strip_sections or not settings.GENERATE_DWARF:
building.save_intermediate(outfile, 'strip.wasm')
building.strip(infile, outfile, debug=not settings.GENERATE_DWARF,
sections=strip_sections)
# TODO(walkingeyerobot): make this work. it appears to not like the wasm file from wasm-bindgen
#if strip_sections or not settings.GENERATE_DWARF:
# building.save_intermediate(outfile, 'strip.wasm')
# building.strip(infile, outfile, debug=not settings.GENERATE_DWARF,
# sections=strip_sections)

metadata = get_metadata(outfile, outfile, modify_wasm, args)

Expand Down Expand Up @@ -951,6 +952,7 @@ def install_wrapper(sym):
else:
wrapper += f"wasmExports['{name}']"

# TODO(walkingeyerobot): if the export is from rust, it should probably be excluded here and dealt with elsewhere.
wrappers.append(wrapper)
return wrappers

Expand Down
10 changes: 10 additions & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .shared import in_temp, safe_copy, do_replace, OFormat
from .shared import DEBUG, WINDOWS, DYNAMICLIB_ENDINGS, STATICLIB_ENDINGS
from .shared import unsuffixed, unsuffixed_basename, get_file_suffix
from .shared import get_emscripten_temp_dir
from .settings import settings, default_setting, user_settings, JS_ONLY_SETTINGS, DEPRECATED_SETTINGS
from .minimal_runtime_shell import generate_minimal_runtime_html

Expand Down Expand Up @@ -1932,6 +1933,11 @@ def phase_post_link(options, state, in_wasm, wasm_target, target, js_syms, base_

settings.TARGET_JS_NAME = os.path.basename(state.js_target)

if settings.WASM_BINDGEN:
phase_wasm_bindgen(in_wasm)
settings.PRE_JS_FILES += [os.path.abspath(get_emscripten_temp_dir() + '/wbg_out/wbg_pre.js')]
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated
settings.JS_LIBRARIES += [os.path.abspath(get_emscripten_temp_dir() + '/wbg_out/library_wbg.js')]

metadata = phase_emscript(in_wasm, wasm_target, js_syms, base_metadata)

if settings.EMBIND_AOT:
Expand All @@ -1950,6 +1956,10 @@ def phase_post_link(options, state, in_wasm, wasm_target, target, js_syms, base_
phase_final_emitting(options, state, target, wasm_target)


def phase_wasm_bindgen(in_wasm, wasm_target=None):
building.run_wasm_bindgen(in_wasm, wasm_target)
Comment thread
walkingeyerobot marked this conversation as resolved.
Outdated


@ToolchainProfiler.profile_block('emscript')
def phase_emscript(in_wasm, wasm_target, js_syms, base_metadata):
# Emscripten
Expand Down