| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 5 | |
| 6 | # The boot image is built from :paths alone — there is no dependency |
| 7 | # resolution inside a cross compile — so every source root deps.edn would have |
| 8 | # resolved has to be named here instead. Two of them are git dependencies, |
| 9 | # which means the jolt cache rather than a checkout; the shas come out of |
| 10 | # deps.edn so there is one place to bump them. |
| 11 | CHECKOUT="$(dirname "$(git -C "$ROOT" rev-parse --path-format=absolute --git-common-dir)")" |
| 12 | if [[ -z "${JOLT_NATIVE:-}" ]]; then |
| 13 | if [[ -d "$CHECKOUT/../jolt-native" ]]; then |
| 14 | JOLT_NATIVE="$(cd "$CHECKOUT/../jolt-native" && pwd)" |
| 15 | else |
| 16 | JOLT_NATIVE="$CHECKOUT/.jolt-native" |
| 17 | fi |
| 18 | fi |
| 19 | |
| 20 | # The sha deps.edn pins for a given git url, so a bump there reaches this. |
| 21 | dep_sha() { |
| 22 | awk -v url="$1" ' |
| 23 | index($0, url) { found = 1 } |
| 24 | found && $1 == ":git/sha" { gsub(/[^0-9a-f]/, "", $2); print $2; exit } |
| 25 | ' "$ROOT/deps.edn" |
| 26 | } |
| 27 | GLIMMER_SHA="$(dep_sha https://gitlab.com/nandithebull/glimmer)" |
| 28 | GLIMMER="${GLIMMER:-$HOME/.jolt/gitlibs/https___gitlab.com_nandithebull_glimmer/$GLIMMER_SHA/src}" |
| 29 | |
| 30 | # glimmer-vidya lives inside jolt-native, so a sibling checkout answers for it |
| 31 | # the way it answers for libvidya; the cache is the fallback, at the sha |
| 32 | # deps.edn pins. |
| 33 | GLIMMER_VIDYA_SHA="$(dep_sha https://gitlab.com/nandithebull/jolt-native)" |
| 34 | if [[ -z "${GLIMMER_VIDYA:-}" ]]; then |
| 35 | if [[ -d "$JOLT_NATIVE/jolt/glimmer-vidya/src" ]]; then |
| 36 | GLIMMER_VIDYA="$JOLT_NATIVE/jolt/glimmer-vidya/src" |
| 37 | else |
| 38 | GLIMMER_VIDYA="$HOME/.jolt/gitlibs/https___gitlab.com_nandithebull_jolt-native/$GLIMMER_VIDYA_SHA/jolt/glimmer-vidya/src" |
| 39 | fi |
| 40 | fi |
| 41 | |
| 42 | for path in "$GLIMMER" "$GLIMMER_VIDYA"; do |
| 43 | [[ -d "$path" ]] || { |
| 44 | echo "missing Jolt source root: $path" >&2 |
| 45 | echo "run \`jolt -M:frq --help\` once to populate the git cache" >&2 |
| 46 | exit 1 |
| 47 | } |
| 48 | done |
| 49 | OUT="${1:?usage: build-jolt-boot.sh OUTPUT_DIRECTORY | --stamp}" |
| 50 | # The DotSlash-pinned jolt, not whatever is on PATH: an upstream jolt cannot |
| 51 | # open a TLS connection on Android — it reads the socket address out of |
| 52 | # `struct addrinfo` at glibc's offset, which is Bionic's `ai_canonname` — so a |
| 53 | # build made with one produces an APK that cannot sign in or send a picture. |
| 54 | # Override with JOLT= to use another. |
| 55 | # |
| 56 | # DOTSLASH and JOLT_MANIFEST are set when buck runs this: the manifest and the |
| 57 | # fetcher are inputs to that action, so the machine running it needs neither |
| 58 | # jolt nor DotSlash installed, and a remote worker resolves the same pin |
| 59 | # against the same digest. Without them the shim beside this script answers, |
| 60 | # which is what a person at a terminal gets. |
| 61 | if [[ -z "${JOLT:-}" ]]; then |
| 62 | if [[ -n "${DOTSLASH:-}" && -n "${JOLT_MANIFEST:-}" ]]; then |
| 63 | JOLT="$("$DOTSLASH" -- fetch "$JOLT_MANIFEST")" |
| 64 | else |
| 65 | JOLT="$ROOT/scripts/jolt" |
| 66 | fi |
| 67 | fi |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 68 | MODULE="${MODULE:-frq.app}" |
| 69 | CHEZ_ANDROID="${CHEZ_ANDROID:-$HOME/.cache/vidya-chez-android}" |
| 70 | HOST_SCHEME="$CHEZ_ANDROID/ta6le/bin/ta6le/scheme" |
| 71 | TARGET_BOOT="$CHEZ_ANDROID/boot/tarm64le" |
| 72 | XPATCH="$CHEZ_ANDROID/xc-tarm64le/s/xpatch" |
| 73 | |
| 74 | for path in "$HOST_SCHEME" "$TARGET_BOOT/petite.boot" \ |
| 75 | "$TARGET_BOOT/scheme.boot" "$TARGET_BOOT/scheme.h" "$XPATCH"; do |
| 76 | [[ -e "$path" ]] || { |
| 77 | echo "missing Android Chez artifact: $path" >&2 |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 78 | echo "Build Chez's tarm64le cross target first." >&2 |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 79 | exit 1 |
| 80 | } |
| 81 | done |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 82 | [[ -x "$JOLT" ]] || command -v "$JOLT" >/dev/null || { |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 83 | echo "Jolt executable not found: $JOLT" >&2 |
| 84 | exit 1 |
| 85 | } |
| 86 | |
| 87 | # The boot image is a pure function of the Scheme sources, the module name, the |
| 88 | # flat-split flag and Chez's own boot files — all static. Hash them, and skip |
| 89 | # the whole thing when the stamp still matches: a Rust-only APK rebuild has no |
| 90 | # reason to spend fifteen single-threaded seconds recompiling Scheme. |
| 91 | # |
| 92 | # The flag is part of the stamp on purpose. JOLT_NO_FLAT_SPLIT changes the shape |
| 93 | # of what `jolt build` emits, so an app.build/ left by an ordinary build is not |
| 94 | # reusable here; a stamp miss wipes the tree below, which is what the |
| 95 | # unconditional `rm -rf` used to be defending against. |
| 96 | STAMP="$OUT/jolt.boot.stamp" |
| 97 | stamp_now() { |
| 98 | { |
| 99 | printf '%s\n' "$MODULE" "JOLT_NO_FLAT_SPLIT=1" |
| 100 | "$JOLT" --version 2>/dev/null || true |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 101 | find "$ROOT/src" "$GLIMMER" "$GLIMMER_VIDYA" -type f \ |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 102 | \( -name '*.jolt' -o -name '*.edn' \) -print0 | sort -z | xargs -0 sha256sum |
| 103 | sha256sum "$TARGET_BOOT/petite.boot" "$TARGET_BOOT/scheme.boot" "$XPATCH" |
| 104 | } | sha256sum | cut -d' ' -f1 |
| 105 | } |
| 106 | |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 107 | # buck needs this before the work rather than after: the sources it hashes live |
| 108 | # in the jolt cache and in jolt-native, outside this cell, so nothing else makes |
| 109 | # them reach an action's digest. See the `buck` recipe in the justfile. |
| 110 | if [[ "${1:-}" == "--stamp" ]]; then |
| 111 | stamp_now |
| 112 | exit 0 |
| 113 | fi |
| 114 | |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 115 | WANT="$(stamp_now)" |
| 116 | if [[ -f "$OUT/jolt.boot" && -f "$OUT/scheme.h" && -f "$STAMP" ]] && |
| 117 | [[ "$(<"$STAMP")" == "$WANT" ]]; then |
| 118 | echo "jolt boot image up to date" >&2 |
| 119 | exit 0 |
| 120 | fi |
| 121 | |
| 122 | rm -f "$STAMP" |
| 123 | rm -rf "$OUT/project" "$OUT/cross" |
| 124 | mkdir -p "$OUT/project" "$OUT/cross" |
| 125 | cat > "$OUT/project/deps.edn" <<EOF |
| Build the APK with buck2, from pins rather than from a second checkout a71ef8f nandi 19d ago | 126 | {:paths ["$ROOT/src" "$GLIMMER" "$GLIMMER_VIDYA"]} |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 127 | EOF |
| 128 | |
| 129 | ( |
| 130 | cd "$OUT/project" |
| 131 | JOLT_NO_FLAT_SPLIT=1 "$JOLT" build \ |
| 132 | -m "$MODULE" -o app |
| 133 | ) |
| 134 | |
| 135 | cat > "$OUT/cross/compile.ss" <<EOF |
| 136 | (import (chezscheme)) |
| 137 | (load "$XPATCH") |
| 138 | (optimize-level 2) |
| 139 | (generate-inspector-information #f) |
| 140 | (compile-file "$OUT/project/app.build/flat.ss" "$OUT/cross/flat.so") |
| 141 | (make-boot-file "$OUT/jolt.boot" '() |
| 142 | "$TARGET_BOOT/petite.boot" |
| 143 | "$TARGET_BOOT/scheme.boot" |
| 144 | "$OUT/cross/flat.so") |
| 145 | EOF |
| 146 | |
| 147 | SCHEMEHEAPDIRS="$CHEZ_ANDROID/ta6le/boot/ta6le" \ |
| 148 | "$HOST_SCHEME" --script "$OUT/cross/compile.ss" |
| 149 | |
| 150 | cp "$TARGET_BOOT/scheme.h" "$OUT/scheme.h" |
| 151 | |
| 152 | # Last, so an interrupted build leaves no stamp and the next run redoes it. |
| 153 | printf '%s\n' "$WANT" > "$STAMP" |