Skip to content

Commit 2385a96

Browse files
author
Felix Berlakovich
committed
[GR-58514] Open WasmLauncher for extension
PullRequest: graal/20324
2 parents 6d5b9bd + 05d911b commit 2385a96

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

wasm/mx.wasm/mx_wasm.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# SOFTWARE.
4040
#
4141
import os
42+
import pathlib
4243
import re
4344
import shutil
4445
import stat
@@ -130,7 +131,7 @@ def wabt_test_args():
130131
if not wabt_dir:
131132
mx.warn("No WABT_DIR specified")
132133
return []
133-
return ["-Dwasmtest.watToWasmExecutable=" + os.path.join(wabt_dir, mx.exe_suffix("wat2wasm"))]
134+
return ["-Dwasmtest.watToWasmExecutable=" + os.path.join(wabt_dir, mx.exe_suffix("wat2wasm")), "-Dwasmtest.watToWasmVerbose=true"]
134135

135136

136137
def graal_wasm_gate_runner(args, tasks):
@@ -633,7 +634,10 @@ def emscripten_init(args):
633634
parser = ArgumentParser(prog='mx emscripten-init', description='initialize the Emscripten environment.')
634635
parser.add_argument('config_path', help='path of the config file to be generated')
635636
parser.add_argument('emsdk_path', help='path of the emsdk')
636-
parser.add_argument('--local', action='store_true', help='Generates config file for local dev environment')
637+
638+
path_mode_group = parser.add_mutually_exclusive_group()
639+
path_mode_group.add_argument('--detect', action='store_true', help='Try to detect the necessary directories in the emsdk automatically')
640+
path_mode_group.add_argument('--local', action='store_true', help='Generates config file for local dev environment')
637641
args = parser.parse_args(args)
638642
config_path = os.path.join(os.getcwd(), args.config_path)
639643
emsdk_path = args.emsdk_path
@@ -643,6 +647,21 @@ def emscripten_init(args):
643647
emscripten_root = os.path.join(emsdk_path, "emscripten", "master")
644648
node_js = os.path.join(emsdk_path, "node", "12.9.1_64bit", "bin", "node")
645649

650+
def find_executable(exe_name):
651+
for root, _, files in os.walk(args.emsdk_path):
652+
if exe_name in files:
653+
full_path = pathlib.Path(root, exe_name)
654+
if os.access(full_path, os.X_OK):
655+
return full_path
656+
657+
mx.abort(f"Unable to find {exe_name} in {args.emsdk_path}")
658+
659+
if args.detect:
660+
llvm_root = str(find_executable("llvm-ar").parent)
661+
binaryen_root = str(find_executable("binaryen-lit").parent.parent)
662+
emscripten_root = str(find_executable("emcc").parent)
663+
node_js = str(find_executable("node"))
664+
646665
if args.local:
647666
llvm_root = os.path.join(emsdk_path, "upstream", "bin")
648667
binaryen_root = os.path.join(emsdk_path, "upstream", "lib")

wasm/src/org.graalvm.wasm.launcher/src/org/graalvm/wasm/launcher/WasmLauncher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
import org.graalvm.polyglot.Value;
5757

5858
public class WasmLauncher extends AbstractLanguageLauncher {
59-
private File file = null;
59+
protected File file = null;
6060
private VersionAction versionAction = VersionAction.None;
61-
private String customEntryPoint = null;
62-
private String[] programArguments = null;
61+
protected String customEntryPoint = null;
62+
protected String[] programArguments = null;
6363
private ArrayList<String> argumentErrors = null;
6464

6565
private static final String USAGE = "Usage: wasm [OPTION...] [FILE] [ARG...]";
@@ -168,7 +168,7 @@ private int execute(Context.Builder contextBuilder) {
168168
}
169169
}
170170

171-
private Value detectEntryPoint(Value mainModule) {
171+
protected Value detectEntryPoint(Value mainModule) {
172172
Value exports = mainModule.getMember("exports");
173173
if (customEntryPoint != null) {
174174
return exports.getMember(customEntryPoint);

wasm/src/org.graalvm.wasm.utils/src/org/graalvm/wasm/utils/SystemProperties.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,9 @@ public class SystemProperties {
4848
public static final String WAT_TO_WASM_EXECUTABLE_PROPERTY_NAME = "wasmtest.watToWasmExecutable";
4949
public static final String WAT_TO_WASM_EXECUTABLE = System.getProperty(WAT_TO_WASM_EXECUTABLE_PROPERTY_NAME);
5050

51+
public static final String WAT_TO_WASM_VERBOSE_PROPERTY_NAME = "wasmtest.watToWasmVerbose";
52+
public static final Boolean WAT_TO_WASM_VERBOSE = Boolean.parseBoolean(System.getProperty(WAT_TO_WASM_VERBOSE_PROPERTY_NAME, "false"));
53+
5154
public static final String BENCHMARK_NAME_PROPERTY_NAME = "wasmbench.benchmarkName";
5255
public static final String BENCHMARK_NAME = System.getProperty(BENCHMARK_NAME_PROPERTY_NAME);
5356

wasm/src/org.graalvm.wasm.utils/src/org/graalvm/wasm/utils/WasmBinaryTools.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,8 @@
4040
*/
4141
package org.graalvm.wasm.utils;
4242

43+
import static org.graalvm.wasm.utils.SystemProperties.WAT_TO_WASM_VERBOSE;
44+
4345
import java.io.File;
4446
import java.io.IOException;
4547
import java.io.InputStream;
@@ -188,7 +190,9 @@ private static String findWat2WasmExecutable() {
188190
map(Path::of).map(p -> p.resolve(WAT_TO_WASM_EXECUTABLE_NAME)).filter(Files::isExecutable).findFirst();
189191
if (executableInPath.isPresent()) {
190192
String pathAsString = executableInPath.get().toString();
191-
System.err.println(String.format("Using %s from %s", WAT_TO_WASM_EXECUTABLE_NAME, pathAsString));
193+
if (WAT_TO_WASM_VERBOSE) {
194+
System.err.println(String.format("Using %s from %s", WAT_TO_WASM_EXECUTABLE_NAME, pathAsString));
195+
}
192196
return pathAsString;
193197
}
194198
}
@@ -222,8 +226,10 @@ private static byte[] compileWatUncached(String name, String program, EnumSet<Wa
222226
try {
223227
return wat2wasmFromString(program, options);
224228
} catch (RuntimeException e) {
225-
System.err.println(e);
226-
System.err.println("wat2wasm compilation via stdin+stdout failed, retrying with temporary files");
229+
if (WAT_TO_WASM_VERBOSE) {
230+
System.err.println(e);
231+
System.err.println("wat2wasm compilation via stdin+stdout failed, retrying with temporary files");
232+
}
227233
compileUsingStdInOut = false;
228234
}
229235
}

0 commit comments

Comments
 (0)