Skip to content

Commit d489b58

Browse files
committed
Merge remote-tracking branch 'origin/main' into issue-20983
2 parents 6925d65 + 00c5c7d commit d489b58

File tree

6 files changed

+92
-35
lines changed

6 files changed

+92
-35
lines changed

.circleci/ccache.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
debug = true
2+
debug_level = 1

.circleci/config.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ commands:
209209
- run:
210210
name: "Ccache stats and configuration"
211211
command: |
212-
ls ~/cache/sysroot/lib/wasm32-emscripten || echo "no build"
212+
ls -l ~/cache/sysroot/lib/wasm32-emscripten || echo "no build"
213+
ls -l ~/cache/sysroot/include/emscripten/heap.h
213214
cat ~/cache/sysroot/lib/wasm32-emscripten/crtbegin.o.ccache-log
214215
date
216+
cat ~/cache/build/libcompiler_rt/absvdi2.o.ccache-log
215217
ccache -s
216218
ccache --print-stats
217219
ccache -p
@@ -574,8 +576,6 @@ jobs:
574576
EMCC_CORES: 16
575577
EMCC_USE_NINJA: 1
576578
EM_COMPILER_WRAPPER: "ccache"
577-
CCACHE_DEBUG: 1
578-
CCACHE_DEBUGLEVEL: 1
579579
steps:
580580
- checkout
581581
- run:
@@ -611,6 +611,12 @@ jobs:
611611
- restore_cache:
612612
name: "Restore Ccache cache"
613613
key: clang-{{ checksum "~/emsdk/clang_version.txt" }}
614+
- run:
615+
name: Configure ccache
616+
command: |
617+
mkdir -p ~/.ccache
618+
cat .circleci/ccache.conf
619+
cp .circleci/ccache.conf ~/.ccache
614620
- build-libs
615621
- run:
616622
name: Clean build directory
@@ -820,7 +826,31 @@ jobs:
820826
command: echo "NODE_JS = NODE_JS_TEST" >> ~/emsdk/.emscripten
821827
- run-tests:
822828
title: "wasm64_4gb"
823-
test_targets: "wasm64_4gb
829+
test_targets: "wasm64_4gb"
830+
- upload-test-results
831+
test-wasm64-misc:
832+
environment:
833+
LANG: "C.UTF-8"
834+
# We don't use `bionic` here since its too old to run recent node versions:
835+
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
836+
executor: linux-python
837+
steps:
838+
- prepare-for-tests
839+
# The linux-python image uses /home/circleci rather than /root and jsvu
840+
# hardcodes /root into its launcher scripts so we need to reinstall v8.
841+
- run: rm -rf $HOME/.jsvu
842+
- install-v8
843+
- install-node-canary
844+
# When running wasm64 tests we need to make sure we use the testing
845+
# version of node (node canary) when running the compiler output (e.g.
846+
# in configure tests.
847+
- run:
848+
name: configure node canary
849+
command: echo "NODE_JS = NODE_JS_TEST" >> ~/emsdk/.emscripten
850+
- run-tests:
851+
title: "wasm64"
852+
test_targets: "
853+
other.*_wasm64
824854
core_2gb.test_*em_asm*
825855
core_2gb.test_*embind*
826856
core_2gb.test_fs_js_api_wasmfs
@@ -829,8 +859,7 @@ jobs:
829859
wasm64l.test_bigswitch
830860
wasm64l.test_module_wasm_memory
831861
wasm64l.test_longjmp2_emscripten
832-
wasm64l.test_embind_val_basics_legacy
833-
other.*_wasm64"
862+
wasm64l.test_embind_val_basics_legacy"
834863
- upload-test-results
835864
test-jsc:
836865
executor: linux-python
@@ -1280,6 +1309,9 @@ workflows:
12801309
- test-core3:
12811310
requires:
12821311
- build-linux
1312+
- test-wasm64-misc:
1313+
requires:
1314+
- build-linux
12831315
- test-wasm64-4gb:
12841316
requires:
12851317
- build-linux

emcc.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
import tarfile
3232
from dataclasses import dataclass
3333
from enum import Enum, auto, unique
34-
from subprocess import PIPE
3534

3635

3736
from tools import shared, system_libs, utils, cmdline
3837
from tools import diagnostics, building, compile
3938
from tools.shared import unsuffixed_basename, get_file_suffix
40-
from tools.shared import run_process, exit_with_error, DEBUG
39+
from tools.shared import exit_with_error, DEBUG
4140
from tools.shared import in_temp
4241
from tools.shared import DYLIB_EXTENSIONS
4342
from tools.cmdline import CLANG_FLAGS_WITH_ARGS
@@ -242,27 +241,6 @@ def run(args):
242241
print(utils.EMSCRIPTEN_VERSION)
243242
return 0
244243

245-
if '--cflags' in args:
246-
# fake running the command, to see the full args we pass to clang
247-
args = [x for x in args if x != '--cflags']
248-
with shared.get_temp_files().get_file(suffix='.o') as temp_target:
249-
input_file = 'hello_world.c'
250-
compiler = shared.EMCC
251-
if shared.run_via_emxx:
252-
compiler = shared.EMXX
253-
cmd = [compiler, utils.path_from_root('test', input_file), '-v', '-c', '-o', temp_target] + args
254-
proc = run_process(cmd, stderr=PIPE, check=False)
255-
if proc.returncode != 0:
256-
print(proc.stderr)
257-
exit_with_error('error getting cflags')
258-
lines = [x for x in proc.stderr.splitlines() if clang in x and input_file in x]
259-
if not lines:
260-
exit_with_error(f'unable to parse output of `{cmd}`:\n{proc.stderr}')
261-
parts = shlex.split(lines[0].replace('\\', '\\\\'))
262-
parts = [x for x in parts if x not in ['-c', '-o', '-v', '-emit-llvm'] and input_file not in x and temp_target not in x]
263-
print(shlex.join(parts[1:]))
264-
return 0
265-
266244
if '-dumpmachine' in args or '-print-target-triple' in args or '--print-target-triple' in args:
267245
print(shared.get_llvm_target())
268246
return 0
@@ -314,6 +292,13 @@ def run(args):
314292

315293
phase_setup(options, state)
316294

295+
if '--cflags' in args:
296+
# Just print the flags we pass to clang and exit. We need to do this after
297+
# phase_setup because the setup sets things like SUPPORT_LONGJMP.
298+
cflags = compile.get_cflags(x for x in args if x != '--cflags')
299+
print(shlex.join(cflags))
300+
return 0
301+
317302
if options.reproduce:
318303
create_reproduce_file(options.reproduce, args)
319304

src/modules.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ function exportSymbol(name) {
433433
function exportRuntimeSymbols() {
434434
// optionally export something.
435435
function shouldExport(name) {
436+
// Native exports are not available to be exported initially. Instead,
437+
// they get exported later in `assignWasmExports`.
438+
if (nativeAliases[name]) {
439+
return false;
440+
}
436441
// If requested to be exported, export it.
437442
if (EXPORTED_RUNTIME_METHODS.has(name)) {
438443
// Unless we are in MODULARIZE=instance mode then HEAP objects are

test/test_other.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,20 @@ def test_js_transform(self):
689689
self.assertIn('transformed!', read_file('a.out.js'))
690690

691691
@crossplatform
692+
@also_with_wasm64
692693
def test_emcc_cflags(self):
693-
output = self.run_process([EMCC, '--cflags'], stdout=PIPE)
694+
output = self.run_process([EMCC, '--cflags'] + self.get_cflags(), stdout=PIPE)
694695
flags = output.stdout.strip()
695-
self.assertContained('-target wasm32-unknown-emscripten', flags)
696+
self.assertContained(r'-target wasm\d\d-unknown-emscripten', flags, regex=True)
696697
self.assertContained('--sysroot=', flags)
697-
output = self.run_process([EMXX, '--cflags'], stdout=PIPE)
698+
output = self.run_process([EMXX, '--cflags'] + self.get_cflags(), stdout=PIPE)
698699
flags = output.stdout.strip()
699-
self.assertContained('-target wasm32-unknown-emscripten', flags)
700+
self.assertContained(r'-target wasm\d\d-unknown-emscripten', flags, regex=True)
700701
self.assertContained('--sysroot=', flags)
701702
# check they work
702703
cmd = [CLANG_CC, test_file('hello_world.c')] + shlex.split(flags.replace('\\', '\\\\')) + ['-c', '-o', 'out.o']
703704
self.run_process(cmd)
704-
self.run_process([EMCC, 'out.o'])
705+
self.run_process([EMCC, 'out.o'] + self.get_cflags())
705706
self.assertContained('hello, world!', self.run_js('a.out.js'))
706707

707708
@crossplatform
@@ -4947,6 +4948,35 @@ def test_jslib_aliases(self, args):
49474948
'''
49484949
self.do_runf('main.c', expected, cflags=['--js-library', 'foo.js'] + args)
49494950

4951+
@parameterized({
4952+
'': ([],),
4953+
'closure': (['--closure=1'],),
4954+
})
4955+
def test_jslib_export_alias(self, args):
4956+
create_file('lib.js', '''
4957+
addToLibrary({
4958+
$foo: 'main',
4959+
$bar: '__indirect_function_table',
4960+
$baz: 'memory',
4961+
});
4962+
''')
4963+
create_file('extern_pre.js', r'''
4964+
Module = {
4965+
onRuntimeInitialized: () => {
4966+
const assert = require('assert');
4967+
console.log("onRuntimeInitialized");
4968+
console.log('foo:', typeof Module.foo)
4969+
console.log('bar:', typeof Module.bar)
4970+
console.log('baz:', typeof Module.baz)
4971+
assert(Module.foo instanceof Function);
4972+
assert(Module.bar instanceof WebAssembly.Table);
4973+
assert(Module.baz instanceof WebAssembly.Memory);
4974+
console.log('done');
4975+
}
4976+
};
4977+
''')
4978+
self.do_runf('hello_world.c', 'done\n', cflags=['--js-library=lib.js', '--extern-pre-js=extern_pre.js', '-sEXPORTED_RUNTIME_METHODS=foo,bar,baz'] + args)
4979+
49504980
def test_postjs_errors(self):
49514981
create_file('post.js', '#preprocess\n#error This is an error')
49524982
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--post-js', 'post.js'])

tools/emscripten.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ def create_receiving(function_exports, other_exports, library_symbols, aliases):
980980
assert alias in exports, f'expected alias target ({alias}) to be exported'
981981
alias_inverse_map.setdefault(alias, []).append(sym)
982982

983+
do_module_exports = (settings.MODULARIZE or not settings.MINIMAL_RUNTIME) and settings.MODULARIZE != 'instance'
983984
receiving.append('\nfunction assignWasmExports(wasmExports) {')
984985
for sym, sig in exports.items():
985986
is_function = sig is not None
@@ -988,11 +989,13 @@ def create_receiving(function_exports, other_exports, library_symbols, aliases):
988989
if generate_dyncall_assignment and is_function and sym.startswith('dynCall_'):
989990
sig_str = sym.replace('dynCall_', '')
990991
assignment += f" = dynCalls['{sig_str}']"
991-
if (settings.MODULARIZE or not settings.MINIMAL_RUNTIME) and should_export(mangled) and settings.MODULARIZE != 'instance':
992+
if do_module_exports and should_export(mangled):
992993
assignment += f" = Module['{mangled}']"
993994
if sym in alias_inverse_map:
994995
for target in alias_inverse_map[sym]:
995996
assignment += f" = {target}"
997+
if do_module_exports and target in settings.EXPORTED_RUNTIME_METHODS:
998+
assignment += f" = Module['{target}']"
996999
if is_function and install_debug_wrapper(sym):
9971000
nargs = len(sig.params)
9981001
receiving.append(f" {assignment} = createExportWrapper('{sym}', {nargs});")

0 commit comments

Comments
 (0)