Files
lucisv/tools/release.sh
T
lucioandClaude Fable 5 a399f81ad9
ci / checks (push) Successful in 41s
ci / corpus (push) Successful in 19s
Platform-specific VSIXs: five packages with the binaries inside
release.sh --cross now cuts a .vsix per platform — darwin-arm64,
darwin-x64, linux-x64, linux-arm64 (new aarch64-musl cross target),
win32-x64 — each carrying lucisv and lucisv-server under bin/, staged
transiently with an EXIT trap and content-asserted with unzip. The
extension resolves a user-set lucisv.serverPath, then the bundled
server (chmod'ed on activation; VSIX extraction drops the exec bit),
then PATH; the universal no-binary .vsix stays as the fallback. The
host package's embedded server is smoke-tested out of the zip on every
release. docs/features/editor-platform-vsix has the full round.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-27 00:55:53 -07:00

251 lines
10 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/lucisv-<version>-darwin-arm64.vsix (the same extension, with the
# host binaries inside it -- no PATH
# setup needed; docs/features/editor-platform-vsix)
# dist/SHA256SUMS
#
# Standard tooling only -- cargo, npm, shasum and unzip (the last only to
# check what the packages ended up containing), nothing installed globally.
# With --cross it also builds x86_64 macOS, static-musl Linux (x86-64 and
# aarch64) and Windows binaries, when the toolchains are present (rustup
# stable + the five targets, and mingw-w64 for Windows; see
# tools/RELEASING.md), plus the four remaining platform-specific .vsix
# packages. 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
# Where a platform package's binaries are staged, one target at a time. It must
# never outlive a packaging step: a leftover bin/ would put the previous
# target's binaries into the next package -- or into the universal one, whose
# whole point is carrying none. The trap covers the failure and Ctrl-C paths;
# every success path removes it explicitly as well.
bin_dir=$repo_root/editors/vscode/bin
trap 'rm -rf "$bin_dir"' EXIT
rm -rf "$bin_dir"
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
# Same recipe, other architecture: rust-lld cross-links aarch64 as happily as
# x86-64, so this needs no C toolchain of its own -- only the rust-std
# component (`rustup target add`, see tools/RELEASING.md).
cross_build aarch64-unknown-linux-musl \
DYLD_FALLBACK_LIBRARY_PATH="$tc/lib" \
CARGO_TARGET_AARCH64_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 aarch64-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
# vsce names platforms its own way and rustc names triples; this table is the
# whole translation. An unlisted triple gets no platform package -- notably
# x86_64-unknown-linux-gnu, because `linux-x64` ships the *musl* build: a
# statically linked server runs on any distro, which is what an extension
# installed by a stranger needs (docs/features/editor-platform-vsix).
vsce_target_for() { # rust triple -> vsce target name, empty if we ship none
case $1 in
aarch64-apple-darwin) echo darwin-arm64 ;;
x86_64-apple-darwin) echo darwin-x64 ;;
x86_64-unknown-linux-musl) echo linux-x64 ;;
aarch64-unknown-linux-musl) echo linux-arm64 ;;
x86_64-pc-windows-gnu) echo win32-x64 ;;
*) echo "" ;;
esac
}
# What a package carries under bin/ is the contract extension.js resolves
# against, so it is asserted rather than assumed: the universal package must
# carry nothing, a platform package exactly its two binaries.
expect_vsix_bins() { # vsix file name, then the extension/bin entries expected
vsix=$1; shift
got=$(unzip -Z1 "$dist/$vsix" 'extension/bin/*' 2>/dev/null | LC_ALL=C sort | tr '\n' ' ')
if [ $# -eq 0 ]; then
want=""
else
want=$(printf '%s\n' "$@" | LC_ALL=C sort | tr '\n' ' ')
fi
if [ "$got" != "$want" ]; then
echo "error: $vsix carries bin/ entries [$got], expected [$want]" >&2
exit 1
fi
echo " $vsix: bin/ contents ok"
}
package_vsix() { # vsce target, rust triple
vsce_target=$1
triple=$2
case $triple in *windows*) exe=.exe ;; *) exe="" ;; esac
echo "==> packaging the VS Code extension for $vsce_target ($triple)"
# Plain names inside the package: extension.js looks for bin/lucisv-server,
# with no version and no triple in it, on every platform.
mkdir -p "$bin_dir"
cp "$dist/lucisv-$version-$triple$exe" "$bin_dir/lucisv$exe"
cp "$dist/lucisv-server-$version-$triple$exe" "$bin_dir/lucisv-server$exe"
chmod +x "$bin_dir/lucisv$exe" "$bin_dir/lucisv-server$exe"
(
cd "$repo_root/editors/vscode"
npx @vscode/vsce package --target "$vsce_target" \
--out "$dist/lucisv-$version-$vsce_target.vsix"
)
rm -rf "$bin_dir"
expect_vsix_bins "lucisv-$version-$vsce_target.vsix" \
"extension/bin/lucisv$exe" "extension/bin/lucisv-server$exe"
vsix_built="$vsix_built lucisv-$version-$vsce_target.vsix"
}
vsix_built=""
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.
#
# The universal package goes first, with bin/ provably gone: it is the one
# that must never carry a binary, being the fallback for every platform we
# do not build for.
rm -rf "$bin_dir"
(
cd "$repo_root/editors/vscode"
npm ci
npx @vscode/vsce package --out "$dist/lucisv-$version.vsix"
)
expect_vsix_bins "lucisv-$version.vsix"
vsix_built=" lucisv-$version.vsix"
# Without --cross only the host's binaries exist, so only the host package
# can be built -- and it is, so that the packaging path and the embedded
# smoke test below run on every ordinary release too.
vsix_triples=$host
if [ "$want_cross" -eq 1 ]; then
vsix_triples="$host x86_64-apple-darwin x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-pc-windows-gnu"
fi
for triple in $vsix_triples; do
vsce_target=$(vsce_target_for "$triple")
[ -n "$vsce_target" ] || continue
package_vsix "$vsce_target" "$triple"
done
# The host package gets one more check: unzip it and drive the *embedded*
# server through a full LSP session, so "install the extension and it works"
# is proven against a binary that has been through the zip rather than
# against the one in dist/. unzip does not restore the executable bit
# reliably -- the same reason extension.js chmods what it spawns.
host_vsce_target=$(vsce_target_for "$host")
if [ -n "$host_vsce_target" ] && command -v node >/dev/null 2>&1; then
echo "==> smoke-testing the server embedded in the $host_vsce_target package"
unpacked=$repo_root/target/vsix-check
rm -rf "$unpacked"
unzip -q "$dist/lucisv-$version-$host_vsce_target.vsix" -d "$unpacked"
chmod +x "$unpacked/extension/bin/lucisv" "$unpacked/extension/bin/lucisv-server"
node "$repo_root/editors/vscode/smoke.js" "$unpacked/extension/bin/lucisv-server"
rm -rf "$unpacked"
fi
fi
echo "==> checksums"
artifacts="lucisv-$version-$host lucisv-server-$version-$host$cross_built$vsix_built"
(
# 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"