Skip to content

Commit

Permalink
Support for Android arm64 compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Jul 5, 2017
1 parent 42e551f commit 48fb715
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 43 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ports/servo/build.rs
Expand Up @@ -80,7 +80,7 @@ fn android_main() {
}

// compiling libandroid_native_app_glue.a
if Command::new(toolchain_path.join("bin").join("arm-linux-androideabi-ar"))
if Command::new(toolchain_path.join("bin").join(format!("{}-ar", toolchain)))
.arg("rcs")
.arg(directory.join("libandroid_native_app_glue.a"))
.arg(directory.join("android_native_app_glue.o"))
Expand Down
2 changes: 1 addition & 1 deletion ports/servo/fake-ld-arm.sh
Expand Up @@ -11,4 +11,4 @@ set -o pipefail
source fake-ld.sh

export _GCC_PARAMS="${@}"
call_gcc "arch-arm" "arm-linux-androideabi-4.9" "android-18" "armeabi"
call_gcc "arch-arm" "arm-linux-androideabi" "android-18" "armeabi"
2 changes: 1 addition & 1 deletion ports/servo/fake-ld-arm64.sh
Expand Up @@ -11,4 +11,4 @@ set -o pipefail
source fake-ld.sh

export _GCC_PARAMS="${@}"
call_gcc "arch-arm64" "aarch64-linux-android-4.9" "android-21" "arm64-v8a"
call_gcc "arch-arm64" "aarch64-linux-android" "android-21" "arm64-v8a"
2 changes: 1 addition & 1 deletion ports/servo/fake-ld-armv7.sh
Expand Up @@ -11,4 +11,4 @@ set -o pipefail
source fake-ld.sh

export _GCC_PARAMS="${@}"
call_gcc "arch-arm" "arm-linux-androideabi-4.9" "android-18" "armeabi-v7a"
call_gcc "arch-arm" "arm-linux-androideabi" "android-18" "armeabi-v7a"
6 changes: 3 additions & 3 deletions ports/servo/fake-ld.sh
Expand Up @@ -18,8 +18,8 @@ call_gcc()
export ANDROID_SYSROOT="${ANDROID_NDK}/platforms/${_ANDROID_PLATFORM}/${_ANDROID_ARCH}"
ANDROID_TOOLCHAIN=""
for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"; do
if [[ -d "${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin" ]]; then
ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/${_ANDROID_EABI}/prebuilt/${host}/bin"
if [[ -d "${ANDROID_NDK}/toolchains/${_ANDROID_EABI}-4.9/prebuilt/${host}/bin" ]]; then
ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/${_ANDROID_EABI}-4.9/prebuilt/${host}/bin"
break
fi
done
Expand All @@ -32,7 +32,7 @@ call_gcc()
echo "sysroot: ${ANDROID_SYSROOT}"
echo "targetdir: ${ANDROID_CXX_LIBS}"

"${ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc" \
"${ANDROID_TOOLCHAIN}/${_ANDROID_EABI}-gcc" \
--sysroot="${ANDROID_SYSROOT}" -L "${ANDROID_CXX_LIBS}" ${_GCC_PARAMS} -lc++ \
-o "${TARGET_DIR}/libservo.so" -shared && touch "${TARGET_DIR}/servo"
}
9 changes: 5 additions & 4 deletions python/servo/build_commands.py
Expand Up @@ -246,6 +246,10 @@ def build(self, target=None, release=False, dev=False, jobs=None,
env["RUSTFLAGS"] = "-C debug_assertions"

if android:
android_platform = self.config["android"]["platform"]
android_toolchain = self.config["android"]["toolchain_name"]
android_arch = "arch-" + self.config["android"]["arch"]

# Build OpenSSL for android
env["OPENSSL_VERSION"] = "1.0.2k"
make_cmd = ["make"]
Expand All @@ -258,6 +262,7 @@ def build(self, target=None, release=False, dev=False, jobs=None,
shutil.copy(path.join(self.android_support_dir(), "openssl.makefile"), openssl_dir)
shutil.copy(path.join(self.android_support_dir(), "openssl.sh"), openssl_dir)
env["ANDROID_NDK_ROOT"] = env["ANDROID_NDK"]
env["RUST_TARGET"] = target
with cd(openssl_dir):
status = call(
make_cmd + ["-f", "openssl.makefile"],
Expand All @@ -283,10 +288,6 @@ def build(self, target=None, release=False, dev=False, jobs=None,
host_suffix = "x86_64"
host = os_type + "-" + host_suffix

android_platform = self.config["android"]["platform"]
android_toolchain = self.config["android"]["toolchain_name"]
android_arch = "arch-" + self.config["android"]["arch"]

env['PATH'] = path.join(
env['ANDROID_NDK'], "toolchains", android_toolchain, "prebuilt", host, "bin"
) + ':' + env['PATH']
Expand Down
72 changes: 47 additions & 25 deletions support/android/openssl.sh
Expand Up @@ -22,12 +22,48 @@ _ANDROID_NDK="android-ndk-r9"
# list in $ANDROID_NDK_ROOT/toolchains. This value is always used.
# _ANDROID_EABI="x86-4.6"
# _ANDROID_EABI="arm-linux-androideabi-4.6"
_ANDROID_EABI="arm-linux-androideabi-4.9"

# Set _ANDROID_ARCH to the architecture you are building for.
# This value is always used.
# _ANDROID_ARCH=arch-x86
_ANDROID_ARCH=arch-arm


case $RUST_TARGET in
armv7*)
_ANDROID_TARGET="arm-linux-androideabi"
_ANDROID_ARCH=arch-arm
_OPENSSL_MACHINE="armv7"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="android-armv7"
;;
arm*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-arm
_OPENSSL_MACHINE="arm"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="android-armv7"
;;
aarch64*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-arm64
_OPENSSL_MACHINE="armv7"
_OPENSSL_ARCH="arm64"
_OPENSSL_CONFIG="linux-generic64 -DB_ENDIAN"
;;
x86*)
_ANDROID_TARGET=$RUST_TARGET
_ANDROID_ARCH=arch-x86
_OPENSSL_MACHINE="x86"
_OPENSSL_ARCH="arm"
_OPENSSL_CONFIG="android-x86"
;;
*)
echo "Error: Invalid TARGET platform: $RUST_TARGET"
;;
esac

_ANDROID_EABI="$_ANDROID_TARGET-4.9"


# Set _ANDROID_API to the API you want to use. You should set it
# to one of: android-14, android-9, android-8, android-14, android-5
Expand Down Expand Up @@ -93,17 +129,7 @@ if [ -z "$ANDROID_TOOLCHAIN" ] || [ ! -d "$ANDROID_TOOLCHAIN" ]; then
# exit 1
fi

case $_ANDROID_ARCH in
arch-arm)
ANDROID_TOOLS="arm-linux-androideabi-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld"
;;
arch-x86)
ANDROID_TOOLS="i686-linux-android-gcc i686-linux-android-ranlib i686-linux-android-ld"
;;
*)
echo "ERROR ERROR ERROR"
;;
esac
ANDROID_TOOLS="$_ANDROID_TARGET-gcc $_ANDROID_TARGET-ranlib $_ANDROID_TARGET-ld"

for tool in $ANDROID_TOOLS
do
Expand Down Expand Up @@ -141,24 +167,17 @@ fi
#####################################################################

# Most of these should be OK (MACHINE, SYSTEM, ARCH). RELEASE is ignored.
export MACHINE=armv7
export MACHINE=$_OPENSSL_MACHINE
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=arm
export CROSS_COMPILE="arm-linux-androideabi-"

if [ "$_ANDROID_ARCH" == "arch-x86" ]; then
export MACHINE=i686
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=x86
export CROSS_COMPILE="i686-linux-android-"
fi
export ARCH=$_OPENSSL_ARCH
export CROSS_COMPILE="$_ANDROID_TARGET-"

# For the Android toolchain
# https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH"
export SYSROOT="$ANDROID_SYSROOT"
export CROSS_SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_API="$_ANDROID_API"
Expand All @@ -168,6 +187,9 @@ export ANDROID_API="$_ANDROID_API"
export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/$_ANDROID_API/$_ANDROID_ARCH/usr"
export HOSTCC=gcc

# See https://github.com/cocochpie/android-openssl/blob/master/build-all-arch.sh
xCFLAGS="-DSHARED_EXTENSION=.so -fPIC -DOPENSSL_PIC -DDSO_DLFCN -DHAVE_DLFCN_H -mandroid -I$ANDROID_DEV/include -B$ANDROID_DEV/lib -O3 -fomit-frame-pointer -Wall"

VERBOSE=1
if [ ! -z "$VERBOSE" ] && [ "$VERBOSE" != "0" ]; then
echo "ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
Expand All @@ -186,6 +208,6 @@ perl -pi -e 's/install: all install_docs install_sw/install: install_docs instal

# The code being built isn't maintained by us, so we redirect stderr to stdout
# so that the warnings don't clutter up buildbot
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API 2>&1
./Configure shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API $_OPENSSL_CONFIG $xCFLAGS 2>&1
make depend 2>&1
make all 2>&1

0 comments on commit 48fb715

Please sign in to comment.