57 lines
2.3 KiB
Bash
Executable File
57 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Build a host-target archive only. No tags, uploads, installers or signing.
|
|
repo_root=$(cd "$(dirname "$0")/.." && pwd)
|
|
cd "$repo_root"
|
|
version=$(sed -n 's/^version = "\([^"]*\)"/\1/p' Cargo.toml)
|
|
target=$(rustc -vV | sed -n 's/^host: //p')
|
|
revision=${SIZED_SOURCE_REVISION:-$(git rev-parse HEAD 2>/dev/null || printf unknown)}
|
|
destination="$repo_root/dist/sized-v$version-$target-${revision:0:12}"
|
|
if [[ $# == 2 && $1 == --output-dir ]]; then
|
|
destination=$2
|
|
elif [[ $# != 0 ]]; then
|
|
printf 'Usage: %s [--output-dir ABSOLUTE_PATH]\n' "$0" >&2
|
|
exit 2
|
|
fi
|
|
[[ $destination == /* ]] || { printf 'Output directory must be absolute.\n' >&2; exit 2; }
|
|
for output in "$destination" "$destination.tar.gz" "$destination.tar.gz.sha256"; do
|
|
[[ ! -e $output ]] || { printf 'Refusing to replace %s\n' "$output" >&2; exit 1; }
|
|
done
|
|
|
|
target_dir=${CARGO_TARGET_DIR:-"$repo_root/target"}
|
|
[[ $target_dir == /* ]] || target_dir="$repo_root/$target_dir"
|
|
cargo build --locked --release --target "$target"
|
|
binary="$target_dir/$target/release/sized"
|
|
mkdir -p "$destination"
|
|
install -m 755 "$binary" "$destination/sized"
|
|
"$binary" --generate-man-page "$destination"
|
|
"$binary" --completions bash > "$destination/sized.bash"
|
|
"$binary" --completions zsh > "$destination/_sized"
|
|
"$binary" --completions fish > "$destination/sized.fish"
|
|
cp LICENSE README.md MANUAL.md "$destination/"
|
|
{
|
|
printf 'Version: %s\nTarget: %s\nSource revision: %s\n' "$version" "$target" "$revision"
|
|
printf 'Source worktree: '
|
|
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
if git diff --quiet HEAD --; then printf 'clean tracked files\n'; else printf 'modified tracked files\n'; fi
|
|
else
|
|
printf 'exported source; verify against supplied revision\n'
|
|
fi
|
|
rustc --version
|
|
cargo --version
|
|
printf 'Unsigned host build; not a notarized Mac application.\n'
|
|
} > "$destination/BUILD-INFO.txt"
|
|
|
|
tar -czf "$destination.tar.gz" -C "$destination" .
|
|
(
|
|
cd "$(dirname "$destination")"
|
|
archive="$(basename "$destination").tar.gz"
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
sha256sum "$archive" > "$archive.sha256"
|
|
else
|
|
shasum -a 256 "$archive" > "$archive.sha256"
|
|
fi
|
|
)
|
|
printf 'Archive: %s.tar.gz\nChecksum: %s.tar.gz.sha256\n' "$destination" "$destination"
|