-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
wasm2c support: compile everything into a single C file #11213
Changes from all commits
da18e44
c208a6d
802b60c
2daf554
7c0c920
38bc2b5
8114412
8bdf87e
cfbc317
e8ad395
efd17ee
5d8fc96
e555a04
6fcb454
fa81d58
7761591
f04b0e3
9b7f095
eab9809
3639b36
dd0bdb3
20eda6f
67c68f4
3f0d8dc
6e5bbfc
c445c0e
f450a40
649d7dd
2e449e5
30c1754
9587ea2
8592f85
d530716
4f8e128
6059231
50e7b18
70dd79f
35ffd97
56ffcf3
8d65523
d490cf9
73924dd
cd1bfbf
83502a5
5f3abb9
29fd4fd
6532c11
33f804a
d0b9a91
b1f5fa9
4028cab
fe05819
5f99dc5
b07152d
8dbc4d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
|
||
// We could | ||
// | ||
// #include <lib.wasm.h> | ||
// | ||
// for the externs declared here manually, but including that currently | ||
// requires having wasm-rt.h in the include path, which may be annoying for | ||
// users - needs to be thought about. | ||
|
||
extern void wasmbox_init(void); | ||
|
||
extern int (*Z_do_bad_thingZ_ii)(int); | ||
|
||
extern int (*Z_twiceZ_ii)(int); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it clearer to just use C ABI for these kinds of tests to avoid the name mangling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's name mangling that wasm2c does. cc @binji The |
||
|
||
int main() { | ||
puts("Initializing sandboxed unsafe library"); | ||
wasmbox_init(); | ||
printf("Calling twice on 21 returns %d\n", Z_twiceZ_ii(21)); | ||
puts("Calling something bad now..."); | ||
int num = Z_do_bad_thingZ_ii(1); | ||
printf("The sandbox should not have been able to print anything.\n" | ||
"It claims it printed %d chars but the test proves it didn't!\n", num); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Initializing sandboxed unsafe library | ||
Calling twice on 21 returns 42 | ||
Calling something bad now... | ||
The sandbox should not have been able to print anything. | ||
It claims it printed 55 chars but the test proves it didn't! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <emscripten.h> | ||
#include <stdio.h> | ||
|
||
EMSCRIPTEN_KEEPALIVE | ||
int twice(int x) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is a called ".c" but the name mangling looks like its being compiled as C++? |
||
return x + x; | ||
} | ||
|
||
EMSCRIPTEN_KEEPALIVE | ||
int do_bad_thing(int size) { | ||
return printf("I am in a sandbox and should not be able to print this!"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,12 @@ | |
sys.path.append(__rootpath__) | ||
|
||
import parallel_testsuite | ||
from tools.shared import EM_CONFIG, TEMP_DIR, EMCC, EMXX, DEBUG, LLVM_TARGET, ASM_JS_TARGET, EMSCRIPTEN_TEMP_DIR, WASM_TARGET, SPIDERMONKEY_ENGINE, WINDOWS, EM_BUILD_VERBOSE | ||
from tools.shared import asstr, get_canonical_temp_dir, run_process, try_delete, asbytes, safe_copy, Settings | ||
from tools.shared import EM_CONFIG, TEMP_DIR, EMCC, EMXX, DEBUG | ||
from tools.shared import LLVM_TARGET, ASM_JS_TARGET, EMSCRIPTEN_TEMP_DIR | ||
from tools.shared import WASM_TARGET, SPIDERMONKEY_ENGINE, WINDOWS | ||
from tools.shared import EM_BUILD_VERBOSE, CLANG_CC | ||
from tools.shared import asstr, get_canonical_temp_dir, run_process, try_delete | ||
from tools.shared import asbytes, safe_copy, Settings | ||
from tools import jsrun, shared, line_endings, building | ||
|
||
|
||
|
@@ -1231,6 +1235,9 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None, | |
if len(wasm_engines) == 0: | ||
logger.warning('no wasm engine was found to run the standalone part of this test') | ||
js_engines += wasm_engines | ||
if self.get_setting('WASM2C'): | ||
# the "engine" to run wasm2c builds is clang that compiles the c | ||
js_engines += [[CLANG_CC]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems odd. Maybe "js_engines" needs to be renamed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I'll look into that as a followup. |
||
if len(js_engines) == 0: | ||
self.skipTest('No JS engine present to run this test with. Check %s and the paths therein.' % EM_CONFIG) | ||
for engine in js_engines: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather that adding yet another feature to emcc itself, what about adding a separate tool for doing as post-link step?
Basically move the code you added to
shared.py
into a completely new command?Historically we tend to tack on more and more features to emcc itself. This seems like a great example of something that can be post-link step. At the very least it would be nice to be able to run it on its own, on existing wasm file. To this end maybe move the shared.py changes to
tools/wasm2c.py
.. to avoid shared.sh growing ever larger.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would be nice to be more modular. But I don't think it would be practical in this case, since the code needs to look at the compiler state - right now it already looks at
AUTODEBUG
andEXPECT_MAIN
, and it will need more for things like FS support options. In theory we could ask the user to pass the flags twice (to emcc and to the post-link tool) but I think that's not as usable.I think this is a non-intrusive change, at least - this won't thread itself around in emcc.py. It's just one chunk of code in shared.py.