Files
lucisv/tools/release.sh
T

141 lines
5.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build lucisv's release artifacts into dist/ and checksum them.
#
# Produces, for the machine it runs on:
# dist/lucisv-<version>-<host-triple>
# dist/lucisv-server-<version>-<host-triple>
# dist/lucisv-<version>.vsix (the VS Code extension; sideload it)
# dist/SHA256SUMS
#
# Standard tooling only -- cargo, npm and shasum, nothing installed globally.
# With --cross it also builds x86_64 macOS, static-musl Linux and Windows
# binaries, when the toolchains are present (rustup stable + the three
# targets, and mingw-w64 for Windows; see tools/RELEASING.md). It publishes
# nothing anywhere.
#
# Usage: tools/release.sh [-o dist-dir] [--no-vsix] [--cross]
#
# Exit status: 0 if every requested artifact was built and checksummed.
set -eu
repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
dist=$repo_root/dist
want_vsix=1
want_cross=0
while [ $# -gt 0 ]; do
case $1 in
-o) dist=$2; shift 2 ;;
--no-vsix) want_vsix=0; shift ;;
--cross) want_cross=1; shift ;;
*) echo "usage: $0 [-o dist-dir] [--no-vsix] [--cross]" >&2; exit 2 ;;
esac
done
case $dist in
/*) ;;
*) dist=$repo_root/$dist ;;
esac
echo "==> building release binaries"
cargo build --release --manifest-path "$repo_root/Cargo.toml" \
-p lucisv -p lucisv_server
# The binaries themselves are the authority on the version, not Cargo.toml:
# `lucisv --version` is what a user will quote in a bug report.
version=$("$repo_root/target/release/lucisv" --version | awk '{print $2}')
host=$(rustc -vV | awk '/^host:/{print $2}')
echo " lucisv $version, host $host"
rm -rf "$dist"
mkdir -p "$dist"
cp "$repo_root/target/release/lucisv" "$dist/lucisv-$version-$host"
cp "$repo_root/target/release/lucisv-server" "$dist/lucisv-server-$version-$host"
# Cross targets: each built only if its toolchain is available, each an
# explicit failure otherwise -- a release with silently missing platforms is
# worse than one that says why. The rustup toolchain is addressed by absolute
# path so the Homebrew rust on PATH keeps owning the host build above.
cross_built=""
if [ "$want_cross" -eq 1 ]; then
tc=$HOME/.rustup/toolchains/stable-aarch64-apple-darwin
if [ ! -x "$tc/bin/cargo" ]; then
echo "error: --cross needs the rustup stable toolchain (see tools/RELEASING.md)" >&2
exit 2
fi
cross_build() { # triple, extra env as VAR=VAL args
triple=$1; shift
echo "==> building for $triple"
env RUSTC="$tc/bin/rustc" "$@" \
"$tc/bin/cargo" build --release --manifest-path "$repo_root/Cargo.toml" \
--target "$triple" -p lucisv -p lucisv_server
}
exe=""
cross_build x86_64-apple-darwin
cross_build x86_64-unknown-linux-musl \
DYLD_FALLBACK_LIBRARY_PATH="$tc/lib" \
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=rust-lld
if command -v x86_64-unknown-linux-gnu-gcc >/dev/null 2>&1; then
cross_build x86_64-unknown-linux-gnu \
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
else
echo "error: --cross needs the linux-gnu toolchain for the RHEL-compatible build" >&2
echo " (brew install messense/macos-cross-toolchains/x86_64-unknown-linux-gnu)" >&2
exit 2
fi
if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
cross_build x86_64-pc-windows-gnu \
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc
else
echo "error: --cross needs mingw-w64 for the Windows build (brew install mingw-w64)" >&2
exit 2
fi
for triple in x86_64-apple-darwin x86_64-unknown-linux-musl x86_64-unknown-linux-gnu x86_64-pc-windows-gnu; do
case $triple in *windows*) exe=.exe ;; *) exe="" ;; esac
cp "$repo_root/target/$triple/release/lucisv$exe" "$dist/lucisv-$version-$triple$exe"
cp "$repo_root/target/$triple/release/lucisv-server$exe" "$dist/lucisv-server-$version-$triple$exe"
cross_built="$cross_built lucisv-$version-$triple$exe lucisv-server-$version-$triple$exe"
done
fi
# Prove the server binary still speaks LSP before it is handed to anyone.
# `smoke.js` is plain node with no dependencies, so this runs before `npm ci`.
if command -v node >/dev/null 2>&1; then
echo "==> smoke-testing the server binary"
node "$repo_root/editors/vscode/smoke.js" "$dist/lucisv-server-$version-$host"
else
echo " note: no node on PATH, skipping the server smoke test" >&2
fi
if [ "$want_vsix" -eq 1 ]; then
echo "==> packaging the VS Code extension"
# `vsce` shells out to `npm list` and globs the paths it prints back, so it
# must run from a plain path: under a directory whose name has the shape the
# session sandbox rewrites, it silently collects zero files and fails with
# "Extension entrypoint(s) missing". The repo itself is such a plain path,
# which is why this packages in place and only the output goes to -o.
(
cd "$repo_root/editors/vscode"
npm ci
npx @vscode/vsce package --out "$dist/lucisv-$version.vsix"
)
fi
echo "==> checksums"
artifacts="lucisv-$version-$host lucisv-server-$version-$host$cross_built"
if [ "$want_vsix" -eq 1 ]; then
artifacts="$artifacts lucisv-$version.vsix"
fi
(
# Relative names, so `shasum -c SHA256SUMS` works from inside dist/.
cd "$dist"
# shellcheck disable=SC2086 # deliberate word splitting: one name per file
shasum -a 256 $artifacts > SHA256SUMS
cat SHA256SUMS
)
echo
echo "artifacts in $dist:"
ls -l "$dist"