From 5a723fedffe0bad8b44b09c0fcb1d3bf25e5fae2 Mon Sep 17 00:00:00 2001 From: dkimitsa Date: Sat, 16 Jul 2022 15:09:44 +0300 Subject: [PATCH 1/4] * fixed #669: this enables swift support by default with option to disable it as mentioned in #669 its nice to have it enabled to ths compatibility with 2.3.16. same time added option to disable `swiftSupport` block in case it causes issues, can be turned off with `robovm.xml` entry: ``` false ``` --- .../java/org/robovm/compiler/config/Config.java | 8 ++++---- .../org/robovm/compiler/config/SwiftSupport.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java b/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java index 76dbf3633..abc2f175f 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/config/Config.java @@ -157,7 +157,7 @@ public enum TreeShakerMode { @ElementList(required = false, entry = "path") private ArrayList appExtensionPaths; @Element(required = false) - private SwiftSupport swiftSupport = null; + private SwiftSupport swiftSupport = new SwiftSupport(); @ElementList(required = false, entry = "resource") private ArrayList resources; @ElementList(required = false, entry = "classpathentry") @@ -478,15 +478,15 @@ public List getAppExtensionPaths() { } public SwiftSupport getSwiftSupport() { - return swiftSupport; + return swiftSupport.isEnabled() ? swiftSupport : null; } public boolean hasSwiftSupport() { - return swiftSupport != null; + return swiftSupport.isEnabled(); } public List getSwiftLibPaths() { - return swiftSupport == null ? Collections.emptyList() + return !swiftSupport.isEnabled() ? Collections.emptyList() : swiftSupport.getSwiftLibPaths().stream() .filter(this::isQualified) .map(f -> f.entry) diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/config/SwiftSupport.java b/compiler/compiler/src/main/java/org/robovm/compiler/config/SwiftSupport.java index 75dca0cc2..abb827cc7 100644 --- a/compiler/compiler/src/main/java/org/robovm/compiler/config/SwiftSupport.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/config/SwiftSupport.java @@ -12,6 +12,12 @@ * Configuration entry for Swift language related configurations */ public class SwiftSupport { + /** + * specifies if swift support is enabled, allows to disable it if required + */ + @Element(required = false) + private boolean enable = true; + /** * path where swift library to be looked at * also these libraries will be added to linker library search path @@ -23,8 +29,12 @@ public class SwiftSupport { * specifies if swift runtime libraries to be copied */ @Element(required = false) - private Boolean copySwiftLibs = true; + private boolean copySwiftLibs = true; + + public boolean isEnabled() { + return enable; + } public List getSwiftLibPaths() { return swiftLibPaths == null ? Collections.emptyList() @@ -32,6 +42,6 @@ public List getSwiftLibPaths() { } public boolean shouldCopySwiftLibs() { - return copySwiftLibs != null ? copySwiftLibs : true; + return copySwiftLibs; } } From dc061431910310b7a843ea47d377ef37b5b1e9d5 Mon Sep 17 00:00:00 2001 From: dkimitsa Date: Sat, 16 Jul 2022 15:14:39 +0300 Subject: [PATCH 2/4] * fixed: in case of simulator build embedded frameworks/dylibs were stripped due wrong condition ## Root case its regression after M1 support: `.isArm()` doesn't mean device target anymore, to filter out simulator `environment` check to be done --- .../java/org/robovm/compiler/target/AbstractTarget.java | 6 +++--- .../main/java/org/robovm/compiler/util/ToolchainUtil.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/target/AbstractTarget.java b/compiler/compiler/src/main/java/org/robovm/compiler/target/AbstractTarget.java index 212bd4d33..877855c78 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/target/AbstractTarget.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/target/AbstractTarget.java @@ -366,7 +366,7 @@ public void processFile(Resource resource, File file, File destDir) throws IOExc if (isDynamicLibrary(file)) { // remove simulator and deprecated archs, also strip bitcode if not used - if (config.getOs() == OS.ios && config.getArch().isArm()) { + if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) { File libFile = new File(destDir, file.getName()); stripExtraArches(libFile); if (!config.isEnableBitcode()) @@ -440,7 +440,7 @@ public boolean processDir(Resource resource, File dir, File destDir) throws IOEx public void processFile(Resource resource, File file, File destDir) throws IOException { copyFile(resource, file, destDir); - if (config.getOs() == OS.ios && config.getArch().isArm()) { + if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) { // remove simulator and deprecated archs, also strip bitcode if not used if (isAppExtension(file)) { File libFile = new File(destDir, file.getName()); @@ -670,7 +670,7 @@ protected void copySwiftLibs(Collection swiftLibraries, File targetDir, // don't strip if libraries goes to SwiftSupport folder if (strip) { // remove simulator and deprecated archs, also strip bitcode if not used - if (config.getOs() == OS.ios && config.getArch().isArm()) { + if (config.getOs() == OS.ios && config.getArch().getEnv() != Environment.Simulator) { File libFile = new File(targetDir, swiftLibrary.getName()); stripExtraArches(libFile); if (!config.isEnableBitcode()) diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java b/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java index f4e44eab1..69a9ae61e 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/util/ToolchainUtil.java @@ -329,7 +329,7 @@ public static void lipoRemoveArchs(Config config, File inFile, File outFile, Str } args.add("-output"); args.add(outFile); - new Executor(Logger.NULL_LOGGER, getLipo()).args(args).exec(); + new Executor(config.getLogger(), getLipo()).args(args).exec(); } From 83eff4866745ce8bea447f2ff64c436ee47be366 Mon Sep 17 00:00:00 2001 From: dkimitsa Date: Sat, 16 Jul 2022 16:24:04 +0300 Subject: [PATCH 3/4] * fixed tests and added tests for `` --- .../robovm/compiler/config/ConfigTest.java | 35 ++++++++++++++++--- .../compiler/config/ConfigTest.console.xml | 4 +++ .../robovm/compiler/config/ConfigTest.ios.xml | 4 +++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/compiler/compiler/src/test/java/org/robovm/compiler/config/ConfigTest.java b/compiler/compiler/src/test/java/org/robovm/compiler/config/ConfigTest.java index 9b190c82b..4cc992dae 100755 --- a/compiler/compiler/src/test/java/org/robovm/compiler/config/ConfigTest.java +++ b/compiler/compiler/src/test/java/org/robovm/compiler/config/ConfigTest.java @@ -18,10 +18,7 @@ import static org.junit.Assert.*; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringWriter; +import java.io.*; import java.util.Arrays; import java.util.Collections; @@ -418,4 +415,34 @@ public void testGetFileName() throws Exception { assertEquals("com/example/AB9ca44297c0e0d22df654119dce73ee52d3d51c71.class.o", Config.getFileName("com/example/ABCDEFGIHJABCDEFGIHJABCDEFGIHJABCDEFGIHJABCDEFGIHJ", "class.o", 50)); } + + @Test + public void testSwiftSupportEnabledByDefault() throws Exception { + String configText = "\n" + + " ios\n" + + ""; + Config.Builder builder = new Config.Builder(); + + builder.read(new StringReader(configText), wd); + Config config = builder.config; + + assertTrue(config.hasSwiftSupport()); + assertNotNull(config.getSwiftSupport()); + assertTrue(config.getSwiftSupport().isEnabled()); + assertTrue(config.getSwiftSupport().shouldCopySwiftLibs()); + } + + @Test + public void testSwiftSupportCanBeDisabled() throws Exception { + String configText = "\n" + + " \n" + + " false\n" + + " \n" + + ""; + Config.Builder builder = new Config.Builder(); + builder.read(new StringReader(configText), wd); + Config config = builder.config; + assertFalse(config.hasSwiftSupport()); + assertNull(config.getSwiftSupport()); + } } diff --git a/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.console.xml b/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.console.xml index d2d815286..c05986389 100644 --- a/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.console.xml +++ b/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.console.xml @@ -15,6 +15,10 @@ Foundation AppKit + + true + true + resources /usr/share/resources diff --git a/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.ios.xml b/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.ios.xml index a481d9881..48fa38450 100644 --- a/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.ios.xml +++ b/compiler/compiler/src/test/resources/org/robovm/compiler/config/ConfigTest.ios.xml @@ -1,4 +1,8 @@ + + true + true + ios 6.1 Info.plist From 59e7e433dc385dbd9f09c3f989d4169657623749 Mon Sep 17 00:00:00 2001 From: dkimitsa Date: Sat, 16 Jul 2022 17:27:55 +0300 Subject: [PATCH 4/4] * fix: support for classes compiled with Java18 (JDK-8272564) when Java18 used as compiler JDK-8272564 changes will be applied this will affect invocation of java.lang.Object methods on interface receivers. as per changes invokevirtual is replaced with invokeinterface and these methods has to be resolved as per https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-5.html#jvms-5.4.3.4 item 3 in RoboVM case this means that final methods of "java.lang.Object" has to be available for lookup, thus changes added to include [lookup] wrappers for final methods in this case otherwise it will fail during linking with message(s): > Undefined symbols for architecture arm64:"[j]java.lang.Object.notifyAll()V[lookup]" --- .../java/org/robovm/compiler/ClassCompiler.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java b/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java index 0745bc76a..6390ce34d 100755 --- a/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java +++ b/compiler/compiler/src/main/java/org/robovm/compiler/ClassCompiler.java @@ -835,8 +835,17 @@ private void compile(Clazz clazz, OutputStream out) throws IOException { } // After this point no changes to methods/fields may be done by CompilerPlugins. - ci.initClassInfo(); - + ci.initClassInfo(); + + // when Java18 used as compiler JDK-8272564 changes will be applied this will affect invocation of + // java.lang.Object methods on interface receivers. + // as per changes invokevirtual is replaced with invokeinterface and these methods + // has to be resolved as per https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-5.html#jvms-5.4.3.4 item 3 + // in RoboVM case this means that final methods of "java.lang.Object" has to be available for lookup, + // thus changes added to include [lookup] wrappers for final methods in this case + // otherwise it will fail during linking with message(s): + // Undefined symbols for architecture arm64:"[j]java.lang.Object.notifyAll()V[lookup]" + boolean isJavaLangObject = sootClass.getName().equals("java.lang.Object"); for (SootMethod method : sootClass.getMethods()) { for (CompilerPlugin compilerPlugin : config.getCompilerPlugins()) { @@ -870,7 +879,7 @@ private void compile(Clazz clazz, OutputStream out) throws IOException { } if (!name.equals("") && !name.equals("") && !method.isPrivate() && !method.isStatic() - && !Modifier.isFinal(method.getModifiers()) + && (isJavaLangObject || !Modifier.isFinal(method.getModifiers())) && !Modifier.isFinal(sootClass.getModifiers())) { createLookupFunction(method);