Files
lucisv/tools/release.sh
T
lucioandClaude Fable 5 a9d73913f5 Cross-platform release: x86_64 macOS, Linux, Windows; author metadata
tools/release.sh --cross builds, next to the host Apple Silicon pair,
x86_64-apple-darwin (runs under Rosetta here, full smoke passed),
x86_64-unknown-linux-musl (static, no glibc dependency) and
x86_64-pc-windows-gnu (.exe depending only on DLLs Windows 10+ ships,
audited). The rustup stable toolchain is addressed by absolute path so
the Homebrew rust on PATH keeps owning day-to-day builds; the musl link
needs DYLD_FALLBACK_LIBRARY_PATH for rust-lld's libLLVM, the Windows
link needs mingw-w64's import libraries - both encoded in the script and
RELEASING.md so nobody rediscovers them. Author metadata: Cargo.toml
authors, package.json publisher guoliangchen + author, LICENSE holder -
all Guoliang Chen.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-25 10:33:15 -07:00

133 lines
4.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build vfmt's release artifacts into dist/ and checksum them.
#
# Produces, for the machine it runs on:
# dist/vfmt-<version>-<host-triple>
# dist/vfmt-server-<version>-<host-triple>
# dist/vfmt-<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 vfmt -p vfmt_server
# The binaries themselves are the authority on the version, not Cargo.toml:
# `vfmt --version` is what a user will quote in a bug report.
version=$("$repo_root/target/release/vfmt" --version | awk '{print $2}')
host=$(rustc -vV | awk '/^host:/{print $2}')
echo " vfmt $version, host $host"
rm -rf "$dist"
mkdir -p "$dist"
cp "$repo_root/target/release/vfmt" "$dist/vfmt-$version-$host"
cp "$repo_root/target/release/vfmt-server" "$dist/vfmt-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 vfmt -p vfmt_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-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-pc-windows-gnu; do
case $triple in *windows*) exe=.exe ;; *) exe="" ;; esac
cp "$repo_root/target/$triple/release/vfmt$exe" "$dist/vfmt-$version-$triple$exe"
cp "$repo_root/target/$triple/release/vfmt-server$exe" "$dist/vfmt-server-$version-$triple$exe"
cross_built="$cross_built vfmt-$version-$triple$exe vfmt-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/vfmt-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/vfmt-$version.vsix"
)
fi
echo "==> checksums"
artifacts="vfmt-$version-$host vfmt-server-$version-$host$cross_built"
if [ "$want_vsix" -eq 1 ]; then
artifacts="$artifacts vfmt-$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"