nandi/jolt-nativepublic Fork 0
14a30c029628db6eb0966e8de5efffa1aeeafc57
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

ndk.sh · 54 lines · 2.4 KBBash Blame HistoryRaw
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago1#!/bin/sh
2# The NDK, as the C toolchain for Android, fetched where the action runs.
3#
4# Unlike zcc.sh, the archive behind this is not an input. That is deliberate:
5# unpacked it is three gigabytes, and an input has to travel to a worker
6# through the CAS — uploaded from here first, then materialised there. What
7# travels instead is DotSlash (under a megabyte) and the manifest naming the
8# archive, and the worker fetches the same bytes under the same digest from
9# Google. A machine that has already fetched it does nothing.
10#
11# The cost of that is honest to state: what the compiler *is* stops being part
12# of the action's cache digest. The manifest is an input, so a version bump
13# still invalidates; a machine whose DotSlash cache holds something else under
14# that digest cannot happen, because the digest is what the cache is keyed on.
15#
16# $1 is the directory holding the DotSlash binary, $2 the manifest to resolve
17# and $3 the mode — cc, c++, ar, ranlib or objcopy. buck passes all three.
18set -e
19dotslash=$1/dotslash
20manifest=$2
21mode=$3
22shift 3
23
24# ANDROID_NDK_HOME still wins, for a machine that has one installed.
25ndk=${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}
26if [ -n "$ndk" ]; then
27 for host in linux-x86_64 darwin-x86_64; do
28 if [ -d "$ndk/toolchains/llvm/prebuilt/$host/bin" ]; then
29 bin=$ndk/toolchains/llvm/prebuilt/$host/bin
30 break
31 fi
32 done
33 [ -n "${bin:-}" ] || { echo "toolchains/ndk.sh: no llvm prebuilt under $ndk" >&2; exit 1; }
34else
35 # The manifest names bin/clang inside the archive; DotSlash unpacks the
36 # whole NDK around it, which is what the driver needs — its sysroot and its
37 # resource directory are found relative to the binary.
38 bin=$(dirname "$("$dotslash" -- fetch "$manifest")")
39fi
40
41# API 28 is frq's min_sdk_version, and the floor for what the app needs from
42# bionic. The NDK ships a wrapper script per API level that adds this flag and
43# nothing else; passing it here keeps this to one executable out of the
44# archive, so nothing depends on which permissions survived the unpacking.
45target=${JOLT_ANDROID_TARGET:-aarch64-linux-android}${JOLT_ANDROID_API:-28}
46
47case $mode in
48 cc) exec "$bin/clang" --target="$target" "$@" ;;
49 c++) exec "$bin/clang++" --target="$target" "$@" ;;
50 ar) exec "$bin/llvm-ar" "$@" ;;
51 ranlib) exec "$bin/llvm-ranlib" "$@" ;;
52 objcopy) exec "$bin/llvm-objcopy" "$@" ;;
53 *) echo "toolchains/ndk.sh: unknown mode $mode" >&2; exit 1 ;;
54esac