| Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago | 1 | #!/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. |
| 18 | set -e |
| 19 | dotslash=$1/dotslash |
| 20 | manifest=$2 |
| 21 | mode=$3 |
| 22 | shift 3 |
| 23 | |
| 24 | # ANDROID_NDK_HOME still wins, for a machine that has one installed. |
| 25 | ndk=${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}} |
| 26 | if [ -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; } |
| 34 | else |
| 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")") |
| 39 | fi |
| 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. |
| 45 | target=${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 ago | 47 | # 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 ago | 53 | case $mode in |
| Let the media plane cross to the phone, camera and all fd0e21a nandi 18d ago | 54 | 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 ago | 56 | 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 ;; |
| 60 | esac |