Skip to content

Commit 588ae3a

Browse files
jerboaazakkak
authored andcommitted
Fix build with --no-jlinking
1 parent eef7b54 commit 588ae3a

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,13 +2220,9 @@ def _get_extra_jvm_args():
22202220
extra_jvm_args = mx.list_to_cmd_line(image_config.extra_jvm_args)
22212221
if not _jlink_libraries():
22222222
if mx.is_windows():
2223-
extra_jvm_args = ' '.join([extra_jvm_args, r'--upgrade-module-path "%location%\..\..\jvmci\graal.jar"',
2224-
r'--add-modules org.graalvm.polyglot',
2225-
r'--module-path "%location%\..\..\truffle\truffle-api.jar:%location%\..\..\jvmci\polyglot.jar"'])
2223+
extra_jvm_args = ' '.join([extra_jvm_args, r'--upgrade-module-path "%location%\..\..\jvmci\graal.jar"'])
22262224
else:
2227-
extra_jvm_args = ' '.join([extra_jvm_args, '--upgrade-module-path "${location}/../../jvmci/graal.jar"',
2228-
'--add-modules org.graalvm.polyglot',
2229-
'--module-path "${location}/../../truffle/truffle-api.jar:${location}/../../jvmci/polyglot.jar"'])
2225+
extra_jvm_args = ' '.join([extra_jvm_args, '--upgrade-module-path "${location}/../../jvmci/graal.jar"'])
22302226
return extra_jvm_args
22312227

22322228
def _get_option_vars():

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,12 @@ public List<String> getBuilderJavaArgs() {
561561
*/
562562
public List<Path> getBuilderModulePath() {
563563
List<Path> result = new ArrayList<>();
564-
// Non-jlinked JDKs need truffle and graal-sdk on the module path since they
565-
// don't have those modules as part of the JDK.
564+
// Non-jlinked JDKs need truffle and word, collections, nativeimage on the
565+
// module path since they don't have those modules as part of the JDK. Note
566+
// that graal-sdk is now obsolete after the split in GR-43819 (#7171)
566567
if (libJvmciDir != null) {
567-
result.addAll(getJars(libJvmciDir, "graal-sdk", "enterprise-graal"));
568+
result.addAll(getJars(libJvmciDir, "enterprise-graal"));
569+
result.addAll(getJars(libJvmciDir, "word", "collections", "nativeimage"));
568570
}
569571
if (modulePathBuild) {
570572
result.addAll(createTruffleBuilderModulePath());
@@ -574,19 +576,36 @@ public List<Path> getBuilderModulePath() {
574576
}
575577

576578
private List<Path> createTruffleBuilderModulePath() {
577-
List<Path> jars = getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api", "truffle-runtime", "truffle-enterprise");
579+
Path libTruffleDir = rootDir.resolve(Paths.get("lib", "truffle"));
580+
List<Path> jars = getJars(libTruffleDir, "truffle-api", "truffle-runtime", "truffle-enterprise");
578581
if (!jars.isEmpty()) {
579582
/*
580583
* If Truffle is installed as part of the JDK we always add the builder modules of
581584
* Truffle to the builder module path. This is legacy support and should in the
582585
* future no longer be needed.
583586
*/
584-
jars.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-compiler"));
587+
jars.addAll(getJars(libTruffleDir, "truffle-compiler"));
585588
Path builderPath = rootDir.resolve(Paths.get("lib", "truffle", "builder"));
586589
if (Files.exists(builderPath)) {
587590
jars.addAll(getJars(builderPath, "truffle-runtime-svm", "truffle-enterprise-svm"));
591+
if (libJvmciDir != null) {
592+
// truffle-runtime-svm depends on polyglot, which is not part of non-jlinked
593+
// JDKs
594+
jars.addAll(getJars(libJvmciDir, "polyglot"));
595+
}
596+
}
597+
if (libJvmciDir != null) {
598+
// truffle-runtime depends on polyglot, which is not part of non-jlinked JDKs
599+
jars.addAll(getJars(libTruffleDir, "jniutils"));
588600
}
589601
}
602+
/*
603+
* Non-Jlinked JDKs don't have truffle-compiler as part of the JDK, however the native
604+
* image builder still needs it
605+
*/
606+
if (libJvmciDir != null) {
607+
jars.addAll(getJars(libTruffleDir, "truffle-compiler"));
608+
}
590609

591610
return jars;
592611
}
@@ -1544,7 +1563,8 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
15441563
Function<Path, Path> substituteModulePath = useBundle() ? bundleSupport::substituteModulePath : Function.identity();
15451564
List<Path> substitutedImageModulePath = imagemp.stream().map(substituteModulePath).toList();
15461565

1547-
Map<String, Path> modules = listModulesFromPath(javaExecutable, Stream.concat(mp.stream(), imagemp.stream()).distinct().toList());
1566+
List<String> mainClassArg = config.getGeneratorMainClass();
1567+
Map<String, Path> modules = listModulesFromPath(javaExecutable, javaArgs, mainClassArg, mp.stream().distinct().toList(), imagemp.stream().distinct().toList());
15481568
if (!addModules.isEmpty()) {
15491569

15501570
arguments.add("-D" + ModuleSupport.PROPERTY_IMAGE_EXPLICITLY_ADDED_MODULES + "=" +
@@ -1564,7 +1584,7 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
15641584
}
15651585
}
15661586

1567-
arguments.addAll(config.getGeneratorMainClass());
1587+
arguments.addAll(mainClassArg);
15681588

15691589
if (IS_AOT && OS.getCurrent().hasProcFS) {
15701590
/*
@@ -1715,33 +1735,41 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
17151735
/**
17161736
* Resolves and lists all modules given a module path.
17171737
*
1718-
* @see #callListModules(String, List)
1738+
* @see #callListModules(String, List, List, List, List)
17191739
*/
1720-
private Map<String, Path> listModulesFromPath(String javaExecutable, Collection<Path> modulePath) {
1740+
private Map<String, Path> listModulesFromPath(String javaExecutable, List<String> javaArgs, List<String> mainClassArg, List<Path> modulePath, List<Path> imagemp) {
17211741
if (modulePath.isEmpty() || !config.modulePathBuild) {
17221742
return Map.of();
17231743
}
17241744
String modulePathEntries = modulePath.stream()
17251745
.map(Path::toString)
17261746
.collect(Collectors.joining(File.pathSeparator));
1727-
return callListModules(javaExecutable, List.of("-p", modulePathEntries));
1747+
String imagePathEntries = imagemp.stream()
1748+
.map(Path::toString)
1749+
.collect(Collectors.joining(File.pathSeparator));
1750+
List<String> imagempArgs = List.of("-imagemp", imagePathEntries);
1751+
List<String> modulePathArgs = List.of("--module-path", modulePathEntries);
1752+
return callListModules(javaExecutable, javaArgs, mainClassArg, imagempArgs, modulePathArgs);
17281753
}
17291754

17301755
/**
1731-
* Calls <code>java $arguments --list-modules</code> to list all modules and parse the output.
1732-
* The output consists of a map with module name as key and {@link Path} to jar file if the
1733-
* module is not installed as part of the JDK. If the module is installed as part of the
1756+
* Calls the image generator's <code>--list-modules</code> to list all modules and parses the
1757+
* output. The output consists of a map with module name as key and {@link Path} to jar file if
1758+
* the module is not installed as part of the JDK. If the module is installed as part of the
17341759
* jdk/boot-layer then a <code>null</code> path will be returned.
17351760
* <p>
17361761
* This is a much more robust solution then trying to parse the JDK file structure manually.
17371762
*/
1738-
private static Map<String, Path> callListModules(String javaExecutable, List<String> arguments) {
1763+
private static Map<String, Path> callListModules(String javaExecutable, List<String> javaArgs, List<String> mainClassArg, List<String> imagempArgs, List<String> modulePathArgs) {
17391764
Process listModulesProcess = null;
17401765
Map<String, Path> result = new LinkedHashMap<>();
17411766
try {
17421767
var pb = new ProcessBuilder(javaExecutable);
1743-
pb.command().addAll(arguments);
1744-
pb.command().add("--list-modules");
1768+
pb.command().addAll(javaArgs);
1769+
pb.command().addAll(modulePathArgs);
1770+
pb.command().addAll(mainClassArg);
1771+
pb.command().addAll(imagempArgs);
1772+
pb.command().add("-H:+ListModules");
17451773
pb.environment().clear();
17461774
listModulesProcess = pb.start();
17471775

@@ -1758,8 +1786,10 @@ private static Map<String, Path> callListModules(String javaExecutable, List<Str
17581786
String[] splitModuleNameAndVersion = StringUtil.split(splitString[0], "@", 2);
17591787
Path externalPath = null;
17601788
if (splitString.length > 1) {
1761-
String pathURI = splitString[1]; // url: file://path/to/file
1762-
externalPath = Path.of(URI.create(pathURI)).toAbsolutePath();
1789+
String pathURI = splitString[1].trim(); // url: file://path/to/file
1790+
if (pathURI.startsWith("file://")) {
1791+
externalPath = Path.of(URI.create(pathURI)).toAbsolutePath();
1792+
}
17631793
}
17641794
result.put(splitModuleNameAndVersion[0], externalPath);
17651795
}

0 commit comments

Comments
 (0)