Skip to content

Remove WASM2C option #19380

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

Merged
merged 2 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ See docs/process.md for more on how version tagging works.
- The JS `err()` function will now bind to `console.error` by default rather
than `console.warning`. For debugging/tracing/logging we recommend the
`dbg()` function instead. (#19326)
- The `WASM2C` options has been removed. All known users are using upstream wabt
these days anyhow.

3.1.38 - 05/10/23
-----------------
Expand Down
13 changes: 0 additions & 13 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import tools.line_endings
from tools import feature_matrix
from tools import js_manipulation
from tools import wasm2c
from tools import webassembly
from tools import config
from tools import cache
Expand Down Expand Up @@ -1898,15 +1897,6 @@ def phase_linker_setup(options, state, newargs):
settings.STANDALONE_WASM = 1
settings.WASM_BIGINT = 1

if settings.WASM2C:
# wasm2c only makes sense with standalone wasm - there will be no JS,
# just wasm and then C
settings.STANDALONE_WASM = 1
# wasm2c doesn't need any special handling of i64, we have proper i64
# handling on the FFI boundary, which is exactly like the case of JS with
# BigInt support
settings.WASM_BIGINT = 1

if options.no_entry:
settings.EXPECT_MAIN = 0
elif settings.STANDALONE_WASM:
Expand Down Expand Up @@ -3810,9 +3800,6 @@ def preprocess_wasm2js_script():
if settings.DEBUG_LEVEL >= 3 and settings.SEPARATE_DWARF and os.path.exists(wasm_target):
building.emit_debug_on_side(wasm_target)

if settings.WASM2C:
wasm2c.do_wasm2c(wasm_target)

# we have finished emitting the wasm, and so intermediate debug info will
# definitely no longer be used tracking it.
if debug_info:
Expand Down
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"dependencies": {
"acorn": "^8.7.1",
"google-closure-compiler": "20220502.0.0",
"html-minifier-terser": "7.2.0",
"wasm2c": "1.0.0"
"html-minifier-terser": "7.2.0"
},
"scripts": {
"lint": "eslint .",
Expand Down
19 changes: 0 additions & 19 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1933,25 +1933,6 @@ var DEFAULT_TO_CXX = true;
// [link]
var PRINTF_LONG_DOUBLE = false;

// Run wabt's wasm2c tool on the final wasm, and combine that with a C runtime,
// resulting in a .c file that you can compile with a C compiler to get a
// native executable that works the same as the normal js+wasm. This will also
// emit the wasm2c .h file. The output filenames will be X.wasm.c, X.wasm.h
// if your output is X.js or X.wasm (note the added .wasm. we make sure to emit,
// which avoids trampling a C file).
// [link]
// [experimental]
var WASM2C = false;

// Experimental sandboxing mode, see
// https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html
//
// * full: Normal full wasm2c sandboxing. This uses a signal handler if it can.
// * mask: Masks loads and stores.
// * none: No sandboxing at all.
// [experimental]
var WASM2C_SANDBOXING = 'full';

// Setting this affects the path emitted in the wasm that refers to the DWARF
// file, in -gseparate-dwarf mode. This allows the debugging file to be hosted
// in a custom location.
Expand Down
9 changes: 0 additions & 9 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,15 +1383,6 @@ def _build_and_run(self, filename, expected_output, args=None, output_nicerizer=
if not self.wasm_engines:
logger.warning('no wasm engine was found to run the standalone part of this test')
engines += self.wasm_engines
if self.get_setting('WASM2C') and not EMTEST_LACKS_NATIVE_CLANG:
# compile the c file to a native executable.
c = shared.replace_suffix(js_file, '.wasm.c')
executable = shared.replace_suffix(js_file, '.exe')
cmd = [shared.CLANG_CC, c, '-o', executable] + clang_native.get_clang_native_args()
self.run_process(cmd, env=clang_native.get_clang_native_env())
# we can now run the executable directly, without an engine, which
# we indicate with None as the engine
engines += [[None]]
if len(engines) == 0:
self.skipTest('No JS engine present to run this test with. Check %s and the paths therein.' % config.EM_CONFIG)
for engine in engines:
Expand Down
42 changes: 0 additions & 42 deletions test/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,47 +244,6 @@ def get_output_files(self):
return ret


class EmscriptenWasm2CBenchmarker(EmscriptenBenchmarker):
def __init__(self, name):
super().__init__(name, 'no engine needed')

def build(self, parent, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder, has_output_parser):
# wasm2c doesn't want minimal runtime which the normal emscripten
# benchmarker defaults to, as we don't have any JS anyhow
emcc_args = emcc_args + [
'-sSTANDALONE_WASM',
'-sMINIMAL_RUNTIME=0',
'-sWASM2C'
]

global LLVM_FEATURE_FLAGS
old_flags = LLVM_FEATURE_FLAGS
try:
# wasm2c does not support anything beyond MVP
LLVM_FEATURE_FLAGS = []
super().build(parent, filename, args, shared_args, emcc_args, native_args, native_exec, lib_builder, has_output_parser)
finally:
LLVM_FEATURE_FLAGS = old_flags

# move the JS away so there is no chance we run it by mistake
shutil.move(self.filename, self.filename + '.old.js')

c = shared.replace_suffix(self.filenmame, '.wasm.c')
native = shared.replace_suffix(self.filenmame, '.exe')

run_process(['clang', c, '-o', native, OPTIMIZATIONS, '-lm',
'-DWASM_RT_MAX_CALL_STACK_DEPTH=8000']) # for havlak

self.filename = native

def run(self, args):
return run_process([self.filename] + args, stdout=PIPE, stderr=PIPE, check=False).stdout

def get_output_files(self):
# return the native code. c size may also be interesting.
return [self.filename]


CHEERP_BIN = '/opt/cheerp/bin/'


Expand Down Expand Up @@ -375,7 +334,6 @@ def get_output_files(self):
EmscriptenBenchmarker(default_v8_name, aot_v8),
EmscriptenBenchmarker(default_v8_name + '-lto', aot_v8, ['-flto']),
EmscriptenBenchmarker(default_v8_name + '-ctors', aot_v8, ['-sEVAL_CTORS']),
# EmscriptenWasm2CBenchmarker('wasm2c')
]
if os.path.exists(CHEERP_BIN):
benchmarkers += [
Expand Down
42 changes: 5 additions & 37 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ def metafunc(self, rawfs):
return metafunc


def can_do_wasm2c(self):
# the npm version of wasm2c does not support MEMORY64
return not self.get_setting('MEMORY64')


def can_do_standalone(self, impure=False):
# Pure standalone engines don't support MEMORY64 yet. Even with MEMORY64=2 (lowered)
# the WASI APIs that take pointer values don't have 64-bit variants yet.
Expand Down Expand Up @@ -202,7 +197,7 @@ def decorated(self):

# Impure means a test that cannot run in a wasm VM yet, as it is not 100%
# standalone. We can still run them with the JS code though.
def also_with_standalone_wasm(wasm2c=False, impure=False):
def also_with_standalone_wasm(impure=False):
def decorated(func):
def metafunc(self, standalone):
if not standalone:
Expand All @@ -221,11 +216,6 @@ def metafunc(self, standalone):
self.wasm_engines = []
self.node_args += shared.node_bigint_flags()
func(self)
if wasm2c and can_do_wasm2c(self):
print('wasm2c')
self.set_setting('WASM2C')
self.wasm_engines = []
func(self)

metafunc._parameterize = {'': (False,),
'standalone': (True,)}
Expand Down Expand Up @@ -610,7 +600,7 @@ def test_cube2md5(self):
shutil.copyfile(test_file('cube2md5.txt'), 'cube2md5.txt')
self.do_run_from_file(test_file('cube2md5.cpp'), test_file('cube2md5.ok'), assert_returncode=NON_ZERO)

@also_with_standalone_wasm(wasm2c=True)
@also_with_standalone_wasm()
@needs_make('make')
def test_cube2hash(self):
# A good test of i64 math
Expand Down Expand Up @@ -1089,7 +1079,7 @@ def test_regex(self):
self.do_core_test('test_regex.c')

@crossplatform
@also_with_standalone_wasm(wasm2c=True, impure=True)
@also_with_standalone_wasm(impure=True)
def test_longjmp_standalone(self):
self.do_core_test('test_longjmp.c')

Expand Down Expand Up @@ -6304,7 +6294,7 @@ def test_unistd_misc(self, fs):
self.emcc_args += ['-lnodefs.js']
self.do_run_in_out_file_test('unistd/misc.c', interleaved_output=False)

@also_with_standalone_wasm(wasm2c=True)
@also_with_standalone_wasm()
def test_posixtime(self):
self.do_core_test('test_posixtime.c')

Expand Down Expand Up @@ -7122,7 +7112,7 @@ def do_test():
else:
do_test_openjpeg()

@also_with_standalone_wasm(wasm2c=True, impure=True)
@also_with_standalone_wasm(impure=True)
@no_asan('autodebug logging interferes with asan')
@with_env_modify({'EMCC_AUTODEBUG': '1'})
def test_autodebug_wasm(self):
Expand All @@ -7134,28 +7124,6 @@ def test_autodebug_wasm(self):
for msg in ['log_execution', 'get_i32', 'set_i32', 'load_ptr', 'load_val', 'store_ptr', 'store_val']:
self.assertIn(msg, output)

@parameterized({
'full': ('full',),
'mask': ('mask',),
'none': ('none',),
})
def test_wasm2c_sandboxing(self, mode):
if self.get_setting('WASMFS'):
# wasm2c disables JS legalization since we are building in standalone
# mode. this happens to work without wasmfs, but with wasmfs we get the
# time when we create/update a file, which uses clock_time_get that has an
# i64 param. For such an import to work we need wasm-bigint support.
self.node_args += shared.node_bigint_flags()
if not can_do_standalone(self):
return self.skipTest('standalone mode not supported')
if not can_do_wasm2c(self):
return self.skipTest('wasm2c not supported')
self.set_setting('STANDALONE_WASM')
self.set_setting('WASM2C')
self.set_setting('WASM2C_SANDBOXING', mode)
self.wasm_engines = []
self.do_core_test('test_hello_world.c')

### Integration tests

@crossplatform
Expand Down
44 changes: 0 additions & 44 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11189,50 +11189,6 @@ def test_standalone_syscalls(self):
for engine in config.WASM_ENGINES:
self.assertContained(expected, self.run_js('test.wasm', engine))

@requires_native_clang
def test_wasm2c_reactor(self):
# test compiling an unsafe library using wasm2c, then using it from a
# main program. this shows it is easy to use wasm2c as a sandboxing
# mechanism.

# first compile the library with emcc, getting a .c and .h
self.run_process([EMCC,
test_file('other/wasm2c/unsafe-library.c'),
'-O3', '-o', 'lib.wasm', '-sWASM2C', '--no-entry'])
# compile the main program natively normally, together with the unsafe
# library
self.run_process([CLANG_CC,
test_file('other/wasm2c/my-code.c'),
'lib.wasm.c', '-O3', '-o', 'program.exe'] +
clang_native.get_clang_native_args(),
env=clang_native.get_clang_native_env())
output = self.run_process([os.path.abspath('program.exe')], stdout=PIPE).stdout
self.assertEqual(output, read_file(test_file('other/wasm2c/output.txt')))

@requires_native_clang
def test_wasm2c_multi_lib(self):
# compile two libraries to object files
for lib in ['a', 'b']:
self.run_process([EMCC,
test_file('other/wasm2c', f'unsafe-library-{lib}.c'),
'-O3', '-o', f'lib{lib}.wasm', '-sWASM2C', '--no-entry'])
# build with a different WASM_RT_MODULE_PREFIX for each library, so that
# they do not have colliding symbols
self.run_process([CLANG_CC, f'lib{lib}.wasm.c', '-O3', '-c',
f'-DWASM_RT_MODULE_PREFIX={lib}_'] +
clang_native.get_clang_native_args(),
env=clang_native.get_clang_native_env())

# compile the main program with the wasmboxed libraries
self.run_process([CLANG_CC,
test_file('other/wasm2c/my-code-multi.c'),
'liba.wasm.o', 'libb.wasm.o',
'-O3', '-o', 'program.exe'] +
clang_native.get_clang_native_args(),
env=clang_native.get_clang_native_env())
output = self.run_process([os.path.abspath('program.exe')], stdout=PIPE).stdout
self.assertEqual(output, read_file(test_file('other/wasm2c/output-multi.txt')))

@parameterized({
'wasm2js': (['-sWASM=0'], ''),
'modularize': (['-sMODULARIZE'], 'Module()'),
Expand Down
Loading