diff options
Diffstat (limited to 'tmuxrdr/scripts/build')
| -rwxr-xr-x | tmuxrdr/scripts/build | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tmuxrdr/scripts/build b/tmuxrdr/scripts/build new file mode 100755 index 00000000..2305ef73 --- /dev/null +++ b/tmuxrdr/scripts/build @@ -0,0 +1,52 @@ +#!/bin/bash + +# Build tmuxrdr from this checkout and install it as ~/.local/bin/tmuxrdr +# (or $TMUXRDR_BIN). cargo's output is herdr's binary, target/release/herdr; +# the name it is installed under is all the renaming there is -- it starts its +# server from its own path, and src/config/io.rs gives it its own directories. +# +# Toolchains, found without PATH or shell-profile changes: +# Rust the version rust-toolchain.toml pins, through rustup; Homebrew's +# keg-only rustup (/opt/homebrew/opt/rustup/bin) is used when no +# cargo is on PATH +# Zig exactly 0.16.0, which herdr's vendored libghostty-vt requires: +# $ZIG, else ~/.local/opt/zig-0.16.0/zig +# sfw Socket Firewall, which every crate fetch goes through (Zig's +# packages are fetched first, by Zig, hash-checked) +# +# The binary is replaced by a rename, so a running tmuxrdr server keeps the +# old one until it is restarted. + +set -euo pipefail + +repo="$(cd "$(dirname "$0")/../.." && pwd -P)" +dest="${TMUXRDR_BIN:-$HOME/.local/bin/tmuxrdr}" + +die() { >&2 echo "ERROR: $*"; exit 1; } + +if ! command -v cargo >/dev/null && [[ -x /opt/homebrew/opt/rustup/bin/cargo ]]; then + PATH="/opt/homebrew/opt/rustup/bin:$PATH" +fi +command -v cargo >/dev/null || die "no cargo: brew install rustup" +command -v sfw >/dev/null || die "no sfw: crates are fetched through Socket Firewall" + +export ZIG="${ZIG:-$HOME/.local/opt/zig-0.16.0/zig}" +[[ -x "$ZIG" ]] || die "no Zig at $ZIG (needs exactly 0.16.0: ziglang.org/download, signature-checked)" +[[ "$("$ZIG" version)" == "0.16.0" ]] || die "$ZIG is Zig $("$ZIG" version), not 0.16.0" + +cd "$repo" +# Zig's packages are fetched by Zig itself, each checked against the hash +# build.zig.zon pins -- not through sfw, whose proxy breaks Zig's downloads +# (400 Bad Request). With them cached, the build itself needs only crates. +(cd vendor/libghostty-vt && "$ZIG" build --fetch=all) +sfw cargo build --release --locked + +mkdir -p "$(dirname "$dest")" +cp target/release/herdr "$dest.new" +mv -f "$dest.new" "$dest" +echo "installed: $dest ($("$dest" --version))" + +if "$dest" status server 2>/dev/null | grep -q 'status: running'; then + echo "A tmuxrdr server is running the previous build; it switches on its next" + echo "start (tmuxrdr server stop ends it, and its panes)." +fi |
