Skip to content

Commit 891c2b4

Browse files
Kyle Berezintresf
authored andcommitted
Add darwin-aarch64 to build
1 parent 95ee1a3 commit 891c2b4

5 files changed

Lines changed: 195 additions & 145 deletions

File tree

build.xml

Lines changed: 117 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@
276276
<condition property="os.prefix" value="win32-${jre.arch}">
277277
<equals arg1="${build.os.family}" arg2="windows"/>
278278
</condition>
279-
<!-- Darwin builds are universal, no arch required -->
280-
<condition property="os.prefix" value="darwin">
279+
<condition property="os.prefix" value="darwin-${jre.arch}">
281280
<equals arg1="${build.os.family}" arg2="mac"/>
282281
</condition>
283282
<condition property="os.prefix" value="sunos-${jre.arch}">
@@ -295,6 +294,11 @@
295294
<condition property="os.prefix" value="kfreebsd-${jre.arch}">
296295
<equals arg1="${build.os.name}" arg2="GNU/kFreeBSD"/>
297296
</condition>
297+
<!-- Darwin's resource prefix lacks arch info, use "darwin" instead -->
298+
<condition property="resource.prefix" value="darwin">
299+
<matches string="${os.prefix}" pattern="^darwin-"/>
300+
</condition>
301+
<property name="resource.prefix" value="${os.prefix}" description="fallback"/>
298302
<fail unless="os.prefix" message="OS/arch not supported (${os.name}/${jre.arch}), edit build.xml and native/Makefile to add it."/>
299303
<!-- Keep all natives separate -->
300304
<property name="native.subdir" value="native-${os.prefix}"/>
@@ -316,6 +320,9 @@
316320
<condition property="ld.preload.name" value="LD_PRELOAD" else="IGNORE">
317321
<not><equals arg1="${libjsig}" arg2=""/></not>
318322
</condition>
323+
<condition property="native.jar" value="darwin.jar">
324+
<matches string="${os.prefix}" pattern="^darwin-"/>
325+
</condition>
319326
<property name="native.jar" value="${os.prefix}.jar"/>
320327
<property name="build.native" location="${build}/${native.subdir}"/>
321328
<property name="build.headers" location="${build}/headers"/>
@@ -521,7 +528,7 @@ com/sun/jna/openbsd-x86-64/libjnidispatch.so;
521528
processor=x86-64;osname=openbsd,
522529
523530
com/sun/jna/darwin/libjnidispatch.jnilib;
524-
osname=macosx;processor=x86;processor=x86-64;processor=ppc
531+
osname=macosx;processor=x86;processor=x86-64;processor=aarch64;processor=ppc
525532
"/>
526533
</manifest>
527534
<manifest file="@{target}" mode="update" if:true="@{module-info}">
@@ -873,6 +880,21 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
873880
</condition>
874881
<property name="make.OS" value="IGNORE="/>
875882
<!-- Ensure Makefile ARCH property properly set -->
883+
<condition property="ARCH" value="aarch64">
884+
<matches string="${os.prefix}" pattern="-aarch64$"/>
885+
</condition>
886+
<condition property="ARCH" value="x86-64">
887+
<matches string="${os.prefix}" pattern="-x86-64$"/>
888+
</condition>
889+
<condition property="ARCH" value="ppc">
890+
<matches string="${os.prefix}" pattern="-ppc$"/>
891+
</condition>
892+
<condition property="ARCH" value="ppc64">
893+
<matches string="${os.prefix}" pattern="-ppc64$"/>
894+
</condition>
895+
<condition property="ARCH" value="x86">
896+
<matches string="${os.prefix}" pattern="-x86$"/>
897+
</condition>
876898
<condition property="ARCH" value="arm">
877899
<equals arg1="${os.prefix}" arg2="w32ce-arm"/>
878900
</condition>
@@ -882,27 +904,12 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
882904
<condition property="ARCH" value="armv7">
883905
<equals arg1="${os.prefix}" arg2="android-armv7"/>
884906
</condition>
885-
<condition property="ARCH" value="aarch64">
886-
<matches string="${os.prefix}" pattern="-aarch64$"/>
887-
</condition>
888-
<condition property="ARCH" value="x86">
889-
<equals arg1="${os.prefix}" arg2="android-x86"/>
890-
</condition>
891-
<condition property="ARCH" value="x86-64">
892-
<equals arg1="${os.prefix}" arg2="android-x86-64"/>
893-
</condition>
894907
<condition property="ARCH" value="mips">
895908
<equals arg1="${os.prefix}" arg2="android-mips"/>
896909
</condition>
897910
<condition property="ARCH" value="mips64">
898911
<equals arg1="${os.prefix}" arg2="android-mips64"/>
899912
</condition>
900-
<condition property="ARCH" value="ppc">
901-
<equals arg1="${os.prefix}" arg2="aix-ppc"/>
902-
</condition>
903-
<condition property="ARCH" value="ppc64">
904-
<equals arg1="${os.prefix}" arg2="aix-ppc64"/>
905-
</condition>
906913
<!-- ensure ARCH is set properly for 64-bit capable platforms -->
907914
<!-- use ANT_OPTS=-d64/-d32 to build 64-bit/32-bit if not the platform default -->
908915
<property name="ARCH" value="${build.os.arch}"/>
@@ -918,49 +925,41 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
918925
<condition property="make.SDKROOT" value="SDKROOT=${SDKROOT}">
919926
<isset property="SDKROOT"/>
920927
</condition>
921-
<property name="xcode" value="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform"/>
922-
<condition property="make.SDKROOT"
923-
value="SDKROOT=${xcode}/Developer/SDKs/MacOSX10.11.sdk">
924-
<and>
925-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
926-
<available file="${xcode}/Developer/SDKs/MacOSX10.11.sdk"/>
927-
</and>
928-
</condition>
929-
<condition property="make.SDKROOT"
930-
value="SDKROOT=${xcode}/Developer/SDKs/MacOSX10.9.sdk">
931-
<and>
932-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
933-
<available file="${xcode}/Developer/SDKs/MacOSX10.9.sdk"/>
934-
</and>
935-
</condition>
936-
<condition property="make.SDKROOT"
937-
value="SDKROOT=${xcode}/Developer/SDKs/MacOSX10.8.sdk">
938-
<and>
939-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
940-
<available file="${xcode}/Developer/SDKs/MacOSX10.8.sdk"/>
941-
</and>
942-
</condition>
943-
<condition property="make.SDKROOT"
944-
value="SDKROOT=/Developer/SDKs/MacOSX10.6.sdk">
928+
<!-- If not manually provided, detect the SDKROOT in various locations:
929+
- Modern build environments ("MacOSX.sdk", no version):
930+
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
931+
932+
- macOS 10.8 and older:
933+
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX(version).sdk
934+
935+
- Prior versions:
936+
/Developer/SDKs/MacOSX(version).sdk
937+
-->
938+
<condition property="make.SDKROOT" value="SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk">
945939
<and>
946-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
947-
<available file="/Developer/SDKs/MacOSX10.6.sdk"/>
940+
<matches string="${os.prefix}" pattern="^darwin-"/>
941+
<available file="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"/>
948942
</and>
949943
</condition>
950-
<condition property="make.SDKROOT"
951-
value="SDKROOT=/Developer/SDKs/MacOSX10.5.sdk">
944+
<condition property="sdk-parent" value="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs">
952945
<and>
953-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
954-
<available file="/Developer/SDKs/MacOSX10.5.sdk"/>
946+
<matches string="${os.prefix}" pattern="^darwin-"/>
947+
<available file="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"/>
955948
</and>
956949
</condition>
957-
<condition property="make.SDKROOT"
958-
value="SDKROOT=/Developer/SDKs/MacOSX10.4u.sdk" else="IGNORE=">
950+
<condition property="sdk-parent" value="/Developer/SDKs">
959951
<and>
960-
<equals arg1="${os.prefix}" arg2="darwin" trim="true"/>
961-
<available file="/Developer/SDKs/MacOSX10.4u.sdk"/>
952+
<matches string="${os.prefix}" pattern="^darwin-"/>
953+
<available file="/Developer/SDKs"/>
962954
</and>
963955
</condition>
956+
<!-- Multiple SDKs is common; find the most recent (sort -V requires 10.12+) -->
957+
<exec executable="sh" dir="${sdk-parent}" outputproperty="sdk-latest" unless:set="make.SDKROOT">
958+
<arg value="-c"/>
959+
<arg line="&quot;ls -d MacOSX10.*.sdk | sort -t &quot;.&quot; -k2 -n | tail -1&quot;"/>
960+
</exec>
961+
<property name="make.SDKROOT" value="SDKROOT=${sdk-parent}/${sdk-latest}"/>
962+
964963
<!-- Windows' drive letters and spaces in absolute paths wreak havoc on
965964
make -->
966965
<condition property="make.BUILD" value="BUILD=../${build}/${native.subdir}" else="BUILD=${build.native}">
@@ -989,7 +988,7 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
989988
<isset property="EXTRA_MAKE_OPTS"/>
990989
</condition>
991990
<!-- Native resource path within jna.jar -->
992-
<property name="native.path" value="com/sun/jna/${os.prefix}"/>
991+
<property name="native.path" value="com/sun/jna/${resource.prefix}"/>
993992

994993
<!-- Default make program -->
995994
<property name="make" value="make"/>
@@ -1055,6 +1054,68 @@ cd ..
10551054
</zip>
10561055
</target>
10571056

1057+
<!--
1058+
Darwin prefers fat libraries. native/Makefile outputs a binary file for
1059+
one architecture. The binary is joined into a preexisting library pulled
1060+
from dist/darwin.jar using lipo.
1061+
1062+
If the preexisting library does not exist, or the library is thin and
1063+
only supports the target arch, the output binary will be renamed and
1064+
used in lieu of joining a fat lib.
1065+
-->
1066+
<macrodef name="darwin-lipo">
1067+
<sequential>
1068+
<available file="${dist}/${native.jar}" property="dist-available"/>
1069+
<unzip src="${dist}/${native.jar}" dest="${build.native}" if:true="${dist-available}">
1070+
<patternset>
1071+
<include name="libjnidispatch.jnilib"/>
1072+
</patternset>
1073+
</unzip>
1074+
<!--
1075+
Detect the arch that was just built.
1076+
Note, lipo -info will not exactly match that provided by ${ARCH}, this is OK
1077+
-->
1078+
<exec executable="lipo" dir="${build.native}" failonerror="true" outputproperty="lipo-info" if:true="${dist-available}">
1079+
<arg value="-info"/>
1080+
<arg value="libjnidispatch-${ARCH}.jnilib"/>
1081+
</exec>
1082+
<regexp id="lipo-regex" pattern="\b(\w+)$"/>
1083+
<loadresource property="lipo-arch" if:true="${dist-available}">
1084+
<propertyresource name="lipo-info"/>
1085+
<filterchain>
1086+
<tokenfilter>
1087+
<filetokenizer/>
1088+
<replaceregex pattern=".*\s" replace=""/>
1089+
</tokenfilter>
1090+
</filterchain>
1091+
</loadresource>
1092+
<!-- Use the detected arch to remove the old binary, and add the new binary to the fat library -->
1093+
<exec executable="lipo" dir="${build.native}" failonerror="false" if:true="${dist-available}">
1094+
<arg value="-remove"/>
1095+
<arg value="${lipo-arch}"/>
1096+
<arg value="libjnidispatch.jnilib"/>
1097+
<arg value="-output"/>
1098+
<arg value="libjnidispatch.jnilib"/>
1099+
</exec>
1100+
<exec executable="lipo" dir="${build.native}" failonerror="false" if:true="${dist-available}" resultproperty="lipo-result">
1101+
<arg value="-create"/>
1102+
<arg value="libjnidispatch.jnilib"/>
1103+
<arg value="libjnidispatch-${ARCH}.jnilib"/>
1104+
<arg value="-output"/>
1105+
<arg value="libjnidispatch.jnilib"/>
1106+
</exec>
1107+
<condition property="replace-lib" value="true">
1108+
<or>
1109+
<not>
1110+
<equals arg1="0" arg2="${lipo-result}"/>
1111+
</not>
1112+
<isfalse value="${dist-available}"/>
1113+
</or>
1114+
</condition>
1115+
<move file="${build.native}/libjnidispatch-${ARCH}.jnilib" tofile="${build.native}/libjnidispatch.jnilib" if:true="${replace-lib}" overwrite="true"/>
1116+
</sequential>
1117+
</macrodef>
1118+
10581119
<target name="native" depends="-enable-native,javah,-native-api-check,-prepare-native" unless="-native"
10591120
description="Build native libraries. Use 'ant -DCC=xxx' to build using a compiler other than gcc">
10601121
<exec executable="${make}" dir="${native}" failonerror="true">
@@ -1074,6 +1135,7 @@ cd ..
10741135
<arg value="JNA_JNI_VERSION=${jni.version}"/>
10751136
<arg value="CHECKSUM=${jni.md5}"/>
10761137
</exec>
1138+
<darwin-lipo if:set="make.SDKROOT"/>
10771139
<mkdir dir="${classes}/${native.path}"/>
10781140
<copy todir="${classes}/${native.path}">
10791141
<fileset dir="${build.native}"
@@ -1132,13 +1194,13 @@ cd ..
11321194
<exclude name="${tests.exclude}"/>
11331195
</javac>
11341196
<!-- Embed testlib-jar at root and at default resource path -->
1135-
<mkdir dir="${test.classes}/${os.prefix}"/>
1197+
<mkdir dir="${test.classes}/${resource.prefix}"/>
11361198
<copy todir="${test.classes}">
11371199
<fileset dir="${build.native}">
11381200
<include name="*testlib-jar*"/>
11391201
</fileset>
11401202
</copy>
1141-
<copy todir="${test.classes}/${os.prefix}">
1203+
<copy todir="${test.classes}/${resource.prefix}">
11421204
<fileset dir="${build.native}">
11431205
<include name="*testlib-jar*"/>
11441206
</fileset>

lib/native/darwin.jar

27.5 KB
Binary file not shown.

native/Makefile

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# Windows (x86/amd64/aarch64)
1313
# Windows CE/Mobile (arm)
14-
# Darwin/OS X (i386/x86_64/ppc)
14+
# Darwin/OS X (i386/x86-64/ppc/aarch64)
1515
# Linux (i386/amd64/ppc/arm)
1616
# Solaris (i386/amd64/sparc/sparcv9)
1717
# AIX (ppc/ppc64)
@@ -392,44 +392,56 @@ endif
392392

393393

394394
ifeq ($(OS),darwin)
395-
XCODE_VERSION=$(shell xcodebuild -version | grep Xcode | sed 's/^Xcode \([1-9]\).*/\1/g')
396-
JAVA_INCLUDES+=-I/System/Library/Frameworks/JavaVM.framework/Headers
397-
DEFAULT_ARCH=$(shell arch)
398-
ARCH=$(shell arch)
399-
HOST_CONFIG=--host $(ARCH)-apple-darwin
400-
FFI_ENV += CC="$(CC)" CFLAGS="-arch $(ARCH) $(ISYSROOT) $(COPT) $(CDEBUG)" CPPFLAGS="$(CDEFINES)" LD="$(LD) -arch $(ARCH)"
401-
ALT_ARCHS=
402-
ifneq ($(ARCH),i386)
403-
ALT_ARCHS+=i386
395+
396+
DARWIN_ARCH=$(ARCH)
397+
ifeq ($(ARCH),aarch64)
398+
DARWIN_ARCH=arm64
399+
else
400+
ifeq ($(ARCH),x86-64)
401+
DARWIN_ARCH=x86_64
402+
else
403+
ifeq ($(ARCH),x86)
404+
DARWIN_ARCH=x86
405+
else
404406
endif
405-
ifneq ($(ARCH),x86_64)
406-
ALT_ARCHS+=x86_64
407407
endif
408+
endif
409+
410+
XCODE_VERSION=$(shell xcodebuild -version | grep Xcode | sed 's/^Xcode \([1-9][0-9]*\).*/\1/g')
411+
MACOS_VERSION_MAJOR=$(shell sw_vers -productVersion | cut -d. -f 1)
412+
MACOS_VERSION_MINOR=$(shell sw_vers -productVersion | cut -d. -f 2)
413+
JAVA_INCLUDES+=-I/System/Library/Frameworks/JavaVM.framework/Headers
414+
DEFAULT_ARCH=$(shell arch)
415+
HOST_CONFIG=--host $(DARWIN_ARCH)-apple-darwin
416+
FFI_ENV += CC="$(CC)" CFLAGS="-arch $(DARWIN_ARCH) $(ISYSROOT) $(COPT) $(CDEBUG)" CPPFLAGS="$(CDEFINES)" LD="$(LD) -arch $(DARWIN_ARCH)"
417+
LIBSFX=.dylib
418+
JNISFX=-$(ARCH).jnilib
419+
# JAWT no longer supported on OSX
420+
CDEFINES+=-DTARGET_RT_MAC_CFM=0 -DFFI_MMAP_EXEC_WRIT -DNO_JAWT
421+
408422
ifneq ($(ARCH),ppc)
409-
ifeq ($(XCODE_VERSION),3)
410-
# Xcode 3 options
411-
# not supported on XCode 4+
412-
ALT_ARCHS+=ppc
413-
else
423+
ifneq ($(XCODE_VERSION),3)
414424
# Xcode 4+ options
415425
NO_COMPACT_UNWIND=-Wl,-no_compact_unwind
416426
endif
417427
endif
418-
LIBSFX=.dylib
419-
JNISFX=.jnilib
420428
ifneq ($(SDKROOT),)
421429
SYSLIBROOT=-Wl,-syslibroot,$(SDKROOT)
422430
ISYSROOT=-isysroot $(SDKROOT)
423-
ARCHFLAGS=-arch i386 -arch x86_64
424-
ifeq ($(XCODE_VERSION),3)
425-
ARCHFLAGS+=-arch ppc
426-
endif
431+
ARCHFLAGS+=-arch $(DARWIN_ARCH)
427432
endif
428433

429434
PCFLAGS+=$(ISYSROOT) -x objective-c
430-
# JAWT no longer supported on OSX
431-
CDEFINES+=-DTARGET_RT_MAC_CFM=0 -DFFI_MMAP_EXEC_WRIT -DNO_JAWT
432-
LDFLAGS=$(ARCHFLAGS) -dynamiclib -o $@ -framework JavaVM \
435+
436+
# MAJOR < 10 || (MAJOR = 10 && MINOR < 7)
437+
MACOS_LT_10_7 = $(shell [ ${MACOS_VERSION_MAJOR} -lt 10 -o ${MACOS_VERSION_MAJOR} -eq 10 -a ${MACOS_VERSION_MINOR} -lt 7 ] && echo true)
438+
439+
# JavaVM.framwork is "Deprecated in OS X v10.7."
440+
ifeq ($(MACOS_LT_10_7),true)
441+
FRAMEWORK=-framework JavaVM
442+
endif
443+
444+
LDFLAGS=$(ARCHFLAGS) -dynamiclib -o $@ $(FRAMEWORK) \
433445
-compatibility_version $(shell echo ${JNA_JNI_VERSION}|sed 's/^\([0-9][0-9]*\).*/\1/g') \
434446
-current_version $(JNA_JNI_VERSION) \
435447
-mmacosx-version-min=10.3 \
@@ -447,11 +459,7 @@ endif
447459
$(BUILD)/%.o : %.c dispatch.h protect.h $(FFI_LIB)
448460
@mkdir -p $(BUILD)
449461
ifneq ($(SDKROOT),)
450-
$(CC) $(LOC_CC_OPTS) -arch $(ARCH) $(CFLAGS) -c $< -o $@.$(ARCH)
451-
for arch in $(ALT_ARCHS); do \
452-
$(CC) $(LOC_CC_OPTS) -arch $$arch -I$(BUILD)/libffi.$$arch/include $(CFLAGS) -c $< -o $@.$$arch; \
453-
done
454-
lipo -create -output $@ $@.*
462+
$(CC) $(LOC_CC_OPTS) -arch $(DARWIN_ARCH) $(CFLAGS) -c $< -o $@
455463
else
456464
$(CC) $(CFLAGS) $(LOC_CC_OPTS) -c $< $(COUT)
457465
endif
@@ -507,25 +515,6 @@ $(FFI_LIB):
507515
&& $(FFI_ENV) $(FFI_SRC)/configure $(FFI_CONFIG) $(HOST_CONFIG)); \
508516
fi
509517
$(MAKE) -C $(FFI_BUILD)
510-
ifneq ($(SDKROOT),)
511-
@for arch in $(ALT_ARCHS); do \
512-
mkdir -p $(BUILD)/libffi.$$arch; \
513-
if [ ! -f $(BUILD)/libffi.$$arch/Makefile ]; then \
514-
echo "Configuring libffi ($$arch)"; \
515-
(cd $(BUILD)/libffi.$$arch \
516-
&& CC="$(CC)" CFLAGS="-arch $$arch $(ISYSROOT) $(COPT) $(CDEBUG)" CPPFLAGS="$(CDEFINES)" \
517-
LDFLAGS="-arch $$arch" \
518-
$(FFI_SRC)/configure $(FFI_CONFIG) --host=$$arch-apple-darwin --disable-dependency-tracking); \
519-
fi; \
520-
$(MAKE) -C $(BUILD)/libffi.$$arch; \
521-
done
522-
ifneq ($(ALT_ARCHS),)
523-
/usr/bin/libtool -static -o [email protected] $(FFI_BUILD)/.libs/${@F} $(BUILD)/libffi.*/.libs/${@F}
524-
else
525-
/usr/bin/libtool -static -o [email protected] $(FFI_BUILD)/.libs/${@F}
526-
endif
527-
528-
endif
529518
endif
530519

531520
clean:

0 commit comments

Comments
 (0)