Skip to content

Commit b213e33

Browse files
woesselkorchi
authored andcommitted
[GR-56805] Include wasm in js standalone.
PullRequest: js/3316
2 parents 2ce4ba6 + 65cfdad commit b213e33

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

graal-js/ci.jsonnet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ local ci = import '../ci.jsonnet';
3737
},
3838

3939
local nativeImageSmokeTest = checkoutJsBenchmarks + {
40-
suiteimports+:: ['vm', 'substratevm'],
40+
suiteimports+:: ['vm', 'substratevm', 'wasm'],
4141
nativeimages+:: ['lib:jsvm', 'lib:jvmcicompiler'],
4242
extraimagebuilderarguments+:: ['-H:+ReportExceptionStackTraces'],
4343
run+: [
@@ -49,9 +49,11 @@ local ci = import '../ci.jsonnet';
4949
['set-export', 'STANDALONE_HOME', ['mx', '--quiet', 'standalone-home', 'js', '--type=native']],
5050
['${STANDALONE_HOME}/bin/js', '--native', '-e', "print('hello:' + Array.from(new Array(10), (x,i) => i*i ).join('|'))"],
5151
['${STANDALONE_HOME}/bin/js', '--native', '../../js-benchmarks/harness.js', '--', '../../js-benchmarks/octane-richards.js', '--show-warmup'],
52+
['${STANDALONE_HOME}/bin/js', '--experimental-options', '--js.webassembly', '-e', 'new WebAssembly.Module(new Uint8Array([0x00,0x61,0x73,0x6d,0x01,0x00,0x00,0x00]))'],
5253
['set-export', 'STANDALONE_HOME', ['mx', '--quiet', 'standalone-home', 'js', '--type=jvm']],
5354
['${STANDALONE_HOME}/bin/js', '--jvm', '-e', "print('hello:' + Array.from(new Array(10), (x,i) => i*i ).join('|'))"],
5455
['${STANDALONE_HOME}/bin/js', '--jvm', '../../js-benchmarks/harness.js', '--', '../../js-benchmarks/octane-richards.js', '--show-warmup'],
56+
['${STANDALONE_HOME}/bin/js', '--experimental-options', '--js.webassembly', '-e', 'new WebAssembly.Module(new Uint8Array([0x00,0x61,0x73,0x6d,0x01,0x00,0x00,0x00]))'],
5557
# maven-downloader smoke test
5658
['VERBOSE_GRAALVM_LAUNCHERS=true', '${STANDALONE_HOME}/bin/js-polyglot-get', '-o', 'maven downloader output', '-a', 'wasm', '-v', '23.1.3'],
5759
],

graal-js/mx.graal-js/mx_graal_js.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
480480
'src', meta_pom.name, meta_pom.maven_group_id(), meta_pom.theLicense,
481481
isolate_build_options=isolate_build_options)
482482

483+
def is_wasm_available():
484+
return any(wasm_suite in mx.get_dynamic_imports() for wasm_suite in [('wasm', True), ('wasm-enterprise', True)])
485+
483486

484487
mx_sdk.register_graalvm_component(mx_sdk.GraalVmLanguage(
485488
suite=_suite,
@@ -506,21 +509,25 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
506509
truffle_jars=[
507510
'graal-js:GRAALJS',
508511
'sdk:MAVEN_DOWNLOADER',
512+
*(['wasm:WASM'] if is_wasm_available() else []),
509513
],
510514
support_distributions=[
511515
'graal-js:GRAALJS_GRAALVM_SUPPORT',
512516
],
513517
library_configs=[
514518
mx_sdk.LanguageLibraryConfig(
515519
launchers=['bin/<exe:js>'],
516-
jar_distributions=['graal-js:GRAALJS_LAUNCHER'],
520+
jar_distributions=[
521+
'graal-js:GRAALJS_LAUNCHER',
522+
*(['wasm:WASM'] if is_wasm_available() else [])
523+
],
517524
main_class='com.oracle.truffle.js.shell.JSLauncher',
518525
build_args=[],
519526
build_args_enterprise=[
520527
'-H:+AuxiliaryEngineCache',
521528
'-H:ReservedAuxiliaryImageBytes=2145482548',
522529
] if not mx.is_windows() else [],
523-
language='js'
530+
language='js',
524531
)
525532
],
526533
boot_jars=[],

graal-js/src/com.oracle.truffle.js.shell/src/com/oracle/truffle/js/shell/JSLauncher.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import java.io.File;
4848
import java.io.IOException;
49+
import java.io.OutputStream;
4950
import java.io.PrintStream;
5051
import java.nio.charset.StandardCharsets;
5152
import java.nio.file.Files;
@@ -69,6 +70,7 @@
6970

7071
public class JSLauncher extends AbstractLanguageLauncher {
7172
static final String MODULE_MIME_TYPE = "application/javascript+module";
73+
private static final String WASM_LANGUAGE_ID = "wasm";
7274
private static final String PROMPT = "> ";
7375

7476
public static void main(String[] args) {
@@ -79,6 +81,7 @@ public static void main(String[] args) {
7981
private boolean fuzzilliREPRL = false;
8082
private boolean allowExperimentalOptions = false;
8183
private boolean useSharedEngine = false;
84+
private boolean wasmEnabled = false;
8285
private String[] programArgs;
8386
private final List<UnparsedSource> unparsedSources = new LinkedList<>();
8487
private VersionAction versionAction = VersionAction.None;
@@ -102,6 +105,15 @@ protected String getLanguageId() {
102105
return "js";
103106
}
104107

108+
@Override
109+
protected String[] getDefaultLanguages() {
110+
if (wasmEnabled && isLanguageAvailable(WASM_LANGUAGE_ID)) {
111+
return new String[]{getLanguageId(), WASM_LANGUAGE_ID};
112+
} else {
113+
return super.getDefaultLanguages();
114+
}
115+
}
116+
105117
protected void preEval(@SuppressWarnings("unused") Context context) {
106118
}
107119

@@ -141,7 +153,8 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
141153

142154
String value;
143155
int equalsIndex = flag.indexOf('=');
144-
if (equalsIndex > 0) {
156+
boolean hasEquals = equalsIndex > 0;
157+
if (hasEquals) {
145158
value = flag.substring(equalsIndex + 1);
146159
flag = flag.substring(0, equalsIndex);
147160
} else if (iterator.hasNext()) {
@@ -157,8 +170,12 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
157170
throw abort("Missing argument for " + arg);
158171
}
159172

173+
if (flag.equals("js.webassembly") || flag.equals("webassembly")) {
174+
wasmEnabled = !hasEquals || "true".equals(value);
175+
}
176+
160177
unrecognizedOptions.add(arg);
161-
if (equalsIndex < 0 && value != null) {
178+
if (!hasEquals && value != null) {
162179
iterator.previous();
163180
}
164181
} else {
@@ -531,6 +548,16 @@ private static void printStackTraceSkipTrailingHost(PolyglotException e, StringB
531548
}
532549
}
533550

551+
private static boolean isLanguageAvailable(String languageId) {
552+
try (Engine tempEngine = Engine.newBuilder().useSystemProperties(false).//
553+
out(OutputStream.nullOutputStream()).//
554+
err(OutputStream.nullOutputStream()).//
555+
option("engine.WarnInterpreterOnly", "false").//
556+
build()) {
557+
return tempEngine.getLanguages().containsKey(languageId);
558+
}
559+
}
560+
534561
private enum SourceType {
535562
FILE,
536563
EVAL,

graal-nodejs/mx.graal-nodejs/mx_graal_nodejs.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from mx_gate import Task
3737
from argparse import ArgumentParser
3838
from os.path import exists, join, isdir, pathsep, sep
39-
from mx_graal_js import get_jdk
39+
from mx_graal_js import get_jdk, is_wasm_available
4040

4141
_suite = mx.suite('graal-nodejs')
4242
_current_os = mx.get_os()
@@ -616,9 +616,6 @@ def _prepare_svm_env():
616616
def mx_post_parse_cmd_line(args):
617617
mx_graal_nodejs_benchmark.register_nodejs_vms()
618618

619-
def _is_wasm_available():
620-
return any(wasm_suite in mx.get_dynamic_imports() for wasm_suite in [('wasm', True), ('wasm-enterprise', True)])
621-
622619
mx_sdk.register_graalvm_component(mx_sdk.GraalVmLanguage(
623620
suite=_suite,
624621
name='Graal.nodejs',
@@ -633,7 +630,7 @@ def _is_wasm_available():
633630
truffle_jars=[
634631
'graal-nodejs:TRUFFLENODE',
635632
'sdk:MAVEN_DOWNLOADER',
636-
*(['wasm:WASM'] if _is_wasm_available() else []),
633+
*(['wasm:WASM'] if is_wasm_available() else []),
637634
],
638635
support_distributions=[
639636
'graal-nodejs:TRUFFLENODE_GRAALVM_SUPPORT',
@@ -651,13 +648,13 @@ def _is_wasm_available():
651648
destination='lib/<lib:graal-nodejs>',
652649
jar_distributions=[
653650
'graal-nodejs:TRUFFLENODE',
654-
*(['wasm:WASM'] if _is_wasm_available() else []),
651+
*(['wasm:WASM'] if is_wasm_available() else []),
655652
],
656653
build_args=[
657654
'--tool:all',
658655
'--language:nodejs',
659656
'-Dgraalvm.libpolyglot=true', # `lib:graal-nodejs` should be initialized like `lib:polyglot` (GR-10038)
660-
*(['--language:wasm'] if _is_wasm_available() else []),
657+
*(['--language:wasm'] if is_wasm_available() else []),
661658
],
662659
build_args_enterprise=[
663660
'-H:+AuxiliaryEngineCache',

0 commit comments

Comments
 (0)