| 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)" |
| 5 | VIDYA="${VIDYA:-$(cd "$ROOT/../vidya" && pwd)}" |
| 6 | # glimmer itself is a git dependency, so its sources live in the jolt cache |
| 7 | # rather than in either checkout. The boot image is built from :paths alone — |
| 8 | # there is no dependency resolution inside a cross compile — so the cache path |
| 9 | # has to be named here. |
| 10 | GLIMMER="${GLIMMER:-$HOME/.jolt/gitlibs/https___github.com_jolt-lang_glimmer/5581c331c51aff989259b9e8e92ec920fe5e6741/src}" |
| 11 | OUT="${1:?usage: build-jolt-boot.sh OUTPUT_DIRECTORY}" |
| Pin the jolt the APK needs 2308a7e nandi 19d ago | 12 | # The DotSlash-pinned jolt beside this script, not whatever is on PATH: an |
| 13 | # upstream jolt cannot open a TLS connection on Android — it reads the socket |
| 14 | # address out of `struct addrinfo` at glibc's offset, which is Bionic's |
| 15 | # `ai_canonname` — so a build made with one produces an APK that cannot sign in |
| 16 | # or send a picture. Override with JOLT= to use another. |
| 17 | JOLT="${JOLT:-$ROOT/scripts/jolt}" |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 18 | MODULE="${MODULE:-frq.app}" |
| 19 | CHEZ_ANDROID="${CHEZ_ANDROID:-$HOME/.cache/vidya-chez-android}" |
| 20 | HOST_SCHEME="$CHEZ_ANDROID/ta6le/bin/ta6le/scheme" |
| 21 | TARGET_BOOT="$CHEZ_ANDROID/boot/tarm64le" |
| 22 | XPATCH="$CHEZ_ANDROID/xc-tarm64le/s/xpatch" |
| 23 | |
| 24 | for path in "$HOST_SCHEME" "$TARGET_BOOT/petite.boot" \ |
| 25 | "$TARGET_BOOT/scheme.boot" "$TARGET_BOOT/scheme.h" "$XPATCH"; do |
| 26 | [[ -e "$path" ]] || { |
| 27 | echo "missing Android Chez artifact: $path" >&2 |
| 28 | echo "Build Chez's tarm64le cross target first; see ../vidya/android." >&2 |
| 29 | exit 1 |
| 30 | } |
| 31 | done |
| 32 | command -v "$JOLT" >/dev/null || { |
| 33 | echo "Jolt executable not found: $JOLT" >&2 |
| 34 | exit 1 |
| 35 | } |
| 36 | |
| 37 | # The boot image is a pure function of the Scheme sources, the module name, the |
| 38 | # flat-split flag and Chez's own boot files — all static. Hash them, and skip |
| 39 | # the whole thing when the stamp still matches: a Rust-only APK rebuild has no |
| 40 | # reason to spend fifteen single-threaded seconds recompiling Scheme. |
| 41 | # |
| 42 | # The flag is part of the stamp on purpose. JOLT_NO_FLAT_SPLIT changes the shape |
| 43 | # of what `jolt build` emits, so an app.build/ left by an ordinary build is not |
| 44 | # reusable here; a stamp miss wipes the tree below, which is what the |
| 45 | # unconditional `rm -rf` used to be defending against. |
| 46 | STAMP="$OUT/jolt.boot.stamp" |
| 47 | stamp_now() { |
| 48 | { |
| 49 | printf '%s\n' "$MODULE" "JOLT_NO_FLAT_SPLIT=1" |
| 50 | "$JOLT" --version 2>/dev/null || true |
| 51 | find "$ROOT/src" "$VIDYA/glimmer/src" "$GLIMMER" -type f \ |
| 52 | \( -name '*.jolt' -o -name '*.edn' \) -print0 | sort -z | xargs -0 sha256sum |
| 53 | sha256sum "$TARGET_BOOT/petite.boot" "$TARGET_BOOT/scheme.boot" "$XPATCH" |
| 54 | } | sha256sum | cut -d' ' -f1 |
| 55 | } |
| 56 | |
| 57 | WANT="$(stamp_now)" |
| 58 | if [[ -f "$OUT/jolt.boot" && -f "$OUT/scheme.h" && -f "$STAMP" ]] && |
| 59 | [[ "$(<"$STAMP")" == "$WANT" ]]; then |
| 60 | echo "jolt boot image up to date" >&2 |
| 61 | exit 0 |
| 62 | fi |
| 63 | |
| 64 | rm -f "$STAMP" |
| 65 | rm -rf "$OUT/project" "$OUT/cross" |
| 66 | mkdir -p "$OUT/project" "$OUT/cross" |
| 67 | cat > "$OUT/project/deps.edn" <<EOF |
| 68 | {:paths ["$ROOT/src" "$VIDYA/glimmer/src" "$GLIMMER"]} |
| 69 | EOF |
| 70 | |
| 71 | ( |
| 72 | cd "$OUT/project" |
| 73 | JOLT_NO_FLAT_SPLIT=1 "$JOLT" build \ |
| 74 | -m "$MODULE" -o app |
| 75 | ) |
| 76 | |
| 77 | cat > "$OUT/cross/compile.ss" <<EOF |
| 78 | (import (chezscheme)) |
| 79 | (load "$XPATCH") |
| 80 | (optimize-level 2) |
| 81 | (generate-inspector-information #f) |
| 82 | (compile-file "$OUT/project/app.build/flat.ss" "$OUT/cross/flat.so") |
| 83 | (make-boot-file "$OUT/jolt.boot" '() |
| 84 | "$TARGET_BOOT/petite.boot" |
| 85 | "$TARGET_BOOT/scheme.boot" |
| 86 | "$OUT/cross/flat.so") |
| 87 | EOF |
| 88 | |
| 89 | SCHEMEHEAPDIRS="$CHEZ_ANDROID/ta6le/boot/ta6le" \ |
| 90 | "$HOST_SCHEME" --script "$OUT/cross/compile.ss" |
| 91 | |
| 92 | cp "$TARGET_BOOT/scheme.h" "$OUT/scheme.h" |
| 93 | |
| 94 | # Last, so an interrupted build leaves no stamp and the next run redoes it. |
| 95 | printf '%s\n' "$WANT" > "$STAMP" |