#!/usr/bin/env bash # Build lucisv's release artifacts into dist/ and checksum them. # # Produces, for the machine it runs on: # dist/lucisv-- # dist/lucisv-server-- # dist/lucisv-mcp-- (the MCP server for coding agents; # docs/features/mcp-packaging) # dist/lucisv-.vsix (the VS Code extension; sideload it) # dist/lucisv--darwin-arm64.vsix (the same extension, with the # three 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 and # dist/lucisv--all.vsix (every platform's three binaries in one package, # under bin/-/ directories # extension.js selects from at runtime) # -- seven packages in all. The all-platforms one needs all five sets, so it # exists only on a --cross run. 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 -p lucisv_mcp # 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" # The extension's two version files must say the same number # (tools/RELEASING.md step 1); package-lock.json sat at 0.10.2 for fifty # releases because nothing checked it. ext_dir="$repo_root/editors/vscode" for pinned in \ "$(node -p "require('$ext_dir/package.json').version")" \ "$(node -p "require('$ext_dir/package-lock.json').version")" \ "$(node -p "require('$ext_dir/package-lock.json').packages[''].version")"; do if [ "$pinned" != "$version" ]; then echo "error: editors/vscode says version $pinned, lucisv --version says $version" >&2 exit 1 fi done 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" cp "$repo_root/target/release/lucisv-mcp" "$dist/lucisv-mcp-$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 -p lucisv_mcp } 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" cp "$repo_root/target/$triple/release/lucisv-mcp$exe" "$dist/lucisv-mcp-$version-$triple$exe" cross_built="$cross_built lucisv-$version-$triple$exe lucisv-server-$version-$triple$exe lucisv-mcp-$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`. # The MCP server gets the same treatment from `mcp_smoke.js`: initialize, # tools/list (the nine tools, in order) and one `hierarchy` over stdio against a # tiny temp project; then again with `--read-only` (the five read tools, and # `rename` answered with the unknown-tool error). 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" echo "==> smoke-testing the MCP server binary" node "$repo_root/editors/vscode/mcp_smoke.js" "$dist/lucisv-mcp-$version-$host" node "$repo_root/editors/vscode/mcp_smoke.js" "$dist/lucisv-mcp-$version-$host" --read-only else echo " note: no node on PATH, skipping the server and MCP smoke tests" >&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 three binaries, the all-platforms # package exactly fifteen under five subdirectories. Info-ZIP's `*` matches `/` # too (unlike a shell glob), so the one pattern covers the nested layout as # well -- and vsce writes no directory entries, so nothing but files comes back. 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 # (and mcp.js for bin/lucisv-mcp), 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" cp "$dist/lucisv-mcp-$version-$triple$exe" "$bin_dir/lucisv-mcp$exe" chmod +x "$bin_dir/lucisv$exe" "$bin_dir/lucisv-server$exe" "$bin_dir/lucisv-mcp$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" "extension/bin/lucisv-mcp$exe" vsix_built="$vsix_built lucisv-$version-$vsce_target.vsix" } # One package for every platform at once: each set of three under bin/-/, # the exact string extension.js builds from `process.platform`/`process.arch` to # pick its own. Deliberately packaged with no --target, like the universal one, # so VS Code offers it to any machine -- including the ones vsce calls alpine-x64 # and alpine-arm64, where our static-musl Linux binaries run perfectly but a # linux-x64-targeted package is never even offered. The price is that every user # downloads every platform's binaries (docs/features/editor-platform-vsix). package_all_vsix() { # rust triples, one per platform to carry echo "==> packaging the VS Code extension for all platforms" rm -rf "$bin_dir" all_bins="" for triple in "$@"; do vsce_target=$(vsce_target_for "$triple") [ -n "$vsce_target" ] || continue case $triple in *windows*) exe=.exe ;; *) exe="" ;; esac mkdir -p "$bin_dir/$vsce_target" cp "$dist/lucisv-$version-$triple$exe" "$bin_dir/$vsce_target/lucisv$exe" cp "$dist/lucisv-server-$version-$triple$exe" "$bin_dir/$vsce_target/lucisv-server$exe" cp "$dist/lucisv-mcp-$version-$triple$exe" "$bin_dir/$vsce_target/lucisv-mcp$exe" chmod +x "$bin_dir/$vsce_target/lucisv$exe" "$bin_dir/$vsce_target/lucisv-server$exe" \ "$bin_dir/$vsce_target/lucisv-mcp$exe" all_bins="$all_bins extension/bin/$vsce_target/lucisv$exe extension/bin/$vsce_target/lucisv-server$exe" all_bins="$all_bins extension/bin/$vsce_target/lucisv-mcp$exe" done ( cd "$repo_root/editors/vscode" npx @vscode/vsce package --out "$dist/lucisv-$version-all.vsix" ) rm -rf "$bin_dir" # shellcheck disable=SC2086 # deliberate word splitting: one arg per entry expect_vsix_bins "lucisv-$version-all.vsix" $all_bins vsix_built="$vsix_built lucisv-$version-all.vsix" } # Unzip a package and drive the server it carries 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. smoke_embedded_server() { # vsix file name, the bin/ path inside the package vsix=$1 inner=$2 echo "==> smoke-testing the server embedded in $vsix" unpacked=$repo_root/target/vsix-check rm -rf "$unpacked" unzip -q "$dist/$vsix" -d "$unpacked" chmod +x "$unpacked/$inner/lucisv" "$unpacked/$inner/lucisv-server" "$unpacked/$inner/lucisv-mcp" node "$repo_root/editors/vscode/smoke.js" "$unpacked/$inner/lucisv-server" rm -rf "$unpacked" } # The same for the MCP server the package carries: unzipped, then driven through # initialize, tools/list and one `hierarchy` by `mcp_smoke.js`, in both modes. smoke_embedded_mcp() { # vsix file name, the bin/ path inside the package vsix=$1 inner=$2 echo "==> smoke-testing the MCP server embedded in $vsix" unpacked=$repo_root/target/vsix-check rm -rf "$unpacked" unzip -q "$dist/$vsix" -d "$unpacked" chmod +x "$unpacked/$inner/lucisv-mcp" node "$repo_root/editors/vscode/mcp_smoke.js" "$unpacked/$inner/lucisv-mcp" node "$repo_root/editors/vscode/mcp_smoke.js" "$unpacked/$inner/lucisv-mcp" --read-only rm -rf "$unpacked" } 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 all-platforms package carries all five sets, so it can only be built # when all five exist -- which is exactly what --cross means here. if [ "$want_cross" -eq 1 ]; then # shellcheck disable=SC2086 # deliberate word splitting: one arg per triple package_all_vsix $vsix_triples fi # Two packages get two more checks each: unzip and drive the *embedded* server # through a full LSP session, and the embedded MCP server through an MCP one. # The host platform package proves the flat bin/ layout, the all-platforms # package proves the bin/-/ one -- the two layouts # extension.js resolves against, both tested against binaries that have # actually been through a zip. host_vsce_target=$(vsce_target_for "$host") if [ -n "$host_vsce_target" ] && command -v node >/dev/null 2>&1; then smoke_embedded_server "lucisv-$version-$host_vsce_target.vsix" extension/bin smoke_embedded_mcp "lucisv-$version-$host_vsce_target.vsix" extension/bin if [ "$want_cross" -eq 1 ]; then smoke_embedded_server "lucisv-$version-all.vsix" "extension/bin/$host_vsce_target" smoke_embedded_mcp "lucisv-$version-all.vsix" "extension/bin/$host_vsce_target" fi fi fi echo "==> checksums" artifacts="lucisv-$version-$host lucisv-server-$version-$host lucisv-mcp-$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"