nandi/jolt-nativepublic Fork 0
3dd441e764bc6b0123d9b33fe9871dcf7ac150b6
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 · 60 lines · 2.9 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
Let the media plane cross to the phone, camera and all fd0e21a nandi 18d ago47# The target goes *after* the caller's arguments, because clang takes the last
48# --target it is given and cc-rs passes one of its own. Its version carries no
49# API level, so putting ours first silently dropped the app back to the NDK's
50# default minimum — where bionic has no `getentropy`, and aws-lc-sys fails to
51# compile against a header that does not declare it. The API level is not a
52# default to be overridden; it is the floor the app is built for.
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago53case $mode in
Let the media plane cross to the phone, camera and all fd0e21a nandi 18d ago54 cc) exec "$bin/clang" "$@" --target="$target" ;;
55 c++) exec "$bin/clang++" "$@" --target="$target" ;;
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago56 ar) exec "$bin/llvm-ar" "$@" ;;
57 ranlib) exec "$bin/llvm-ranlib" "$@" ;;
58 objcopy) exec "$bin/llvm-objcopy" "$@" ;;
59 *) echo "toolchains/ndk.sh: unknown mode $mode" >&2; exit 1 ;;
60esac