| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 1 | # The work is here now, in recipe bodies, where it used to be in scripts/ — |
| 2 | # babashka scripts run through a scripts/bb that went looking for a babashka. |
| 3 | # That indirection bought one thing worth having, a shared way to reach nix on |
| 4 | # a host that keeps it in a container, and `nix` below is the whole of it. |
| 5 | # |
| 6 | # Every recipe that runs frq has the same shape: outside the dev shell, re-enter |
| 7 | # it and come back to this same recipe; inside, hand jolt the deps overrides and |
| 8 | # the library path the shell exported. The re-entry test is JOLT_NATIVE_LIB, |
| 9 | # which only the shell sets — no flag to forget, and no second code path for |
| 10 | # someone who runs `nix develop --command just run` by hand. |
| Take glimmer-vidya from gitlab, so a stranger can build this 5c40e75 nandi 19d ago | 11 | |
| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 12 | set shell := ["bash", "-euo", "pipefail", "-c"] |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 13 | |
| Give the terminal's classpath an nREPL, and hand recipes their arguments 664397d nandi 10d ago | 14 | # Every recipe below is a `#!` script and passes its arguments on with "$@". |
| 15 | # Without this that is empty in one — just interpolates into a shebang recipe |
| 16 | # rather than handing it argv — and `just tui --headless` silently ran the |
| 17 | # terminal instead. |
| 18 | set positional-arguments |
| 19 | |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 20 | # nix is not on every host this runs on: on the machine these recipes were |
| 21 | # written for it lives in an Arch distrobox, at the same path — which is why |
| 22 | # the container is entered rather than the tree copied into it. See CLAUDE.md. |
| 23 | nix := `command -v nix >/dev/null 2>&1 && echo nix || echo "distrobox enter arch -- nix"` |
| 24 | |
| 25 | # --max-jobs 0 is what sends the work to the `builders` entry rather than |
| 26 | # compiling it here. Left to the default, nix prefers the local machine, and a |
| 27 | # cold jolt-native is egui, openh264 and quinn on a laptop — for a derivation a |
| 28 | # remote builder has likely built already. FRQ_MAX_JOBS=auto is the way out on |
| 29 | # a machine with no builder configured. |
| 30 | jobs := env("FRQ_MAX_JOBS", "0") |
| 31 | |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 32 | default: |
| 33 | @just --list |
| 34 | |
| Paint the phone in COSMIC's own theme, read from cosmic-config ba4e71b nandi 7d ago | 35 | # Re-read the COSMIC theme into the APK. |
| 36 | # |
| 37 | # libcosmic asks cosmic-config for the accent and the surfaces at run time, so |
| 38 | # `just run` already follows COSMIC Settings as it changes. A phone has no |
| 39 | # cosmic-config, so the APK carries them instead — read here, on the machine |
| 40 | # that has them, and compiled in. That is the one real difference between the |
| 41 | # two, and it is why the generated file is in git rather than gitignored: a |
| 42 | # checkout on a machine with no COSMIC still builds. |
| 43 | # |
| 44 | # Run it after changing the theme in COSMIC Settings, then `just apk`. |
| 45 | theme: |
| 46 | #!/usr/bin/env bash |
| 47 | set -euo pipefail |
| 48 | cd "{{justfile_directory()}}" |
| 49 | python3 tools/cosmic2cljd.py flutter/src/frq/theme/cosmic.cljd |
| 50 | |
| Build the APK, out of ClojureDart and Flutter e2b0e6b nandi 7d ago | 51 | # The APK: ClojureDart compiled to Dart, then Flutter's Gradle build. |
| 52 | # |
| 53 | # Impure on purpose, and worth saying why rather than leaving it to be |
| 54 | # discovered. Gradle resolves its own dependencies over the network and |
| 55 | # installs build-tools and a platform into ANDROID_HOME as it goes, so it |
| 56 | # cannot run in a sandbox and cannot write to the store. What nix gives here |
| 57 | # is the toolchain — clojure, a JDK, Flutter, and an SDK composed by |
| 58 | # androidenv — and the recipe copies that SDK somewhere writable |
| 59 | # (flutter/.home) for Gradle to finish off. That copy and everything Gradle |
| 60 | # leaves behind are gitignored. |
| 61 | # |
| 62 | # No ndkVersion in android/app/build.gradle.kts, for the same reason: the |
| 63 | # Flutter template sets it, setting it makes Gradle fetch that exact NDK, and |
| 64 | # there is no native code here to need one. |
| 65 | # |
| 66 | # just apk build the debug APK |
| 67 | # just apk install build it and put it on a connected device |
| 68 | # just apk run install and launch |
| 69 | # just apk log logcat, filtered to this app |
| 70 | apk action="build": |
| 71 | #!/usr/bin/env bash |
| 72 | set -euo pipefail |
| 73 | cd "{{justfile_directory()}}/flutter" |
| 74 | |
| 75 | sdk="$(nix build --impure --no-link --print-out-paths \ |
| 76 | --expr 'let pkgs = import (builtins.getFlake "github:NixOS/nixpkgs/nixos-unstable") { system = "x86_64-linux"; config = { allowUnfree = true; android_sdk.accept_license = true; }; }; in (pkgs.androidenv.composeAndroidPackages { cmdLineToolsVersion = "13.0"; buildToolsVersions = [ "34.0.0" ]; platformVersions = [ "35" "34" ]; includeNDK = false; }).androidsdk')/libexec/android-sdk" |
| 77 | |
| 78 | export HOME="$PWD/.home" |
| 79 | export ANDROID_HOME="$HOME/android-sdk" |
| 80 | export ANDROID_SDK_ROOT="$ANDROID_HOME" |
| 81 | mkdir -p "$HOME" |
| 82 | |
| 83 | # Gradle writes into ANDROID_HOME, so it is a copy rather than the store |
| 84 | # path. Made once and kept: re-copying would throw away the build-tools |
| 85 | # and platform Gradle installed into it on the last run. |
| 86 | if [ ! -d "$ANDROID_HOME" ]; then |
| 87 | cp -r "$sdk" "$ANDROID_HOME" |
| 88 | chmod -R u+w "$ANDROID_HOME" |
| 89 | fi |
| 90 | |
| 91 | flutter="nix shell nixpkgs#clojure nixpkgs#jdk17 nixpkgs#flutter --command" |
| 92 | |
| 93 | $flutter clojure -M:cljd compile |
| 94 | |
| 95 | # Rewritten every run: it carries absolute store paths, and the flutter |
| 96 | # one moves whenever nixpkgs does. |
| 97 | $flutter flutter config --android-sdk "$ANDROID_HOME" >/dev/null |
| 98 | |
| 99 | apk=build/app/outputs/flutter-apk/app-debug.apk |
| 100 | adb="${ADB:-$ANDROID_HOME/platform-tools/adb}" |
| 101 | |
| 102 | case "{{action}}" in |
| 103 | build) $flutter flutter build apk --debug ;; |
| 104 | install) $flutter flutter build apk --debug && "$adb" install -r "$apk" ;; |
| 105 | run) $flutter flutter build apk --debug && "$adb" install -r "$apk" \ |
| 106 | && "$adb" shell monkey -p uk.nandi.frq -c android.intent.category.LAUNCHER 1 ;; |
| 107 | log) "$adb" logcat -s flutter ;; |
| 108 | *) echo "usage: just apk [build|install|run|log]" >&2; exit 1 ;; |
| 109 | esac |
| 110 | |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 111 | # Two halves, and the split is the point. The frq source is the files on disk, |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 112 | # uncommitted edits and all. Everything under it — jolt, glimmer, glimmer-cosmic |
| 113 | # and the native objects — is the flake's, built rather than fetched. |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 114 | # |
| 115 | # Deliberately not `nix run .#frq`. That builds the flake's own copy of the |
| 116 | # source, which is the tree as git has it — so an edit that has not been |
| 117 | # committed, or committed on a branch the command was not pointed at, runs as |
| 118 | # whatever was there before, silently. A run meant to answer "does my change |
| 119 | # work" has to be the files on disk. |
| 120 | # |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 121 | # libcosmic paints through wgpu, so this needs nixGL off NixOS for the same |
| 122 | # reason the window always did: the real driver is the host's. |
| 123 | # |
| 124 | # There is no jvui and no vidya here any more — both were experiments. The |
| 125 | # window is libcosmic and the terminal is libjolttui, and those are the two. |
| 126 | # |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 127 | # The app: this tree's source on the flake's everything-else, in the dev shell. |
| A freeq client in jolt, as glimmer components on Vidya 4719d6f nandi 20d ago | 128 | run *args: |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 129 | #!/usr/bin/env bash |
| 130 | set -euo pipefail |
| 131 | cd "{{justfile_directory()}}" |
| 132 | if [ -z "${JOLT_NATIVE_LIB:-}" ]; then |
| 133 | exec {{nix}} develop . --max-jobs {{jobs}} --command just run "$@" |
| 134 | fi |
| 135 | |
| 136 | deps="{:deps {jolt-lang/glimmer {:local/root \"$GLIMMER_SRC\"}" |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 137 | deps="$deps nandi/glimmer-cosmic {:local/root \"$GLIMMER_COSMIC_SRC\"}}}" |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 138 | |
| 139 | export LD_LIBRARY_PATH="$JOLT_NATIVE_LIB:$FRQ_LIB_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" |
| Paint the same screens into a terminal ab83b42 nandi 17d ago | 140 | |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 141 | runner=() |
| 142 | [ -e /run/current-system ] || runner=("$NIXGL") |
| 143 | |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 144 | exec "${runner[@]}" jolt -Sdeps "$deps" -m frq.cosmic "$@" |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 145 | |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 146 | # `run` with the other backend under it. Only libjolttui: `frq.app` names no |
| 147 | # backend at all any more, and `frq.tui` requires glimmer-tui so the one |
| 148 | # installed is the terminal. |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 149 | # |
| 150 | # No nixGL here, unlike `run`: a terminal wants nothing from the host's GL |
| 151 | # driver, which is the reason this output exists on machines that have none. |
| 152 | # |
| Check what common/ may contain, on every push 86c2e1b nandi 7d ago | 153 | # What may appear in common/, checked — the half of the tree both backends |
| 154 | # compile. Needs nothing built: it reads the source, so it is the one check |
| 155 | # that runs anywhere, and CI runs exactly this. |
| 156 | check-common: |
| 157 | #!/usr/bin/env bash |
| 158 | python3 tools/check-common.py common |
| 159 | |
| Paint the same screens into a terminal ab83b42 nandi 17d ago | 160 | # The same screens in a terminal. `just tui --headless` prints one screenshot. |
| 161 | tui *args: |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 162 | #!/usr/bin/env bash |
| 163 | set -euo pipefail |
| 164 | cd "{{justfile_directory()}}" |
| 165 | if [ -z "${JOLT_NATIVE_LIB:-}" ]; then |
| 166 | exec {{nix}} develop . --max-jobs {{jobs}} --command just tui "$@" |
| 167 | fi |
| 168 | |
| 169 | deps="{:deps {jolt-lang/glimmer {:local/root \"$GLIMMER_SRC\"}" |
| 170 | deps="$deps nandi/glimmer-tui {:local/root \"$GLIMMER_TUI_SRC\"}}}" |
| 171 | |
| 172 | export LD_LIBRARY_PATH="$JOLT_NATIVE_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" |
| Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago | 173 | |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 174 | exec jolt -Sdeps "$deps" -m frq.tui "$@" |
| 175 | |
| Give the terminal's classpath an nREPL, and hand recipes their arguments 664397d nandi 10d ago | 176 | # The same classpath as `tui`, with an nREPL on it instead of a `-main`: a |
| 177 | # session that can require `frq.tui` and then redefine a component while it is |
| 178 | # on screen, which is a second and not the minute a rebuild costs. |
| 179 | # |
| 180 | # just nrepl then, from an editor or a client on 7888: |
| 181 | # (require (quote frq.tui)) both backends, terminal installed last |
| 182 | # (frq.tui/-main "--headless" "--demo") |
| 183 | # (glimmer.core/reload!) re-mount after redefining a component |
| 184 | # |
| 185 | # `just repl nrepl-server` is the window's half of this — the same thing minus |
| 186 | # glimmer-tui. Port is nrepl-server's own positional: `just nrepl 7889`. |
| 187 | nrepl *args: |
| 188 | #!/usr/bin/env bash |
| 189 | set -euo pipefail |
| 190 | cd "{{justfile_directory()}}" |
| 191 | if [ -z "${JOLT_NATIVE_LIB:-}" ]; then |
| 192 | exec {{nix}} develop . --max-jobs {{jobs}} --command just nrepl "$@" |
| 193 | fi |
| 194 | |
| 195 | deps="{:deps {jolt-lang/glimmer {:local/root \"$GLIMMER_SRC\"}" |
| 196 | deps="$deps nandi/glimmer-tui {:local/root \"$GLIMMER_TUI_SRC\"}}}" |
| 197 | |
| 198 | export LD_LIBRARY_PATH="$JOLT_NATIVE_LIB:$FRQ_LIB_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" |
| 199 | |
| 200 | exec jolt -Sdeps "$deps" nrepl-server "$@" |
| 201 | |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 202 | # `jolt` in the repo root does not work on its own: deps.edn carries |
| 203 | # :jolt/native, so every invocation here loads libvidya and libjoltmoq before it |
| 204 | # reads a line, and dies naming the library if the loader cannot find them. So |
| 205 | # this is `run` without the app — and `run` is this with a window's worth of |
| 206 | # extra care about the GL driver. |
| 207 | # |
| Build the desktop libraries rather than fetching a release of them 0b81161 nandi 15d ago | 208 | # A jolt with the native libraries under it: a REPL, or `just repl nrepl-server`. |
| 209 | repl *args: |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 210 | #!/usr/bin/env bash |
| 211 | set -euo pipefail |
| 212 | cd "{{justfile_directory()}}" |
| 213 | if [ -z "${JOLT_NATIVE_LIB:-}" ]; then |
| 214 | exec {{nix}} develop . --max-jobs {{jobs}} --command just repl "$@" |
| 215 | fi |
| 216 | |
| 217 | deps="{:deps {jolt-lang/glimmer {:local/root \"$GLIMMER_SRC\"}" |
| Split the tree three ways, and let the phone be Flutter's 7070931 nandi 7d ago | 218 | deps="$deps nandi/glimmer-cosmic {:local/root \"$GLIMMER_COSMIC_SRC\"}}}" |
| Inline the babashka scripts into the justfile 76dcc6c nandi 11d ago | 219 | |
| 220 | export LD_LIBRARY_PATH="$JOLT_NATIVE_LIB:$FRQ_LIB_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" |
| 221 | |
| 222 | exec jolt -Sdeps "$deps" "$@" |
| Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago | 223 | |
| 224 | # Regenerate src/frq/moq/raw.clj from the libmoq_ffi we actually load. |
| 225 | # |
| 226 | # UniFFI embeds its interface metadata in the object, so `uniffi-bindgen |
| 227 | # --library` reads the truth out of the .so rather than a header shipped |
| Fetch libmoq_ffi again, and keep the codecs out of Rust f518938 nandi 9d ago | 228 | # beside it. Those differ at one version number: the published Linux and |
| 229 | # Android objects are built without moq-ffi's `audio` and `video` features |
| 230 | # (206 functions, no codecs), while the shipped C header describes the Apple |
| 231 | # build (230). The object is the only source this recipe will accept. |
| Bind libmoq_ffi from the object's own metadata, not from its header 9f081a1 nandi 9d ago | 232 | # |
| 233 | # The bindgen must match the uniffi that built the object — 0.32 for moq-ffi |
| 234 | # 0.3.17 — and it is built once into the scratch dir rather than pinned into |
| 235 | # the flake: nothing in a normal build needs it, and a regeneration is a thing |
| 236 | # done when the moq-ffi pin moves, by hand, on purpose. |
| 237 | # |
| 238 | # just gen-moq # the loaded library |
| 239 | # just gen-moq path/to/libmoq_ffi.so |
| 240 | # |
| 241 | # Regenerate the libmoq_ffi bindings from the object's own embedded metadata. |
| 242 | gen-moq lib="": |
| 243 | #!/usr/bin/env bash |
| 244 | set -euo pipefail |
| 245 | lib="${1:-${JOLT_NATIVE_LIB:-}/libmoq_ffi.so}" |
| 246 | [ -f "$lib" ] || { echo "no libmoq_ffi.so at $lib — pass one: just gen-moq <path>" >&2; exit 1; } |
| 247 | work="${TMPDIR:-/tmp}/frq-gen-moq" |
| 248 | mkdir -p "$work/ubg/src" |
| 249 | cat > "$work/ubg/Cargo.toml" <<'TOML' |
| 250 | [package] |
| 251 | name = "ubg" |
| 252 | version = "0.1.0" |
| 253 | edition = "2021" |
| 254 | [[bin]] |
| 255 | name = "uniffi-bindgen" |
| 256 | path = "src/main.rs" |
| 257 | [dependencies] |
| 258 | uniffi = { version = "0.32", features = ["cli"] } |
| 259 | TOML |
| 260 | echo 'fn main() { uniffi::uniffi_bindgen_main() }' > "$work/ubg/src/main.rs" |
| 261 | ( cd "$work/ubg" && cargo build --release -q ) |
| 262 | ( cd "$work/ubg" && ./target/release/uniffi-bindgen generate \ |
| 263 | --library "$lib" --language python --out-dir "$work/py" --no-format ) |
| 264 | python3 tools/py2jolt.py "$work"/py/*.py > "$work/body.clj" |
| 265 | { sed -n '1,/^ (:require \[jolt.ffi :as ffi\]))$/p' src/frq/moq/raw.clj; echo; cat "$work/body.clj"; } > "$work/raw.clj" |
| 266 | mv "$work/raw.clj" src/frq/moq/raw.clj |
| 267 | echo "wrote src/frq/moq/raw.clj ($(grep -c '^(ffi/defcfn' src/frq/moq/raw.clj) entry points)" |