Repository navigation
Expand file tree
/
Copy pathxcompile_android_arm32.sh
More file actions
executable file
·97 lines (79 loc) · 4.08 KB
/
Copy pathxcompile_android_arm32.sh
File metadata and controls
executable file
·97 lines (79 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# scripts/release/xcompile_android_arm32.sh
# Cross-compile OTP for Android arm32 (armv7a-linux-androideabi, API 24+).
#
# Inputs (env or default):
# OTP_SRC — OTP source checkout (default: ~/code/otp)
# OPENSSL_PREFIX — pre-built OpenSSL install (default: /tmp/openssl-android-arm32)
# RELEASE_ROOT — install dir to populate (default: /tmp/otp-android-arm32)
# NDK_VERSION — NDK version (sourced from openssl/_lib.sh)
# ANDROID_NDK_ROOT — NDK root (sourced from openssl/_lib.sh)
# NDK_ABI_PLAT — Android API-level prefix (default: android24)
#
# Output:
# $RELEASE_ROOT/{bin,erts-<vsn>,lib,releases,...}
# $OTP_SRC/erts/arm-unknown-linux-androideabi/{config.h,...}
# $OTP_SRC/erts/emulator/{zstd,pcre,ryu}/obj/arm-unknown-linux-androideabi/opt/lib*.a
#
# Mirror of the arm64 sibling under openssl/_build_otp_android_arm64.sh.
# Targets armeabi-v7a for older 32-bit-only devices (e.g. Motorola E 2020).
set -euo pipefail
# Resolve our own dir to an absolute path before cd'ing — `dirname "$0"` is
# relative and would break the openssl/_lib.sh source line below.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
source ./_lib.sh
# NDK_VERSION + ANDROID_NDK_ROOT come from this shared file (single source of truth).
. "$SCRIPT_DIR/openssl/_lib.sh"
: "${OPENSSL_PREFIX:=/tmp/openssl-android-arm32}"
: "${RELEASE_ROOT:=/tmp/otp-android-arm32}"
# NDK_ABI_PLAT is interpolated into the xcomp conf's CC line as
# "armv7a-linux-${NDK_ABI_PLAT}-clang". The actual NDK clang for arm32 is
# named "armv7a-linux-androideabi24-clang" — the "eabi" suffix is required.
# arm64 differs (just "aarch64-linux-android24-clang"), which is why the
# arm64 sibling sets NDK_ABI_PLAT=android24.
: "${NDK_ABI_PLAT:=androideabi24}"
log "OTP_SRC=$OTP_SRC"
log "OPENSSL_PREFIX=$OPENSSL_PREFIX"
log "RELEASE_ROOT=$RELEASE_ROOT"
log "ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT"
[ -d "$OPENSSL_PREFIX" ] || fail "OPENSSL_PREFIX missing at $OPENSSL_PREFIX — run scripts/release/openssl/android_arm32.sh first"
[ -d "$ANDROID_NDK_ROOT" ] || fail "ANDROID_NDK_ROOT missing at $ANDROID_NDK_ROOT"
export NDK_ROOT="$ANDROID_NDK_ROOT"
export PATH="$NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH"
export NDK_ABI_PLAT
export RELEASE_LIBBEAM=yes
cd "$OTP_SRC"
# Install mob's arm32 xcomp conf over upstream's stub (llvm-ar, 16 KB pages,
# -Os/gc-sections, trimmed apps) — see the header of
# scripts/release/xcomp/erl-xcomp-arm-android.conf.
VENDORED_CONF="$SCRIPT_DIR/xcomp/erl-xcomp-arm-android.conf"
[ -f "$VENDORED_CONF" ] || fail "missing $VENDORED_CONF"
cp "$VENDORED_CONF" "$OTP_SRC/xcomp/erl-xcomp-arm-android.conf"
# Clean any stale config from a prior arch (iOS, arm64, etc.).
make distclean >/dev/null 2>&1 || true
log "configuring for arm-unknown-linux-androideabi..."
./otp_build configure \
--xcomp-conf=./xcomp/erl-xcomp-arm-android.conf \
--with-ssl="$OPENSSL_PREFIX" \
--disable-dynamic-ssl-lib
# Android xcomp configs do NOT set --enable-static-nifs, so beam.emu's link
# is fine without OpenSSL on the link line — crypto.so loads at runtime
# instead. We still build a separate static crypto.a via
# build_crypto_static_android_arm32.sh after this, since Android loads
# native libs RTLD_LOCAL and dlopen-ing crypto.so from a child .so doesn't
# see the parent's enif_* symbols.
log "building (this takes ~5–10 min)..."
./otp_build boot
# Static asn1 NIF for the tarball's erts-*/lib/asn1rt_nif.a, as the arm64 and
# x86_64 scripts do. (This used to be a manual NDK clang step.)
ERL_TOP="$OTP_SRC" make -C lib/asn1/c_src TARGET=arm-unknown-linux-androideabi static_lib
log "installing to $RELEASE_ROOT..."
rm -rf "$RELEASE_ROOT"
./otp_build release -a "$RELEASE_ROOT"
log "verifying outputs..."
[ -d "$RELEASE_ROOT/erts-$ERTS_VSN" ] \
|| fail "missing $RELEASE_ROOT/erts-$ERTS_VSN"
ls "$RELEASE_ROOT/lib/" | grep -E '^(crypto|public_key|ssl)-' >/dev/null \
|| fail "crypto/ssl/public_key apps NOT in install tree — --with-ssl wired wrong?"
log "done. Next: scripts/release/openssl/build_crypto_static_android_arm32.sh, then scripts/release/tarball_android_arm32.sh"