diff --git a/iris/run-headless.sh b/iris/run-headless.sh index e253b88..3daa305 100755 --- a/iris/run-headless.sh +++ b/iris/run-headless.sh @@ -4,6 +4,16 @@ # ./run-headless.sh tabs [-- cargo args] # ./run-headless.sh tabs --shot /tmp/tabs.png --seconds 4 # +# `--bin` runs a real crate binary instead of an example (E4's +# `desktop-app`, which is a window a person runs, not a demo) -- +# `cargo build --bin NAME` instead of `--example NAME`, and +# `target/debug/NAME` instead of `target/debug/examples/NAME`. Its own +# argv (the CLI flags a real binary takes, as opposed to `cargo build`'s +# own flags after `--`) comes through `$RUN_HEADLESS_ARGS`, word-split on +# purpose -- an example never needed one, so there was nowhere to plumb it +# through positionally without disturbing the existing `-- cargo args` +# convention above. +# # The VM has a virtio-gpu render node (Vulkan 1.4 through Venus, GL 4.6 # through virgl), so wgpu runs on the host's real GPU -- what is missing is # only a compositor to give winit a surface. So: a headless sway, the same @@ -20,16 +30,18 @@ run="${XDG_RUNTIME_DIR:-/tmp}/iris-headless" seconds=3 shot="" example="" +kind=example while [ $# -gt 0 ]; do case "$1" in --shot) shot=$2; shift 2 ;; --seconds) seconds=$2; shift 2 ;; + --bin) kind=bin; shift ;; --) shift; break ;; *) example=$1; shift ;; esac done -[ -n "$example" ] || { echo "usage: $0 EXAMPLE [--shot PNG] [--seconds N] [-- cargo args]" >&2; exit 2; } +[ -n "$example" ] || { echo "usage: $0 NAME [--bin] [--shot PNG] [--seconds N] [-- cargo args]" >&2; exit 2; } mkdir -p "$run" export SWAYSOCK="$run/sway.sock" @@ -67,10 +79,17 @@ export WAYLAND_DISPLAY echo "run-headless: $WAYLAND_DISPLAY (sway $(swaymsg -t get_version --raw | sed -n 's/.*"human_readable":"\([^"]*\)".*/\1/p'))" >&2 cd "$here" -cargo build --example "$example" "$@" >&2 -bin="$here/target/debug/examples/$example" +if [ "$kind" = bin ]; then + cargo build --bin "$example" "$@" >&2 + bin="$here/target/debug/$example" +else + cargo build --example "$example" "$@" >&2 + bin="$here/target/debug/examples/$example" +fi -"$bin" >"$run/$example.log" 2>&1 & +# shellcheck disable=SC2086 -- deliberately word-split: this is the +# binary's own argv, not a single path. +"$bin" ${RUN_HEADLESS_ARGS:-} >"$run/$example.log" 2>&1 & pid=$! trap 'kill "$pid" 2>/dev/null || true' EXIT INT TERM