Skip to content

Commit 6326c55

Browse files
committed
Support inline flags for Emscripten benchmarks, update Emscripten
1 parent f4a4dcf commit 6326c55

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

wasm/ci/ci_common/common.jsonnet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ local graal_suite_root = root_ci.graal_suite_root;
8080

8181
emsdk:: {
8282
downloads+: {
83-
EMSDK_DIR: {name: 'emsdk', version: '1.39.13', platformspecific: true},
83+
EMSDK_DIR: {name: 'emsdk', version: '4.0.10', platformspecific: true},
8484
},
8585
environment+: {
86-
EMCC_DIR: '$EMSDK_DIR/emscripten/master/'
86+
EMCC_DIR: '$EMSDK_DIR/upstream/emscripten/'
8787
}
8888
},
8989

@@ -125,7 +125,7 @@ local graal_suite_root = root_ci.graal_suite_root;
125125
setup+: [
126126
['set-export', 'ROOT_DIR', ['pwd']],
127127
['set-export', 'EM_CONFIG', '$ROOT_DIR/.emscripten-config'],
128-
['mx', 'emscripten-init', '$EM_CONFIG', '$EMSDK_DIR']
128+
['mx', 'emscripten-init', '--detect', '$EM_CONFIG', '$EMSDK_DIR']
129129
],
130130
},
131131

wasm/docs/contributor/TestsAndBenchmarks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To compile these programs, you will need to install additional dependencies on y
5454
To build these additional tests and benchmarks, you need to:
5555
5656
1. Install the [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html).
57-
We currently test against Emscripten **1.39.13**.
57+
We currently test against Emscripten **4.0.10**.
5858
```bash
5959
$ cd [preferred emsdk install location]
6060
@@ -129,7 +129,7 @@ The benchmarks are kept in the `src/com.oracle.truffle.wasm.benchcases` MX proje
129129
For the benchmarks to run, `NODE_DIR` has to be set. You can use the node version that is part of Emscripten, for example:
130130

131131
```bash
132-
$ export NODE_DIR=[path to emsdk]/node/14.15.5_64bit/bin
132+
$ export NODE_DIR=[path to emsdk]/node/22.16.0_64bit/bin
133133
```
134134

135135
After building the additional benchmarks, as described in the last section, they can be executed as follows:

wasm/mx.wasm/mx_wasm.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def processDeps(self, deps):
220220
"_benchmarkSetupEach",
221221
"_benchmarkTeardownEach",
222222
"_benchmarkRun",
223-
"_main"
224223
]
225224

226225

@@ -469,7 +468,7 @@ def build(self):
469468
include_flags = []
470469
if hasattr(self.project, "includeset"):
471470
include_flags = ["-I", os.path.join(_suite.dir, "includes", self.project.includeset)]
472-
emcc_flags = ["-s", "EXIT_RUNTIME=1", "-s", "STANDALONE_WASM", "-s", "WASM_BIGINT"] + cc_flags
471+
emcc_flags = ["-s", "STANDALONE_WASM", "-s", "WASM_BIGINT"] + cc_flags
473472
if self.project.isBenchmarkProject():
474473
emcc_flags = emcc_flags + ["-s", "EXPORTED_FUNCTIONS=" + str(self.benchmark_methods()).replace("'", "\"") + ""]
475474
subdir_program_names = defaultdict(lambda: [])
@@ -489,12 +488,23 @@ def build(self):
489488
timestampedOutput = mx.TimeStampFile(output_wasm_path)
490489
mustRebuild = timestampedSource.isNewerThan(timestampedOutput) or not timestampedOutput.exists()
491490

491+
source_cc_flags = []
492+
native_bench = True
493+
if filename.endswith(".c"):
494+
with open(source_path) as f:
495+
source_file = f.read()
496+
for flags in re.findall(r'//\s*CFLAGS\s*=\s*(.*)\n', source_file):
497+
source_cc_flags.extend(flags.split())
498+
native_bench_option = re.search(r'//\s*NATIVE_BENCH\s*=\s*(.*)\n', source_file)
499+
if native_bench_option:
500+
native_bench = native_bench_option.group(1).lower() == "true"
501+
492502
# Step 1: build the .wasm binary.
493503
if mustRebuild:
494504
if filename.endswith(".c"):
495505
# This generates both a js file and a wasm file.
496506
# See https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone
497-
build_cmd_line = [emcc_cmd] + emcc_flags + [source_path, "-o", output_js_path] + include_flags
507+
build_cmd_line = [emcc_cmd] + emcc_flags + source_cc_flags + [source_path, "-o", output_js_path] + include_flags
498508
if mx.run(build_cmd_line, nonZeroIsFatal=False) != 0:
499509
mx.abort("Could not build the wasm-only output of " + filename + " with emcc.")
500510
elif filename.endswith(".wat"):
@@ -533,11 +543,11 @@ def build(self):
533543

534544
# Step 5: if this is a benchmark project, create native binaries too.
535545
if mustRebuild:
536-
if filename.endswith(".c"):
546+
if filename.endswith(".c") and native_bench:
537547
mx_util.ensure_dir_exists(os.path.join(output_dir, subdir, NATIVE_BENCH_DIR))
538548
output_path = os.path.join(output_dir, subdir, NATIVE_BENCH_DIR, mx.exe_suffix(basename))
539549
link_flags = ["-lm"]
540-
gcc_cmd_line = [gcc_cmd] + cc_flags + [source_path, "-o", output_path] + include_flags + link_flags
550+
gcc_cmd_line = [gcc_cmd] + cc_flags + source_cc_flags + [source_path, "-o", output_path] + include_flags + link_flags
541551
if mx.run(gcc_cmd_line, nonZeroIsFatal=False) != 0:
542552
mx.abort("Could not build the native binary of " + filename + ".")
543553
os.chmod(output_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -666,7 +676,7 @@ def find_executable(exe_name):
666676
llvm_root = os.path.join(emsdk_path, "upstream", "bin")
667677
binaryen_root = os.path.join(emsdk_path, "upstream", "lib")
668678
emscripten_root = os.path.join(emsdk_path, "upstream", "emscripten")
669-
node_js = os.path.join(emsdk_path, "node", "14.15.5_64bit", "bin", "node")
679+
node_js = os.path.join(emsdk_path, "node", "22.16.0_64bit", "bin", "node")
670680

671681
mx.log("Generating Emscripten configuration...")
672682
mx.log("Config file path: " + str(config_path))

wasm/mx.wasm/mx_wasm_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def run_vm(self, args, out=None, err=None, cwd=None, nonZeroIsFatal=False):
166166
try:
167167
tmp_dir = self.extract_jar_to_tempdir(jar, suite, benchmark)
168168
node_cmd = os.path.join(node_dir, "node")
169-
node_cmd_line = [node_cmd, "--experimental-wasm-bigint", os.path.join(tmp_dir, "bench", suite, benchmark + ".js")]
169+
node_cmd_line = [node_cmd, os.path.join(tmp_dir, "bench", suite, benchmark + ".js")]
170170
mx.log("Running benchmark " + benchmark + " with node.")
171171
mx.run(node_cmd_line, cwd=tmp_dir, out=out, err=err, nonZeroIsFatal=nonZeroIsFatal)
172172
finally:

0 commit comments

Comments
 (0)