Skip to content

Commit

Permalink
build(native): build Mac arm64 with Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Aug 24, 2022
1 parent d5cbe62 commit 63c6c4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ all: jni-header package
deploy:
mvn package deploy -DperformRelease=true

DOCKER_RUN_OPTS=--rm
MVN:=mvn
CODESIGN:=docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir gotson/rcodesign sign
SRC:=src/main/java
SQLITE_OUT:=$(TARGET)/$(sqlite)-$(OS_NAME)-$(OS_ARCH)
SQLITE_OBJ?=$(SQLITE_OUT)/sqlite3.o
Expand Down Expand Up @@ -111,7 +113,7 @@ NATIVE_TARGET_DIR:=$(TARGET)/classes/org/sqlite/native/$(OS_NAME)/$(OS_ARCH)
NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)

# For cross-compilation, install docker. See also https://github.com/dockcross/dockcross
native-all: native win32 win64 win-armv7 win-arm64 mac64 linux32 linux64 freebsd32 freebsd64 freebsd-arm64 linux-arm linux-armv6 linux-armv7 linux-arm64 linux-android-arm linux-android-arm64 linux-android-x86 linux-android-x64 linux-ppc64 alpine-linux64 linux-musl-arm64
native-all: native win32 win64 win-armv7 win-arm64 mac64 mac-arm64-signed linux32 linux64 freebsd32 freebsd64 freebsd-arm64 linux-arm linux-armv6 linux-armv7 linux-arm64 linux-android-arm linux-android-arm64 linux-android-x86 linux-android-x64 linux-ppc64 alpine-linux64 linux-musl-arm64

native: $(NATIVE_DLL)

Expand All @@ -121,8 +123,6 @@ $(NATIVE_DLL): $(SQLITE_OUT)/$(LIBNAME)
@mkdir -p $(NATIVE_TARGET_DIR)
cp $< $(NATIVE_TARGET_DIR)/$(LIBNAME)

DOCKER_RUN_OPTS=--rm

win32: $(SQLITE_UNPACKED) jni-header
./docker/dockcross-windows-x86 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86'

Expand Down Expand Up @@ -186,13 +186,19 @@ linux-ppc64: $(SQLITE_UNPACKED) jni-header
mac64: $(SQLITE_UNPACKED) jni-header
docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86_64

mac-arm64: $(SQLITE_UNPACKED) jni-header
docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=aarch64-apple-darwin gotson/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=aarch64 CROSS_PREFIX="/usr/osxcross/bin/aarch64-apple-darwin20.4-"

# deprecated
mac32: $(SQLITE_UNPACKED) jni-header
docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=i386-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86

sparcv9:
$(MAKE) native OS_NAME=SunOS OS_ARCH=sparcv9

mac-arm64-signed: mac-arm64
$(CODESIGN) src/main/resources/org/sqlite/native/Mac/aarch64/libsqlitejdbc.jnilib

package: native-all
rm -rf target/dependency-maven-plugin-markers
$(MVN) package
Expand Down
13 changes: 6 additions & 7 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,12 @@ Mac-x86_64_LINKFLAGS := -dynamiclib
Mac-x86_64_LIBNAME := libsqlitejdbc.jnilib
Mac-x86_64_SQLITE_FLAGS :=

Mac-aarch64_CC := gcc -arch arm64
Mac-aarch64_STRIP := strip -x
MAC_SDK := /Developer/SDKs/MacOSX10.10.sdk
ifeq ($(wildcard MAC_SDK),)
MAC_SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
endif
Mac-aarch64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Ilib/inc_mac -Os -fPIC -mmacosx-version-min=10.6 -fvisibility=hidden -Wno-implicit-function-declaration
# Use a CROSS_PREFIX as the cross-triple clang is not available in crossbuild, see https://github.com/multiarch/crossbuild/blob/ad79cc84b6fb3fb1d09bc4a78719ef26f23bab85/Dockerfile#L134
# When running on a M1 mac, CROSS_PREFIX will be empty, and 'make native' can still build
Mac-aarch64_CC := $(CROSS_PREFIX)clang
Mac-aarch64_STRIP := $(CROSS_PREFIX)strip -x
MAC_SDK := /usr/osxcross/SDK/MacOSX11.3.sdk
Mac-aarch64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Ilib/inc_mac -Os -fPIC -mmacosx-version-min=10.9 -fvisibility=hidden -Wno-implicit-function-declaration
Mac-aarch64_LINKFLAGS := -dynamiclib
Mac-aarch64_LIBNAME := libsqlitejdbc.jnilib
Mac-aarch64_SQLITE_FLAGS :=
Expand Down

0 comments on commit 63c6c4a

Please sign in to comment.