mouse/cheesed

Blob: scripts/build-static.sh

Raw · Blame

#!/bin/sh
set -eu

script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
repo_dir=$(dirname "$script_dir")
target=${CHEESED_TARGET:-x86_64-unknown-linux-musl}

if ! rustup target list --installed | grep -qx "$target"; then
    printf '%s\n' "missing Rust target: $target" >&2
    printf '%s\n' "install it with: rustup target add $target" >&2
    exit 1
fi

(
    cd "$repo_dir"
    cargo build --locked --release --target "$target"
)
binary="$repo_dir/target/$target/release/cheesed"

if ! file "$binary" | grep -Eq 'statically linked|static-pie linked'; then
    printf '%s\n' "release binary is not statically linked: $binary" >&2
    exit 1
fi

printf '%s\n' "$binary"