diff --git a/CHANGES.md b/CHANGES.md
index 71eb416c13..a5904b37db 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@ Next Release (5.8.0)
Features
--------
+* [#1313](https://github.com/java-native-access/jna/issues/1313): Normalize `RESOURCE_PREFIX` for darwin to `darwin-$arch` and split jnidispatch library per architecture - [@matthiasblaesing](https://github.com/matthiasblaesing).
Bug Fixes
---------
@@ -20,6 +21,15 @@ Important Changes
the platform artifacts depend on the jna artifacts and need to pull in the
right variant. This is not possible if the classifier is used.
+* `RESOURCE_PREFIX` for darwin (mac OS) was changed from `darwin` to
+ `darwin-$arch` as the fat binaries on mac OS causes various problems:
+ It was reported, that binaries were rejected from the appstore because x86
+ binaries were found in the application (jnidispatch for mac OS x86) and that
+ builds needed to be special cased so that the native library can be
+ assembled. The latter is also true for JNA.
+ While the prefix is changed, the old prefix is still searched as a fallback
+ location, so if only a fat binary is present, it can still be loaded.
+
Release 5.7.0
=============
diff --git a/build.xml b/build.xml
index 9fde0aac5f..6180933522 100644
--- a/build.xml
+++ b/build.xml
@@ -38,6 +38,8 @@
+
+
@@ -311,13 +313,6 @@
-
-
-
-
-
-
-
@@ -340,9 +335,6 @@
-
-
-
@@ -542,13 +534,22 @@ com/sun/jna/freebsd-x86/libjnidispatch.so;
processor=x86;osname=freebsd,
com/sun/jna/freebsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=freebsd,
+
com/sun/jna/openbsd-x86/libjnidispatch.so;
processor=x86;osname=openbsd,
com/sun/jna/openbsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=openbsd,
-com/sun/jna/darwin/libjnidispatch.jnilib;
-osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
+com/sun/jna/darwin-ppc/libjnidispatch.jnilib;
+osname=macosx;processor=ppc,
+com/sun/jna/darwin-ppc64/libjnidispatch.jnilib;
+osname=macosx;processor=ppc64,
+com/sun/jna/darwin-x86/libjnidispatch.jnilib;
+osname=macosx;processor=x86,
+com/sun/jna/darwin-x86-64/libjnidispatch.jnilib;
+osname=macosx;processor=x86-64,
+com/sun/jna/darwin-aarch64/libjnidispatch.jnilib;
+osname=macosx;processor=aarch64
"/>
@@ -575,7 +576,6 @@ osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
-
@@ -590,9 +590,21 @@ osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
-
+ prefix="com/sun/jna/darwin-ppc"/>
+
+
+
+
@@ -814,7 +826,11 @@ osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
Invalidating native code, new checksum is ${md5}
-
+
+
+
+
+
@@ -903,7 +919,7 @@ osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
-
+
@@ -1091,68 +1107,6 @@ cd ..
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1172,7 +1126,6 @@ cd ..
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/native/darwin-aarch64.jar b/lib/native/darwin-aarch64.jar
new file mode 100644
index 0000000000..900049fde0
Binary files /dev/null and b/lib/native/darwin-aarch64.jar differ
diff --git a/lib/native/darwin-ppc.jar b/lib/native/darwin-ppc.jar
new file mode 100644
index 0000000000..6716399ab6
Binary files /dev/null and b/lib/native/darwin-ppc.jar differ
diff --git a/lib/native/darwin-ppc64.jar b/lib/native/darwin-ppc64.jar
new file mode 100644
index 0000000000..6716399ab6
Binary files /dev/null and b/lib/native/darwin-ppc64.jar differ
diff --git a/lib/native/darwin-x86-64.jar b/lib/native/darwin-x86-64.jar
new file mode 100644
index 0000000000..1d5619fbcb
Binary files /dev/null and b/lib/native/darwin-x86-64.jar differ
diff --git a/lib/native/darwin-x86.jar b/lib/native/darwin-x86.jar
new file mode 100644
index 0000000000..6716399ab6
Binary files /dev/null and b/lib/native/darwin-x86.jar differ
diff --git a/lib/native/darwin.jar b/lib/native/darwin.jar
deleted file mode 100644
index a1366fc388..0000000000
Binary files a/lib/native/darwin.jar and /dev/null differ
diff --git a/native/Makefile b/native/Makefile
index 05e5d26c1f..0c45a85d52 100644
--- a/native/Makefile
+++ b/native/Makefile
@@ -417,7 +417,7 @@ DEFAULT_ARCH=$(shell arch)
HOST_CONFIG=--host $(DARWIN_ARCH)-apple-darwin
FFI_ENV += CC="$(CC)" CFLAGS="-mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) -arch $(DARWIN_ARCH) $(ISYSROOT) $(COPT) $(CDEBUG)" CPPFLAGS="$(CDEFINES)" LD="$(LD) -arch $(DARWIN_ARCH)"
LIBSFX=.dylib
-JNISFX=-$(ARCH).jnilib
+JNISFX=.jnilib
# JAWT no longer supported on OSX
CDEFINES+=-DTARGET_RT_MAC_CFM=0 -DFFI_MMAP_EXEC_WRIT -DNO_JAWT
diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java
index fa32c89df9..c539b4f8cf 100644
--- a/src/com/sun/jna/Native.java
+++ b/src/com/sun/jna/Native.java
@@ -1084,9 +1084,32 @@ public static File extractFromResourcePath(String name, ClassLoader loader) thro
resourcePath = resourcePath.substring(1);
}
URL url = loader.getResource(resourcePath);
- if (url == null && resourcePath.startsWith(Platform.RESOURCE_PREFIX)) {
- // If not found with the standard resource prefix, try without it
- url = loader.getResource(libname);
+ if (url == null) {
+ if (resourcePath.startsWith(Platform.RESOURCE_PREFIX)) {
+ // Fallback for legacy darwin behaviour: darwin was in the past
+ // special cased in that all architectures were mapped to the same
+ // prefix and it was expected, that a fat binary was present at that
+ // point, that contained all architectures.
+ if(Platform.RESOURCE_PREFIX.startsWith("darwin")) {
+ url = loader.getResource("darwin/" + resourcePath.substring(Platform.RESOURCE_PREFIX.length() + 1));
+ }
+ if (url == null) {
+ // If not found with the standard resource prefix, try without it
+ url = loader.getResource(libname);
+ }
+ } else if (resourcePath.startsWith("com/sun/jna/" + Platform.RESOURCE_PREFIX + "/")) {
+ // Fallback for legacy darwin behaviour: darwin was in the past
+ // special cased in that all architectures were mapped to the same
+ // prefix and it was expected, that a fat binary was present at that
+ // point, that contained all architectures.
+ if(Platform.RESOURCE_PREFIX.startsWith("com/sun/jna/darwin")) {
+ url = loader.getResource("com/sun/jna/darwin" + resourcePath.substring(("com/sun/jna/" + Platform.RESOURCE_PREFIX).length() + 1));
+ }
+ if (url == null) {
+ // If not found with the standard resource prefix, try without it
+ url = loader.getResource(libname);
+ }
+ }
}
if (url == null) {
String path = System.getProperty("java.class.path");
@@ -1111,7 +1134,7 @@ public static File extractFromResourcePath(String name, ClassLoader loader) thro
}
}
else if (!Boolean.getBoolean("jna.nounpack")) {
- InputStream is = loader.getResourceAsStream(resourcePath);
+ InputStream is = url.openStream();
if (is == null) {
throw new IOException("Can't obtain InputStream for " + resourcePath);
}
diff --git a/src/com/sun/jna/Platform.java b/src/com/sun/jna/Platform.java
index 48618b4ec4..0af1ce05f7 100644
--- a/src/com/sun/jna/Platform.java
+++ b/src/com/sun/jna/Platform.java
@@ -313,7 +313,7 @@ static String getNativeLibraryResourcePrefix(int osType, String arch, String nam
osPrefix = "w32ce-" + arch;
break;
case Platform.MAC:
- osPrefix = "darwin";
+ osPrefix = "darwin-" + arch;
break;
case Platform.LINUX:
osPrefix = "linux-" + arch;
diff --git a/test/com/sun/jna/LibraryLoadTest.java b/test/com/sun/jna/LibraryLoadTest.java
index aa07a673a4..676e72a0be 100644
--- a/test/com/sun/jna/LibraryLoadTest.java
+++ b/test/com/sun/jna/LibraryLoadTest.java
@@ -100,7 +100,8 @@ public void testLoadFromClasspathAbsolute() throws MalformedURLException {
}
public void testLoadFromJar() throws MalformedURLException {
- NativeLibrary.getInstance("testlib-jar", new TestLoader(new File(TESTJAR)));
+ NativeLibrary.getInstance("testlib-jar", new TestLoader(new File(TESTJAR2)));
+ NativeLibrary.getInstance("testlib-jar", new TestLoader(new File(TESTJAR3)));
}
public void testLoadFromJarAbsolute() throws MalformedURLException {
diff --git a/test/com/sun/jna/Paths.java b/test/com/sun/jna/Paths.java
index f2a48ba542..40e6f6aab4 100644
--- a/test/com/sun/jna/Paths.java
+++ b/test/com/sun/jna/Paths.java
@@ -54,4 +54,6 @@ public CloverLoader(ClassLoader parent) throws MalformedURLException {
: System.getProperty("jna.nativedir",
BUILDDIR + "/native-" + Platform.RESOURCE_PREFIX + "/");
String TESTJAR = BUILDDIR + "/jna-test.jar";
+ String TESTJAR2 = BUILDDIR + "/jna-test2.jar";
+ String TESTJAR3 = BUILDDIR + "/jna-test3.jar";
}
diff --git a/test/com/sun/jna/PlatformTest.java b/test/com/sun/jna/PlatformTest.java
index b82679aa38..58b92551b3 100644
--- a/test/com/sun/jna/PlatformTest.java
+++ b/test/com/sun/jna/PlatformTest.java
@@ -38,16 +38,16 @@ public void testOSPrefix() {
assertEquals("Wrong resource path Windows CE/arm", "w32ce-arm",
Platform.getNativeLibraryResourcePrefix(Platform.WINDOWSCE,
"arm", "Windows CE"));
- assertEquals("Wrong resource path Mac/x86", "darwin",
+ assertEquals("Wrong resource path Mac/x86", "darwin-x86",
Platform.getNativeLibraryResourcePrefix(Platform.MAC,
"x86", "Darwin"));
- assertEquals("Wrong resource path Mac/x86", "darwin",
+ assertEquals("Wrong resource path Mac/x86", "darwin-x86",
Platform.getNativeLibraryResourcePrefix(Platform.MAC,
"i386", "Darwin"));
- assertEquals("Wrong resource path Mac/x86_64", "darwin",
+ assertEquals("Wrong resource path Mac/x86_64", "darwin-x86-64",
Platform.getNativeLibraryResourcePrefix(Platform.MAC,
"x86_64", "Mac"));
- assertEquals("Wrong resource path Mac/aarch64", "darwin",
+ assertEquals("Wrong resource path Mac/aarch64", "darwin-aarch64",
Platform.getNativeLibraryResourcePrefix(Platform.MAC,
"aarch64", "Mac"));
assertEquals("Wrong resource path Solaris/sparc", "sunos-sparc",