| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 1 | #!/bin/sh |
| 2 | #_( |
| 3 | exec "$(dirname "$0")/bb" "$0" "$@" |
| 4 | ) |
| 5 | |
| Run the source on disk, not the source in git 66ba416 nandi 17d ago | 6 | ;; The app, from this working tree. |
| Run the app the way it is built: nix run 35e7155 nandi 17d ago | 7 | ;; |
| 8 | ;; run.bb [args...] |
| 9 | ;; |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 10 | ;; Two halves, and the split is the point. The frq source is the files on disk, |
| 11 | ;; uncommitted edits and all. Everything under it — jolt, glimmer, |
| 12 | ;; glimmer-vidya, both native objects — is the flake's, built rather than |
| 13 | ;; fetched: this re-execs itself inside `nix develop`, and that shell is the |
| 14 | ;; jolt-native input compiled and the Jolt halves that bind it, at the revs |
| 15 | ;; flake.lock names. |
| Run the app the way it is built: nix run 35e7155 nandi 17d ago | 16 | ;; |
| Run the source on disk, not the source in git 66ba416 nandi 17d ago | 17 | ;; Deliberately not `nix run .#frq`. That builds the flake's own copy of the |
| 18 | ;; source, which is the tree as git has it — so an edit that has not been |
| 19 | ;; committed, or has been committed on a branch the command was not pointed at, |
| 20 | ;; runs as whatever was there before, silently. A run that is meant to answer |
| 21 | ;; "does my change work" has to be the files on disk. |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 22 | ;; |
| 23 | ;; And deliberately not the scripts/*.dotslash pins either, which is what this |
| 24 | ;; used to do. Those name a release; a change to jolt-native is by definition |
| Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago | 25 | ;; not in one yet. `just lib` still fetches them, and the APK takes the same |
| 26 | ;; released bytes through nix/android.nix — but a run does not. |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 27 | (require '[babashka.classpath :as cp]) |
| 28 | (cp/add-classpath (str (babashka.fs/parent *file*))) |
| 29 | (require '[frq.paths :as paths] |
| 30 | '[babashka.fs :as fs] |
| 31 | '[babashka.process :as p] |
| 32 | '[clojure.string :as str]) |
| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 33 | |
| 34 | (def root (str (fs/canonicalize (fs/path (fs/parent *file*) "..")))) |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 35 | (def self (str (fs/path root "scripts" "run.bb"))) |
| 36 | |
| 37 | ;; Outside the shell, get inside it and come back to this same script. The |
| 38 | ;; shell is what sets JOLT_NATIVE_LIB, so its absence is the test — no flag to |
| 39 | ;; forget, and `nix develop --command scripts/run.bb` by hand is not a second |
| 40 | ;; code path. |
| 41 | ;; |
| 42 | ;; --max-jobs 0 is what sends the work to the `builders` entry rather than |
| 43 | ;; compiling it here. Left to the default, nix prefers the local machine, and a |
| 44 | ;; cold jolt-native is egui, openh264 and quinn on a laptop — for a derivation |
| 45 | ;; a remote builder has likely built already. FRQ_MAX_JOBS is the way out on a |
| 46 | ;; machine with no builder configured: FRQ_MAX_JOBS=auto. |
| 47 | (when-not (System/getenv "JOLT_NATIVE_LIB") |
| Build the APK as derivations only, and retire the buck2 graph 3bc3aaa nandi 16d ago | 48 | ;; Getting to a nix on a host that may not have one is paths/nix's problem, |
| 49 | ;; and scripts/apk.bb has the same one. |
| 50 | (let [cmd (paths/nix root |
| 51 | ["nix" "develop" root |
| 52 | "--max-jobs" (paths/env "FRQ_MAX_JOBS" "0") |
| 53 | "--command" self] |
| 54 | *command-line-args*)] |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 55 | (System/exit (:exit @(apply p/process {:inherit true :dir root} cmd))))) |
| Run the app the way it is built: nix run 35e7155 nandi 17d ago | 56 | |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 57 | ;; The Jolt halves that have to match those objects. glimmer-vidya lives inside |
| 58 | ;; jolt-native and binds libvidya's ABI, so it comes out of the same input that |
| 59 | ;; was built rather than deps.edn's git sha — the pin drifting from the library |
| 60 | ;; is exactly what the flake input's comment describes. glimmer is the flake's |
| 61 | ;; for the same reason. |
| 62 | (def overrides |
| 63 | (str "{:deps {jolt-lang/glimmer {:local/root \"" (System/getenv "GLIMMER_SRC") "\"}" |
| 64 | " nandi/glimmer-vidya {:local/root \"" (System/getenv "GLIMMER_VIDYA_SRC") "\"}}}")) |
| Run the app the way it is built: nix run 35e7155 nandi 17d ago | 65 | |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 66 | ;; On NixOS the store's Mesa is the system's and the window opens. Anywhere |
| 67 | ;; else — a bare host, or the distrobox above — the real driver is the host's, |
| 68 | ;; so defer to nixGL, which prepends it. Same rule the flake's launcher uses. |
| 69 | (def runner |
| 70 | (when-not (fs/exists? "/run/current-system") |
| 71 | (some-> (System/getenv "NIXGL") not-empty vector))) |
| Write the build in babashka, and pin the babashka 34832a8 nandi 18d ago | 72 | |
| 73 | (System/exit |
| Run the source on disk, not the source in git 66ba416 nandi 17d ago | 74 | (:exit @(apply p/process |
| 75 | {:inherit true |
| 76 | :dir root |
| 77 | :extra-env {"LD_LIBRARY_PATH" |
| Run this tree on a native half the builders made a32699e nandi 17d ago | 78 | (->> [(System/getenv "JOLT_NATIVE_LIB") |
| 79 | (System/getenv "FRQ_LIB_PATH") |
| 80 | (System/getenv "LD_LIBRARY_PATH")] |
| 81 | (remove str/blank?) |
| 82 | (str/join ":"))}} |
| 83 | (concat runner ["jolt" "-Sdeps" overrides "-M:frq"] *command-line-args*)))) |