Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 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
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
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ commands:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH=${HOME}/.cargo/bin:${PATH}
rustup target add wasm32-unknown-emscripten
cargo install wasm-bindgen-cli
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> $BASH_ENV
install-node-version:
description: "install a specific version of node"
Expand Down Expand Up @@ -159,6 +160,7 @@ commands:
# We use an out-of-tree cache directory so it can be part of the
# persisted workspace (see below).
echo "CACHE = os.path.expanduser('~/cache')" >> .emscripten
echo "WASM_BINDGEN = os.path.expanduser('~/.cargo/bin/wasm-bindgen')" >> .emscripten
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.

Can we just add ~/.cargo/bin to the PATH instead? (see commend in config.py)

# Refer to commit 0bc3640 if we need to pin V8 version.
echo "V8_ENGINE = [os.path.expanduser('~/.jsvu/bin/v8')]" >> .emscripten
echo "JS_ENGINES = [NODE_JS]" >> .emscripten
Expand Down
19 changes: 2 additions & 17 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import shutil
import sys
import tarfile
from dataclasses import dataclass
from enum import Enum, auto, unique

# This assert needs to happen early, before any too-recent python syntax is used.
Expand All @@ -51,7 +50,7 @@
from tools.settings import COMPILE_TIME_SETTINGS, default_setting, settings, user_settings
from tools.shared import DEBUG, DYLIB_EXTENSIONS, in_temp
from tools.toolchain_profiler import ToolchainProfiler
from tools.utils import exit_with_error, get_file_suffix, read_file, unsuffixed_basename
from tools.utils import LinkFlag, exit_with_error, get_file_suffix, read_file, unsuffixed_basename

logger = logging.getLogger('emcc')

Expand Down Expand Up @@ -96,20 +95,6 @@ class Mode(Enum):
COMPILE_AND_LINK = auto()


@dataclass
class LinkFlag:
"""Used to represent a linker flag.

The flag value is stored along with a bool that distinguishes input
files from non-files.

A list of these is returned by separate_linker_flags.
"""

value: str
is_file: int


class EmccState:
def __init__(self, args):
self.mode = Mode.COMPILE_AND_LINK
Expand Down Expand Up @@ -578,7 +563,7 @@ def compile_source_file(input_file):
# Default to assuming the inputs are object files and pass them to the linker
pass

return [f.value for f in linker_args]
return linker_args


if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,15 @@ Example use ``-sSIGNATURE_CONVERSIONS=someFunction:_p,anotherFunction:p``

Default value: []

.. _wasm_bindgen:

WASM_BINDGEN
============

Run wasm-bindgen and integrate the rust-exported symbols into the rest of Emscripten's JS output.

Default value: 0

.. _source_phase_imports:

SOURCE_PHASE_IMPORTS
Expand Down
6 changes: 4 additions & 2 deletions src/runtime_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if (ENVIRONMENT_IS_NODE && {{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {

// Memory management

#if SUPPORT_BIG_ENDIAN
#if SUPPORT_BIG_ENDIAN || WASM_BINDGEN
/** @type {!DataView} */
var HEAP_DATA_VIEW;
#endif
Expand Down Expand Up @@ -130,8 +130,10 @@ function updateMemoryViews() {
{{{ maybeExportHeap('HEAP64') }}}HEAP64 = new BigInt64Array(b);
{{{ maybeExportHeap('HEAPU64') }}}HEAPU64 = new BigUint64Array(b);
#endif
#if SUPPORT_BIG_ENDIAN || WASM_BINDGEN
{{{ maybeExportHeap('HEAP_DATA_VIEW') }}}HEAP_DATA_VIEW = new DataView(b);
#endif
#if SUPPORT_BIG_ENDIAN
{{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b);
LE_HEAP_UPDATE();
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,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;

// Experimental support for wasm source phase imports.
// This is only currently implemented in the pre-release/nightly version of
// node, and not yet supported by browsers.
Expand Down
3 changes: 1 addition & 2 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,7 @@ def ccshared(src, linkto=None):
cfunc_ptr();
return 0;
}
''' % locals(),
'a: loaded\na: b (prev: (null))\na: c (prev: b)\n', cflags=extra_args)
''', 'a: loaded\na: b (prev: (null))\na: c (prev: b)\n', cflags=extra_args)

def do_run(self, src, expected_output=None, force_c=False, **kwargs):
if 'no_build' in kwargs:
Expand Down
2 changes: 2 additions & 0 deletions test/rust/basics/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-unknown-emscripten"
7 changes: 7 additions & 0 deletions test/rust/bindgen_integration/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
target = "wasm32-unknown-emscripten"
rustflags = [
"-Cllvm-args=-enable-emscripten-cxx-exceptions=0",
"-Cpanic=abort",
"-Crelocation-model=static",
]
8 changes: 8 additions & 0 deletions test/rust/bindgen_integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "bindgen_integration"
edition = "2021"

[lib]
crate-type = ["staticlib"]

[dependencies]
6 changes: 6 additions & 0 deletions test/rust/bindgen_integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn rs_add(a: i32, b: i32) -> i32 {
return a + b;
}
27 changes: 26 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -14845,7 +14845,7 @@ def test_embool(self):
@requires_rust
def test_rust_integration_basics(self):
copytree(test_file('rust/basics'), '.')
self.run_process(['cargo', 'build', '--target=wasm32-unknown-emscripten'])
self.run_process(['cargo', 'build'])
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.

Why isn't --target needed here anymore? .. Oh I see its in the cargo.toml file now.

Maybe just revert these changes to test_rust_integration_basics ? Since they seem unrelated?

lib = 'target/wasm32-unknown-emscripten/debug/libbasics.a'
self.assertExists(lib)

Expand All @@ -14857,6 +14857,31 @@ def test_rust_integration_basics(self):
}''')
self.do_runf('main.cpp', 'Hello from rust!', cflags=[lib])

@requires_rust
def test_wasm_bindgen_integration(self):
copytree(test_file('rust/bindgen_integration'), '.')
self.run_process(['cargo', 'add', 'wasm-bindgen'])
self.run_process(['cargo', 'build'])
lib = 'target/wasm32-unknown-emscripten/debug/libbindgen_integration.a'
self.assertExists(lib)
self.assertExists(os.path.abspath(config.WASM_BINDGEN[0]))

create_file('main.cpp', '')
create_file('post.js', '''
Module.onRuntimeInitialized = () => {
out(Module.rs_add(17, 25));
};
''')
emcc_args = [
lib,
'-sWASM_BINDGEN',
'--post-js',
'post.js',
'-lexports.js',
]

self.do_runf('main.cpp', '42', cflags=emcc_args)

def test_relative_em_cache(self):
with env_modify({'EM_CACHE': 'foo'}):
self.assert_fail([EMCC, '-c', test_file('hello_world.c')], 'emcc: error: environment variable EM_CACHE must be an absolute path: foo')
Expand Down
59 changes: 56 additions & 3 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,43 @@ def lld_flags_for_executable(external_symbols):
return cmd


def lld_flags(args):
def get_wasm_bindgen_exported_symbols(input_files):
if not os.path.exists(LLVM_NM):
exit_with_error('llvm-nm not found in LLVM directory: %s', LLVM_NM)
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.

I would just remove these two lines.

We don't have these checks elsewhere. See emar.py for example.


nm_args = [
LLVM_NM,
'--defined-only',
'--extern-only',
'--format=just-symbols',
'--print-file-name',
'--quiet',
]
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.

We allow lines up to 100 chars in our python code.. maybe just put this on a singe line?

if input_files is not None:
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.

Can input_files actaully ever be null? I would expect the emtpy list if now inputs are given.

nm_args += input_files

result = run_process(nm_args, stdout=subprocess.PIPE)
symbols = []
for line in result.stdout.splitlines():
(path, symbol) = line.split()
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.

No braces on the LHS here.

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.

Does this work if there are spaces in the filenames?

# Skip mangled (non-C) symbols
if symbol.startswith(('_Z', '_R', 'anon.')):
continue
symbols.append(symbol)

return symbols


def lld_flags(args, linker_inputs=None):
# lld doesn't currently support --start-group/--end-group since the
# semantics are more like the windows linker where there is no need for
# grouping.
args = [a for a in args if a not in {'--start-group', '--end-group'}]

if settings.WASM_BINDGEN:
exported_symbols = get_wasm_bindgen_exported_symbols(linker_inputs)
args.extend(f'--export-if-defined={e}' for e in exported_symbols)

# Emscripten currently expects linkable output (SIDE_MODULE/MAIN_MODULE) to
# include all archive contents.
if settings.LINKABLE:
Expand Down Expand Up @@ -312,7 +343,7 @@ def lld_flags(args):
return args


def link_lld(args, target, external_symbols=None):
def link_lld(args, target, external_symbols=None, linker_inputs=None):
# runs lld to link things.
if not os.path.exists(WASM_LD):
exit_with_error('linker binary not found in LLVM directory: %s', WASM_LD)
Expand All @@ -321,7 +352,7 @@ def link_lld(args, target, external_symbols=None):
# normal linker flags that are used when building and executable
if '--relocatable' not in args and '-r' not in args:
cmd += lld_flags_for_executable(external_symbols)
cmd += lld_flags(args)
cmd += lld_flags(args, linker_inputs)
cmd = get_command_with_possible_response_file(cmd)
check_call(cmd)

Expand Down Expand Up @@ -1254,6 +1285,28 @@ 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
bindgen_out_dir = get_emscripten_temp_dir() + '/bindgen_out/'

cmd = config.WASM_BINDGEN + [
infile,
'--keep-lld-exports',
'--keep-debug',
'--out-dir',
bindgen_out_dir,
]
check_call(cmd)

# Don't try to predict the .wasm filename that wasm-bindgen outputs. Instead
# just grab the .wasm file itself.
all_output_files = os.listdir(bindgen_out_dir)
new_wasm_file = list(filter(lambda x: x.endswith('.wasm'), all_output_files))[0]
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.

Use list comprehension here. e.g. [x for x in all_output_files if x.endswith('.wasm')]

if outfile is None:
outfile = infile

shutil.copyfile(bindgen_out_dir + new_wasm_file, outfile)


intermediate_counter = 0


Expand Down
4 changes: 4 additions & 0 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
CACHE = None
PORTS = None
COMPILER_WRAPPER = None
WASM_BINDGEN = None

# Set by init()
EM_CONFIG = None
Expand Down Expand Up @@ -60,6 +61,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

SPIDERMONKEY_ENGINE = fix_js_engine(SPIDERMONKEY_ENGINE, listify(SPIDERMONKEY_ENGINE))
NODE_JS = fix_js_engine(NODE_JS, listify(NODE_JS))
Expand All @@ -68,6 +70,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 @@ -131,6 +134,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.

)

# Only propagate certain settings from the config file.
Expand Down
8 changes: 7 additions & 1 deletion tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def create_tsd_exported_runtime_methods(metadata):
return utils.read_file(in_temp(f'{file}.d.ts'))


def create_tsd(metadata, embind_tsd):
def create_tsd(metadata, embind_tsd, bindgen_tsd=None):
out = '// TypeScript bindings for emscripten-generated code. Automatically generated at compile time.\n'
if settings.EXPORTED_RUNTIME_METHODS:
out += create_tsd_exported_runtime_methods(metadata)
Expand Down Expand Up @@ -712,6 +712,12 @@ def create_tsd(metadata, embind_tsd):
# Add in embind definitions.
if embind_tsd:
export_interfaces += ' & EmbindModule'
if settings.WASM_BINDGEN and bindgen_tsd:
for file_path in bindgen_tsd:
with open(file_path, encoding='utf-8') as file:
for line in file:
out += f'{line}'
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.

Can these 3 lines be replaced with just out += read_file(file_path)?

export_interfaces += ' & BindgenModule'
out += f'export type MainModule = {export_interfaces};\n'
if settings.MODULARIZE:
return_type = 'MainModule'
Expand Down
Loading
Loading