mirror of https://github.com/status-im/xgo.git
Support assembling Android .aar archives
This commit is contained in:
parent
fe103ea160
commit
72ebb6b456
|
@ -30,8 +30,8 @@ RUN \
|
|||
gcc-5-arm-linux-gnueabihf g++-5-arm-linux-gnueabihf libc6-dev-armhf-cross \
|
||||
gcc-5-aarch64-linux-gnu g++-5-aarch64-linux-gnu libc6-dev-arm64-cross \
|
||||
gcc-5-multilib g++-5-multilib gcc-mingw-w64 g++-mingw-w64 clang-3.7 llvm-dev \
|
||||
libtool libxml2-dev uuid-dev libssl-dev pkg-config patch make xz-utils \
|
||||
cpio wget unzip p7zip git mercurial bzr --no-install-recommends
|
||||
libtool libxml2-dev uuid-dev libssl-dev swig openjdk-7-jdk pkg-config patch \
|
||||
make xz-utils cpio wget zip unzip p7zip git mercurial bzr --no-install-recommends
|
||||
|
||||
# Fix any stock package issues
|
||||
RUN \
|
||||
|
@ -58,26 +58,6 @@ RUN \
|
|||
|
||||
ENV PATH $OSX_NDK_X86/bin:$PATH
|
||||
|
||||
# Configure the container for Android cross compilation
|
||||
ENV ANDROID_NDK android-ndk-r10e
|
||||
ENV ANDROID_NDK_PATH http://dl.google.com/android/ndk/$ANDROID_NDK-linux-x86_64.bin
|
||||
ENV ANDROID_NDK_ROOT /usr/local/$ANDROID_NDK
|
||||
ENV ANDROID_PLATFORM 21
|
||||
ENV ANDROID_CHAIN_ARM arm-linux-androideabi-4.9
|
||||
|
||||
RUN \
|
||||
$FETCH $ANDROID_NDK_PATH c685e5f106f8daa9b5449d0a4f21ee8c0afcb2f6 && \
|
||||
7zr x `basename $ANDROID_NDK_PATH` \
|
||||
"$ANDROID_NDK/build" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/include" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi*" \
|
||||
"$ANDROID_NDK/prebuilt/linux-x86_64" \
|
||||
"$ANDROID_NDK/platforms/*/arch-arm" \
|
||||
"$ANDROID_NDK/toolchains/$ANDROID_CHAIN_ARM" -o/usr/local > /dev/null && \
|
||||
rm -f `basename $ANDROID_NDK_PATH`
|
||||
|
||||
ENV PATH /usr/$ANDROID_CHAIN_ARM/bin:$PATH
|
||||
|
||||
# Configure the container for iOS cross compilation
|
||||
ENV IOS_NDK_ARM_7 /usr/local/ios-ndk-arm-7
|
||||
ENV IOS_NDK_ARM64 /usr/local/ios-ndk-arm64
|
||||
|
@ -94,6 +74,37 @@ RUN \
|
|||
$UPDATE_IOS /iPhoneOS8.1.sdk.tar.bz2 && \
|
||||
rm -rf /iPhoneOS8.1.sdk.tar.bz2
|
||||
|
||||
# Configure the container for Android cross compilation
|
||||
ENV ANDROID_NDK android-ndk-r10e
|
||||
ENV ANDROID_NDK_PATH http://dl.google.com/android/ndk/$ANDROID_NDK-linux-x86_64.bin
|
||||
ENV ANDROID_NDK_ROOT /usr/local/$ANDROID_NDK
|
||||
ENV ANDROID_NDK_LIBC $ANDROID_NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9
|
||||
ENV ANDROID_PLATFORM 21
|
||||
ENV ANDROID_CHAIN_ARM arm-linux-androideabi-4.9
|
||||
ENV ANDROID_CHAIN_ARM64 aarch64-linux-android-4.9
|
||||
ENV ANDROID_CHAIN_386 x86-4.9
|
||||
|
||||
RUN \
|
||||
$FETCH $ANDROID_NDK_PATH c685e5f106f8daa9b5449d0a4f21ee8c0afcb2f6 && \
|
||||
7zr x `basename $ANDROID_NDK_PATH` \
|
||||
"$ANDROID_NDK/build" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/include" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi*" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64*" \
|
||||
"$ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86" \
|
||||
"$ANDROID_NDK/prebuilt/linux-x86_64" \
|
||||
"$ANDROID_NDK/platforms/*/arch-arm" \
|
||||
"$ANDROID_NDK/platforms/*/arch-arm64" \
|
||||
"$ANDROID_NDK/platforms/*/arch-x86" \
|
||||
"$ANDROID_NDK/toolchains/$ANDROID_CHAIN_ARM" \
|
||||
"$ANDROID_NDK/toolchains/$ANDROID_CHAIN_ARM64" \
|
||||
"$ANDROID_NDK/toolchains/$ANDROID_CHAIN_386" -o/usr/local > /dev/null && \
|
||||
rm -f `basename $ANDROID_NDK_PATH`
|
||||
|
||||
ENV PATH /usr/$ANDROID_CHAIN_ARM/bin:$PATH
|
||||
ENV PATH /usr/$ANDROID_CHAIN_ARM64/bin:$PATH
|
||||
ENV PATH /usr/$ANDROID_CHAIN_386/bin:$PATH
|
||||
|
||||
# Inject the old Go package downloader and tool-chain bootstrapper
|
||||
ADD bootstrap.sh /bootstrap.sh
|
||||
ENV BOOTSTRAP /bootstrap.sh
|
||||
|
@ -120,3 +131,6 @@ ENV BUILD /build.sh
|
|||
RUN chmod +x $BUILD
|
||||
|
||||
ENTRYPOINT ["/build.sh"]
|
||||
|
||||
# Temporary injects to fix possible Go bugs
|
||||
ADD android_arm64.patch /android_arm64.patch
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
From 844d3e17e89af37ce4b851b73e4c2a903f8dcfd4 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= <peterke@gmail.com>
|
||||
Date: Sun, 13 Dec 2015 21:04:06 +0200
|
||||
Subject: [PATCH] runtime: init argc/argv for android/arm64 c-shared
|
||||
|
||||
Analogous to https://go-review.googlesource.com/#/c/8457/ this
|
||||
code synthesizes an set of program arguments for Android on the
|
||||
arm64 architecture.
|
||||
|
||||
Change-Id: I851958b4b0944ec79d7a1426a3bb2cfc31746797
|
||||
---
|
||||
src/runtime/rt0_android_arm64.s | 19 +++++++++++++++++++
|
||||
1 file changed, 19 insertions(+)
|
||||
|
||||
diff --git a/src/runtime/rt0_android_arm64.s b/src/runtime/rt0_android_arm64.s
|
||||
index 7291476..5341a25 100644
|
||||
--- a/src/runtime/rt0_android_arm64.s
|
||||
+++ b/src/runtime/rt0_android_arm64.s
|
||||
@@ -8,6 +8,25 @@ TEXT _rt0_arm64_android(SB),NOSPLIT,$-8
|
||||
MOVD $_rt0_arm64_linux(SB), R4
|
||||
B (R4)
|
||||
|
||||
+// When building with -buildmode=c-shared, this symbol is called when the shared
|
||||
+// library is loaded.
|
||||
TEXT _rt0_arm64_android_lib(SB),NOSPLIT,$-8
|
||||
+ MOVW $1, R0 // argc
|
||||
+ MOVD $_rt0_arm64_android_argv(SB), R1 // **argv
|
||||
MOVD $_rt0_arm64_linux_lib(SB), R4
|
||||
B (R4)
|
||||
+
|
||||
+DATA _rt0_arm64_android_argv+0x00(SB)/8,$_rt0_arm64_android_argv0(SB)
|
||||
+DATA _rt0_arm64_android_argv+0x08(SB)/8,$0
|
||||
+DATA _rt0_arm64_android_argv+0x10(SB)/8,$0
|
||||
+DATA _rt0_arm64_android_argv+0x18(SB)/8,$15 // AT_PLATFORM
|
||||
+DATA _rt0_arm64_android_argv+0x20(SB)/8,$_rt0_arm64_android_auxv0(SB)
|
||||
+DATA _rt0_arm64_android_argv+0x28(SB)/8,$16 // AT_HWCAP
|
||||
+DATA _rt0_arm64_android_argv+0x30(SB)/8,$0
|
||||
+GLOBL _rt0_arm64_android_argv(SB),NOPTR,$0x38
|
||||
+
|
||||
+DATA _rt0_arm64_android_argv0(SB)/8, $"gojni"
|
||||
+GLOBL _rt0_arm64_android_argv0(SB),RODATA,$8
|
||||
+
|
||||
+DATA _rt0_arm64_android_auxv0(SB)/8, $"v8a"
|
||||
+GLOBL _rt0_arm64_android_auxv0(SB),RODATA,$8
|
||||
--
|
||||
2.5.0
|
||||
|
|
@ -10,10 +10,6 @@
|
|||
# FETCH - Remote file fetcher and checksum verifier (injected by image)
|
||||
set -e
|
||||
|
||||
# Prepare the image for manual Go compilation
|
||||
apt-get install -y netbase --no-install-recommends # Needed for `net` tests
|
||||
apt-get remove -y clang # Broken thread sanitizer
|
||||
|
||||
# Define the paths to deploy the bootstrapper and the final distribution
|
||||
export GOROOT=/usr/local/go
|
||||
export GOROOT_BOOTSTRAP=${GOROOT}-boot
|
||||
|
@ -31,13 +27,10 @@ mv $GOROOT $GOROOT_BOOTSTRAP
|
|||
# Download, build and install the requesed Go sources
|
||||
(cd /usr/local && git clone https://go.googlesource.com/go)
|
||||
(cd $GOROOT && git checkout $1)
|
||||
(cd $GOROOT/src && ./all.bash)
|
||||
(cd $GOROOT && if [ "$1" == "master" ]; then git apply /android_arm64.patch; fi)
|
||||
(cd $GOROOT/src && ./make.bash)
|
||||
|
||||
rm -rf $GOROOT_BOOTSTRAP && \
|
||||
export GOROOT_BOOTSTRAP=$GOROOT && \
|
||||
|
||||
# Restore the original image and bootstrap Go
|
||||
apt-get install -y clang --no-install-recommends
|
||||
apt-get remove -y netbase
|
||||
rm -rf $GOROOT_BOOTSTRAP
|
||||
export GOROOT_BOOTSTRAP=$GOROOT
|
||||
|
||||
$BOOTSTRAP_PURE
|
||||
|
|
|
@ -159,12 +159,16 @@ for TARGET in $TARGETS; do
|
|||
if [ "$PLATFORM" -ge 16 ]; then
|
||||
CGO_CCPIE="-fPIE"
|
||||
CGO_LDPIE="-fPIE"
|
||||
EXT_LDPIE="-extldflags=-pie -extldflags=-Wl,--allow-multiple-definition"
|
||||
EXT_LDPIE="-extldflags=-pie"
|
||||
else
|
||||
unset CGO_CCPIE CGO_LDPIE EXT_LDPIE
|
||||
fi
|
||||
# Iterate over the requested architectures, bootstrap and
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm" ]; then
|
||||
EXT_LDAMD="-extldflags=-Wl,--allow-multiple-definition"
|
||||
|
||||
mkdir -p /build-android-aar
|
||||
|
||||
# Iterate over the requested architectures, bootstrap and build
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm" ] || [ $XGOARCH == "aar" ]; then
|
||||
if [ "$GO_VERSION" -lt 150 ]; then
|
||||
echo "Go version too low, skipping android-$PLATFORM/arm..."
|
||||
else
|
||||
|
@ -176,16 +180,109 @@ for TARGET in $TARGETS; do
|
|||
|
||||
echo "Compiling for android-$PLATFORM/arm..."
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ HOST=arm-linux-androideabi PREFIX=/usr/$ANDROID_CHAIN_ARM/arm-linux-androideabi $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go build $V $X "${T[@]}" --ldflags="$V $EXT_LDPIE $LD" $BM -o "/build/$NAME-android-$PLATFORM-arm`extension android`" ./$PACK
|
||||
|
||||
echo "Cleaning up Go runtime for android-$PLATFORM/arm..."
|
||||
rm -rf /usr/local/go/pkg/android_arm
|
||||
|
||||
echo "Cleaning up toolchain for android-$PLATFORM/arm..."
|
||||
rm -rf /usr/$ANDROID_CHAIN_ARM
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm" ]; then
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go build $V $X "${T[@]}" --ldflags="$V $EXT_LDPIE $LD" $BM -o "/build/$NAME-android-$PLATFORM-arm`extension android`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "aar" ]; then
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-linux-androideabi-gcc CXX=arm-linux-androideabi-g++ GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="$V $EXT_LDAMD $LD" --buildmode=c-shared -o "/build-android-aar/$NAME-android-$PLATFORM-arm.so" ./$PACK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ "$GO_VERSION" -lt 160 ]; then
|
||||
echo "Go version too low, skipping android-$PLATFORM/386,arm64..."
|
||||
else
|
||||
if [ "$PLATFORM" -ge 9 ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "386" ] || [ $XGOARCH == "aar" ]); then
|
||||
echo "Assembling toolchain for android-$PLATFORM/386..."
|
||||
$ANDROID_NDK_ROOT/build/tools/make-standalone-toolchain.sh --ndk-dir=$ANDROID_NDK_ROOT --install-dir=/usr/$ANDROID_CHAIN_386 --toolchain=$ANDROID_CHAIN_386 --arch=x86 --system=linux-x86_64 > /dev/null 2>&1
|
||||
|
||||
echo "Bootstrapping android-$PLATFORM/386..."
|
||||
CC=i686-linux-android-gcc GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go install std
|
||||
|
||||
echo "Compiling for android-$PLATFORM/386..."
|
||||
CC=i686-linux-android-gcc CXX=i686-linux-android-g++ HOST=i686-linux-android PREFIX=/usr/$ANDROID_CHAIN_386/i686-linux-android $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "386" ]; then
|
||||
CC=i686-linux-android-gcc CXX=i686-linux-android-g++ GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=i686-linux-android-gcc CXX=i686-linux-android-g++ GOOS=android GOARCH=386 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go build $V $X "${T[@]}" --ldflags="$V $EXT_LDPIE $EXT_LDAMD $LD" $BM -o "/build/$NAME-android-$PLATFORM-386`extension android`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "aar" ]; then
|
||||
CC=i686-linux-android-gcc CXX=i686-linux-android-g++ GOOS=android GOARCH=386 CGO_ENABLED=1 go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=i686-linux-android-gcc CXX=i686-linux-android-g++ GOOS=android GOARCH=386 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="$V $EXT_LDAMD $LD" --buildmode=c-shared -o "/build-android-aar/$NAME-android-$PLATFORM-386.so" ./$PACK
|
||||
fi
|
||||
fi
|
||||
if [ "$PLATFORM" -ge 21 ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm64" ] || [ $XGOARCH == "aar" ]); then
|
||||
echo "Assembling toolchain for android-$PLATFORM/arm64..."
|
||||
$ANDROID_NDK_ROOT/build/tools/make-standalone-toolchain.sh --ndk-dir=$ANDROID_NDK_ROOT --install-dir=/usr/$ANDROID_CHAIN_ARM64 --toolchain=$ANDROID_CHAIN_ARM64 --arch=arm64 --system=linux-x86_64 > /dev/null 2>&1
|
||||
|
||||
echo "Bootstrapping android-$PLATFORM/arm64..."
|
||||
CC=aarch64-linux-android-gcc GOOS=android GOARCH=arm64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go install std
|
||||
|
||||
echo "Compiling for android-$PLATFORM/arm64..."
|
||||
CC=aarch64-linux-android-gcc CXX=aarch64-linux-android-g++ HOST=aarch64-linux-android PREFIX=/usr/$ANDROID_CHAIN_ARM64/aarch64-linux-android $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm64" ]; then
|
||||
CC=aarch64-linux-android-gcc CXX=aarch64-linux-android-g++ GOOS=android GOARCH=arm64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=aarch64-linux-android-gcc CXX=aarch64-linux-android-g++ GOOS=android GOARCH=arm64 CGO_ENABLED=1 CGO_CFLAGS="$CGO_CCPIE" CGO_CXXFLAGS="$CGO_CCPIE" CGO_LDFLAGS="$CGO_LDPIE" go build $V $X "${T[@]}" --ldflags="$V $EXT_LDPIE $EXT_LDAMD $LD" $BM -o "/build/$NAME-android-$PLATFORM-arm64`extension android`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "aar" ]; then
|
||||
CC=aarch64-linux-android-gcc CXX=aarch64-linux-android-g++ GOOS=android GOARCH=arm64 CGO_ENABLED=1 go get $V $X "${T[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=aarch64-linux-android-gcc CXX=aarch64-linux-android-g++ GOOS=android GOARCH=arm64 CGO_ENABLED=1 go build $V $X "${T[@]}" --ldflags="$V $EXT_LDAMD $LD" --buildmode=c-shared -o "/build-android-aar/$NAME-android-$PLATFORM-arm64.so" ./$PACK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# Assemble the Android Archive from the built shared libraries
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "aar" ]; then
|
||||
title=${NAME^}
|
||||
archive=/build/$NAME-android-$PLATFORM-aar
|
||||
bundle=/build/$NAME-android-$PLATFORM.aar
|
||||
|
||||
# Generate the Java import path based on the Go one
|
||||
package=`go list ./$PACK | tr '-' '_'`
|
||||
package=$(for p in `echo ${package//\// }`; do echo $p | awk 'BEGIN{FS="."}{for (i=NF; i>0; i--){printf "%s.", $i;}}'; done | sed 's/.$//')
|
||||
package=${package%.*}
|
||||
|
||||
# Create a fresh empty Android archive
|
||||
rm -rf $archive $bundle
|
||||
mkdir -p $archive
|
||||
|
||||
echo -e "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"$package\">\n <uses-sdk android:minSdkVersion=\"$PLATFORM\"/>\n</manifest>" > $archive/AndroidManifest.xml
|
||||
mkdir -p $archive/res
|
||||
touch $archive/R.txt
|
||||
|
||||
# Generate the JNI wrappers automatically with SWIG
|
||||
jni=`mktemp -d`
|
||||
cp `find /build-android-aar | grep '\.h$' | head -n 1` $jni/$NAME.h
|
||||
sed -i -e 's|__complex|complex|g' $jni/$NAME.h
|
||||
echo -e "%module $title\n%{\n#include \"$NAME.h\"\n%}\n%pragma(java) jniclasscode=%{\nstatic {\nSystem.loadLibrary(\"$NAME\");\n}\n%}\n%include \"$NAME.h\"" > $jni/$NAME.i
|
||||
|
||||
mkdir -p $jni/${package//.//}
|
||||
swig -java -package $package -outdir $jni/${package//.//} $jni/$NAME.i
|
||||
|
||||
# Assemble the Go static libraries and the JNI interface into shared libraries
|
||||
for lib in `find /build-android-aar | grep '\.so$'`; do
|
||||
if [[ "$lib" = *-arm.so ]]; then cc=arm-linux-androideabi-gcc; abi="armeabi-v7a"; fi
|
||||
if [[ "$lib" = *-arm64.so ]]; then cc=aarch64-linux-android-gcc; abi="arm64-v8a"; fi
|
||||
if [[ "$lib" = *-386.so ]]; then cc=i686-linux-android-gcc; abi="x86"; fi
|
||||
|
||||
mkdir -p $archive/jni/$abi
|
||||
cp ${lib%.*}.h $jni/${NAME}.h
|
||||
cp $lib $archive/jni/$abi/lib${NAME}raw.so
|
||||
(cd $archive/jni/$abi && $cc -shared -fPIC -o lib${NAME}.so -I"$ANDROID_NDK_LIBC/include" -I"$ANDROID_NDK_LIBC/libs/$abi/include" -I"$jni" lib${NAME}raw.so $jni/${NAME}_wrap.c)
|
||||
done
|
||||
|
||||
# Compile the Java wrapper and assemble into a .jar file
|
||||
mkdir -p $jni/build
|
||||
javac -cp . -d $jni/build $jni/${package//.//}/*.java
|
||||
(cd $jni/build && jar cvf $archive/classes.jar *)
|
||||
|
||||
# Finally assemble the archive contents into an .aar and clean up
|
||||
(cd $archive && zip -r $bundle *)
|
||||
rm -rf $jni $archive
|
||||
fi
|
||||
# Clean up the android builds, toolchains and runtimes
|
||||
rm -rf /build-android-aar
|
||||
rm -rf /usr/local/go/pkg/android_*
|
||||
rm -rf /usr/$ANDROID_CHAIN_ARM /usr/$ANDROID_CHAIN_ARM64 /usr/$ANDROID_CHAIN_386
|
||||
fi
|
||||
# Check and build for Linux targets
|
||||
if ([ $XGOOS == "." ] || [ $XGOOS == "linux" ]) && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]); then
|
||||
|
@ -333,10 +430,15 @@ for TARGET in $TARGETS; do
|
|||
else
|
||||
IOSTAGS=(--tags ios)
|
||||
fi
|
||||
mkdir -p /build-ios
|
||||
mkdir -p /build-ios-fw
|
||||
|
||||
# Strip symbol table below Go 1.6 to prevent DWARF issues
|
||||
LDSTRIP=""
|
||||
if [ "$GO_VERSION" -lt 160 ]; then
|
||||
LDSTRIP="-s"
|
||||
fi
|
||||
# Cross compile to all available iOS and simulator platforms
|
||||
if [ -d "$IOS_NDK_ARM_7" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm" ] || [ $XGOARCH == "arm-7" ]); then
|
||||
if [ -d "$IOS_NDK_ARM_7" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm-7" ] || [ $XGOARCH == "framework" ]); then
|
||||
echo "Bootstrapping ios-$PLATFORM/arm-7..."
|
||||
export PATH=$IOS_NDK_ARM_7/bin:$PATH
|
||||
GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-apple-darwin11-clang go install --tags ios std
|
||||
|
@ -344,12 +446,16 @@ for TARGET in $TARGETS; do
|
|||
echo "Compiling for ios-$PLATFORM/arm-7..."
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ HOST=arm-apple-darwin11 PREFIX=/usr/local $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1 go get $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios/$NAME-ios-$PLATFORM-armv7.a" ./$PACK
|
||||
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm-7" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$LDSTRIP $V $LD" $BM -o "/build/$NAME-ios-$PLATFORM-armv7`extension darwin`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "framework" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm GOARM=7 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios-fw/$NAME-ios-$PLATFORM-armv7.a" ./$PACK
|
||||
fi
|
||||
echo "Cleaning up Go runtime for ios-$PLATFORM/arm-7..."
|
||||
rm -rf /usr/local/go/pkg/darwin_arm
|
||||
fi
|
||||
if [ -d "$IOS_NDK_ARM64" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm" ] || [ $XGOARCH == "arm64" ]); then
|
||||
if [ -d "$IOS_NDK_ARM64" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "arm64" ] || [ $XGOARCH == "framework" ]); then
|
||||
echo "Bootstrapping ios-$PLATFORM/arm64..."
|
||||
export PATH=$IOS_NDK_ARM64/bin:$PATH
|
||||
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 CC=arm-apple-darwin11-clang go install --tags ios std
|
||||
|
@ -357,12 +463,16 @@ for TARGET in $TARGETS; do
|
|||
echo "Compiling for ios-$PLATFORM/arm64..."
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ HOST=arm-apple-darwin11 PREFIX=/usr/local $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go get $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios/$NAME-ios-$PLATFORM-arm64.a" ./$PACK
|
||||
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "arm64" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$LDSTRIP $V $LD" $BM -o "/build/$NAME-ios-$PLATFORM-arm64`extension darwin`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "framework" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios-fw/$NAME-ios-$PLATFORM-arm64.a" ./$PACK
|
||||
fi
|
||||
echo "Cleaning up Go runtime for ios-$PLATFORM/arm64..."
|
||||
rm -rf /usr/local/go/pkg/darwin_arm64
|
||||
fi
|
||||
if [ -d "$IOS_SIM_NDK_AMD64" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]); then
|
||||
if [ -d "$IOS_SIM_NDK_AMD64" ] && ([ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ] || [ $XGOARCH == "framework" ]); then
|
||||
echo "Bootstrapping ios-$PLATFORM/amd64..."
|
||||
export PATH=$IOS_SIM_NDK_AMD64/bin:$PATH
|
||||
mv /usr/local/go/pkg/darwin_amd64 /usr/local/go/pkg/darwin_amd64_bak
|
||||
|
@ -371,44 +481,50 @@ for TARGET in $TARGETS; do
|
|||
echo "Compiling for ios-$PLATFORM/amd64..."
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ HOST=arm-apple-darwin11 PREFIX=/usr/local $BUILD_DEPS /deps ${DEPS_ARGS[@]}
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go get $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" -d ./$PACK
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios/$NAME-ios-$PLATFORM-x86_64.a" ./$PACK
|
||||
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "amd64" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$LDSTRIP $V $LD" $BM -o "/build/$NAME-ios-$PLATFORM-x86_64`extension darwin`" ./$PACK
|
||||
fi
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "framework" ]; then
|
||||
CC=arm-apple-darwin11-clang CXX=arm-apple-darwin11-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $V $X "${IOSTAGS[@]}" --ldflags="$V $LD" --buildmode=c-archive -o "/build-ios-fw/$NAME-ios-$PLATFORM-x86_64.a" ./$PACK
|
||||
fi
|
||||
echo "Cleaning up Go runtime for ios-$PLATFORM/amd64..."
|
||||
rm -rf /usr/local/go/pkg/darwin_amd64
|
||||
mv /usr/local/go/pkg/darwin_amd64_bak /usr/local/go/pkg/darwin_amd64
|
||||
fi
|
||||
# Assemble the iOS framework from the built binaries
|
||||
title=${NAME^}
|
||||
framework=/build/$NAME-ios-$PLATFORM/$title.framework
|
||||
if [ $XGOARCH == "." ] || [ $XGOARCH == "framework" ]; then
|
||||
title=${NAME^}
|
||||
framework=/build/$NAME-ios-$PLATFORM-framework/$title.framework
|
||||
|
||||
rm -rf $framework
|
||||
mkdir -p $framework/Versions/A
|
||||
(cd $framework/Versions && ln -nsf A Current)
|
||||
rm -rf $framework
|
||||
mkdir -p $framework/Versions/A
|
||||
(cd $framework/Versions && ln -nsf A Current)
|
||||
|
||||
arches=()
|
||||
for lib in `ls /build-ios | grep -e '\.a$'`; do
|
||||
arches+=("-arch" "`echo ${lib##*-} | cut -d '.' -f 1`" "/build-ios/$lib")
|
||||
done
|
||||
arm-apple-darwin11-lipo -create "${arches[@]}" -o $framework/Versions/A/$title
|
||||
arm-apple-darwin11-ranlib $framework/Versions/A/$title
|
||||
(cd $framework && ln -nsf Versions/A/$title $title)
|
||||
arches=()
|
||||
for lib in `ls /build-ios-fw | grep -e '\.a$'`; do
|
||||
arches+=("-arch" "`echo ${lib##*-} | cut -d '.' -f 1`" "/build-ios-fw/$lib")
|
||||
done
|
||||
arm-apple-darwin11-lipo -create "${arches[@]}" -o $framework/Versions/A/$title
|
||||
arm-apple-darwin11-ranlib $framework/Versions/A/$title
|
||||
(cd $framework && ln -nsf Versions/A/$title $title)
|
||||
|
||||
mkdir -p $framework/Versions/A/Headers
|
||||
for header in `ls /build-ios | grep -e '\.h$'`; do
|
||||
cp -f /build-ios/$header $framework/Versions/A/Headers/$title.h
|
||||
done
|
||||
(cd $framework && ln -nsf Versions/A/Headers Headers)
|
||||
mkdir -p $framework/Versions/A/Headers
|
||||
for header in `ls /build-ios-fw | grep -e '\.h$'`; do
|
||||
cp -f /build-ios-fw/$header $framework/Versions/A/Headers/$title.h
|
||||
done
|
||||
(cd $framework && ln -nsf Versions/A/Headers Headers)
|
||||
|
||||
mkdir -p $framework/Versions/A/Resources
|
||||
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n</dict>\n</plist>" > $framework/Versions/A/Resources/Info.plist
|
||||
(cd $framework && ln -nsf Versions/A/Resources Resources)
|
||||
mkdir -p $framework/Versions/A/Resources
|
||||
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n</dict>\n</plist>" > $framework/Versions/A/Resources/Info.plist
|
||||
(cd $framework && ln -nsf Versions/A/Resources Resources)
|
||||
|
||||
mkdir -p $framework/Versions/A/Modules
|
||||
echo -e "framework module \"$title\" {\n header \"$title.h\"\n export *\n}" > $framework/Versions/A/Modules/module.modulemap
|
||||
(cd $framework && ln -nsf Versions/A/Modules Modules)
|
||||
mkdir -p $framework/Versions/A/Modules
|
||||
echo -e "framework module \"$title\" {\n header \"$title.h\"\n export *\n}" > $framework/Versions/A/Modules/module.modulemap
|
||||
(cd $framework && ln -nsf Versions/A/Modules Modules)
|
||||
|
||||
chmod 777 -R /build/$NAME-ios-$PLATFORM
|
||||
rm -rf /build-ios
|
||||
chmod 777 -R /build/$NAME-ios-$PLATFORM-framework
|
||||
fi
|
||||
rm -rf /build-ios-fw
|
||||
fi
|
||||
# Remove any automatically injected deployment target vars
|
||||
unset IPHONEOS_DEPLOYMENT_TARGET
|
||||
|
|
Loading…
Reference in New Issue