diff --git a/native-build/BuildNativeImage.java b/native-build/BuildNativeImage.java index 884259cc..83c6b810 100644 --- a/native-build/BuildNativeImage.java +++ b/native-build/BuildNativeImage.java @@ -2,13 +2,11 @@ import java.net.*; import java.nio.file.*; import java.util.zip.*; +import java.util.*; public class BuildNativeImage { public static void main(String[] a) throws Exception { - String VERSION = "22.3.3"; - String JAVA_VERSION = "java17"; - Files.copy(Paths.get("../server/Peergos.jar"), Paths.get("Peergos.jar"), StandardCopyOption.REPLACE_EXISTING); String OS = canonicaliseOS(System.getProperty("os.name").toLowerCase()); @@ -17,12 +15,15 @@ public static void main(String[] a) throws Exception { String binExt = OS.equals("windows") ? ".cmd" : ""; String extraDirs = OS.equals("darwin") ? "/Contents/Home" : ""; - if (! new File("graalvm-ce-" + JAVA_VERSION + "-"+VERSION + extraDirs + "/bin/native-image" + binExt).exists()) - throw new IllegalStateException("native-image not installed..."); String ext = OS.equals("windows") ? ".exe" : ""; - + Optional nativeImage = Files.walk(Paths.get(""), 3) + .filter(p -> p.getFileName().startsWith("native-image") && p.toFile().isFile()) + .findFirst(); + if (nativeImage.isEmpty()) + throw new IllegalStateException("Couldn't find native image executable"); + // run native-image - runCommand("graalvm-ce-" + JAVA_VERSION + "-"+VERSION + extraDirs + "/bin/native-image" + binExt + + runCommand(nativeImage.get().toString() + " --allow-incomplete-classpath " + "-H:EnableURLProtocols=http " + "-H:EnableURLProtocols=https " + @@ -48,16 +49,16 @@ private static String getOsArch() { String os = canonicaliseOS(System.getProperty("os.name").toLowerCase()); String arch = canonicaliseArchitecture(System.getProperty("os.arch")); - return os + "-" + arch; + return os + "-" + canonicaliseArchitecture(arch); } private static String canonicaliseArchitecture(String arch) { if (arch.startsWith("arm64")) - return "arm64"; + return "aarch64"; if (arch.startsWith("arm")) return "arm"; - if (arch.startsWith("x86_64")) - return "amd64"; + if (arch.startsWith("amd64")) + return "x64"; if (arch.startsWith("x86")) return "386"; return arch; diff --git a/native-build/InstallNativeImage.java b/native-build/InstallNativeImage.java index 60041688..f61e2846 100644 --- a/native-build/InstallNativeImage.java +++ b/native-build/InstallNativeImage.java @@ -5,15 +5,14 @@ public class InstallNativeImage { public static void main(String[] a) throws Exception { - String VERSION = "22.3.3"; + String VERSION = "22.0.0"; String OS = canonicaliseOS(System.getProperty("os.name").toLowerCase()); String OS_ARCH = getOsArch(); System.out.println("OS-ARCH: " + OS_ARCH); - String ext = OS.equals("windows") ? ".zip" : ".tar.gz"; - String JAVA_VERSION = "java17"; - String filename = "graalvm-ce-" + JAVA_VERSION + "-" + OS_ARCH + "-"+VERSION+ext; - String url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-" +VERSION +"/" + filename; + String ext = OS.equals("windows") ? "bin.zip" : "bin.tar.gz"; + String filename = "graalvm-community-jdk-" + VERSION + "_" + OS_ARCH + "_"+ext; + String url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-" +VERSION +"/" + filename; // Download graalVM if (! new File(filename).exists()) @@ -25,10 +24,12 @@ public static void main(String[] a) throws Exception { // install native-image String binExt = OS.equals("windows") ? ".cmd" : ""; - String extraDirs = OS.equals("darwin") ? "/Contents/Home" : ""; - runCommand("./graalvm-ce-" + JAVA_VERSION + "-" + VERSION + extraDirs + "/bin/gu" + binExt + " install native-image"); - if (new File("graalvm-ce-" + JAVA_VERSION + "-"+VERSION + extraDirs + "/bin/native-image" + binExt).exists()) + Optional nativeImage = Files.walk(Paths.get(""), 3) + .filter(p -> p.getFileName().startsWith("native-image") && p.toFile().isFile()) + .findFirst(); + + if (nativeImage.isPresent()) System.out.println("native-image installed"); else throw new IllegalStateException("native-image not installed..."); @@ -63,16 +64,16 @@ private static String getOsArch() { String os = canonicaliseOS(System.getProperty("os.name").toLowerCase()); String arch = canonicaliseArchitecture(System.getProperty("os.arch")); - return os + "-" + arch; + return os + "-" + canonicaliseArchitecture(arch); } private static String canonicaliseArchitecture(String arch) { if (arch.startsWith("arm64")) - return "arm64"; + return "aarch64"; if (arch.startsWith("arm")) return "arm"; - if (arch.startsWith("x86_64")) - return "amd64"; + if (arch.startsWith("amd64")) + return "x64"; if (arch.startsWith("x86")) return "386"; return arch;