From c1eaa2373d11d1751ad3e16861da39ea975185a5 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Fri, 26 Jan 2024 14:21:38 +0200 Subject: [PATCH] Only build and include svm-foreign when building with JDK > 21 Since https://github.com/oracle/graal/pull/7980 the foreign API is only available for JDK >= 22 builds. --- build.java | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/build.java b/build.java index a8e5c16..0bb4bb6 100644 --- a/build.java +++ b/build.java @@ -138,10 +138,13 @@ public static void main(String... args) throws IOException FileSystem.copy(mandrelRepo.resolve( Path.of("sdk", "mxbuild", PLATFORM, "native-image.exe.image-bash", "native-image.export-list")), nativeImageExport); } - logger.debugf("Copy svm-preview..."); - final Path svmForeign = mandrelJavaHome.resolve(Path.of("lib", "svm-preview", "builder", "svm-foreign.jar")); - final Path svmForeignSource = PathFinder.getFirstExisting(mandrelRepo.resolve(Path.of("substratevm", "mxbuild")).toString(), "svm-foreign.jar"); - FileSystem.copy(svmForeignSource, svmForeign); + if (Runtime.version().feature() > 21) + { + logger.debugf("Copy svm-preview..."); + final Path svmForeign = mandrelJavaHome.resolve(Path.of("lib", "svm-preview", "builder", "svm-foreign.jar")); + final Path svmForeignSource = PathFinder.getFirstExisting(mandrelRepo.resolve(Path.of("substratevm", "mxbuild")).toString(), "svm-foreign.jar"); + FileSystem.copy(svmForeignSource, svmForeign); + } } if (!options.skipNative) @@ -854,20 +857,34 @@ class Mx private static final Pattern DEPENDENCY_VERSION_PATTERN = Pattern.compile("\"version\"\\s*:\\s*\"([0-9.]*)\""); - static final List BUILD_JAVA_STEPS = List.of( - BuildArgs.of("--no-native", "--dependencies", "SVM,SVM_FOREIGN,GRAAL_SDK,SVM_DRIVER,SVM_AGENT,SVM_DIAGNOSTICS_AGENT") - , BuildArgs.of("--only", - build.IS_WINDOWS ? - "native-image.exe.image-bash," + - "native-image-agent-library_native-image.properties," + - "native-image-launcher_native-image.properties," + - "native-image-diagnostics-agent-library_native-image.properties" - : - "native-image.image-bash," + - "native-image-agent-library_native-image.properties," + - "native-image-launcher_native-image.properties," + - "native-image-diagnostics-agent-library_native-image.properties") - ); + static final List BUILD_JAVA_STEPS; + + static { + String dependencies; + if (Runtime.version().feature() > 21) + { + dependencies = "SVM,SVM_FOREIGN,GRAAL_SDK,SVM_DRIVER,SVM_AGENT,SVM_DIAGNOSTICS_AGENT"; + } + else + { + dependencies = "SVM,GRAAL_SDK,SVM_DRIVER,SVM_AGENT,SVM_DIAGNOSTICS_AGENT"; + } + + BUILD_JAVA_STEPS = List.of( + BuildArgs.of("--no-native", "--dependencies", dependencies) + , BuildArgs.of("--only", + build.IS_WINDOWS ? + "native-image.exe.image-bash," + + "native-image-agent-library_native-image.properties," + + "native-image-launcher_native-image.properties," + + "native-image-diagnostics-agent-library_native-image.properties" + : + "native-image.image-bash," + + "native-image-agent-library_native-image.properties," + + "native-image-launcher_native-image.properties," + + "native-image-diagnostics-agent-library_native-image.properties") + ); + } static final List BUILD_NATIVE_STEPS;