#!/usr/bin/env sh # Builds a static Linux libbui for one musl target and runs it once to prove # it starts: natively when the target matches this machine, otherwise under # qemu-user. The release workflow builds every Linux binary with this, and # scripts/riscv64.sh is this script for riscv64. Needs rustup, zig and # cargo-zigbuild. # # scripts/static-linux.sh x86_64-unknown-linux-musl # scripts/static-linux.sh aarch64-unknown-linux-musl # QEMU=qemu-aarch64-static scripts/static-linux.sh aarch64-unknown-linux-musl # REQUIRE_QEMU=1 scripts/static-linux.sh ... # fail instead of skipping the run set -eu if [ $# -ne 1 ]; then echo "usage: $0 , such as x86_64-unknown-linux-musl" >&2 exit 2 fi target=$1 case "$target" in *-linux-musl) ;; *) echo "error: $target is not a musl target; only musl builds are static" >&2 exit 2 ;; esac # riscv64gc-unknown-linux-musl runs on qemu-riscv64. arch="${target%%-*}" arch="${arch%gc}" cd "$(dirname "$0")/.." rustup target add "$target" >/dev/null cargo zigbuild --locked --release -p libbui --target "$target" binary="${CARGO_TARGET_DIR:-target}/$target/release/libbui" # A static binary has no interpreter: it must run on any Linux of its # architecture, Alpine and the browser's aarch64 machine included. if readelf -l "$binary" | grep -q 'Requesting program interpreter'; then echo "error: $binary is dynamically linked" >&2 exit 1 fi if [ "$arch" = "$(uname -m)" ] && [ "$(uname -s)" = Linux ]; then runner="" where=natively else runner="${QEMU:-qemu-$arch}" where="under $runner" if ! command -v "$runner" >/dev/null 2>&1; then if [ "${REQUIRE_QEMU:-0}" = 1 ]; then echo "error: $runner not found and REQUIRE_QEMU=1; the binary was never run" >&2 exit 1 fi echo "warning: $runner not found; built but not run" >&2 sha256sum "$binary" exit 0 fi fi # $runner is empty for a native run, so it must stay unquoted. # shellcheck disable=SC2086 $runner "$binary" --version # shellcheck disable=SC2086 $runner "$binary" --help >/dev/null # shellcheck disable=SC2086 HOME="$(mktemp -d)" $runner "$binary" paths --json >/dev/null echo "smoke test passed $where" sha256sum "$binary"