From 2b476440b20f804012ec28a4483287f025b47176 Mon Sep 17 00:00:00 2001 From: tinfoil hash <238757206+tinfoilhash@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:05:13 -0500 Subject: [PATCH 1/2] build releases on linux with cargo-zigbuild MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zig links macos binaries without an sdk, so one linux machine builds every platform, and the homebrew llvm setup and ring's cflags workaround go away. the macos binaries keep rust's minimum versions (11.0 for arm64, 10.12 for x86-64), like the ones built on a mac, since zig would otherwise target macos 15. > made with claude code + tinfoil hash · session `2f2d708e-2590-4fbb-a068-cd4fdd452239` Co-Authored-By: Claude Opus 5.5 --- .vscode/settings.json | 3 +-- README.md | 11 +++++---- bin/release | 54 +++++++++++++++---------------------------- 3 files changed, 25 insertions(+), 43 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 84f5614..731e9cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,6 @@ "damus", "darwin", "eose", - "ffreestanding", "hasheus", "jiff", "llvm", @@ -15,7 +14,6 @@ "musl", "nak", "ncryptsec", - "nostdlibinc", "nostr", "npub", "nsec", @@ -36,6 +34,7 @@ "xattr", "xdg", "yansi", + "zigbuild", "zstd" ] } diff --git a/README.md b/README.md index 9c94989..bb2933c 100644 --- a/README.md +++ b/README.md @@ -184,13 +184,14 @@ cargo fmt --check && cargo clippy --all-targets -- -D warnings ## releasing -releases are built on a mac, for macos and linux, by -[`bin/release`](bin/release). it needs [homebrew](https://brew.sh/)'s llvm to -build for linux, and the [github cli](https://cli.github.com/), logged in, to -create the release: +releases are built on linux, for macos and linux, by +[`bin/release`](bin/release). it needs [zig](https://ziglang.org/download/) and +[cargo-zigbuild](https://github.com/rust-cross/cargo-zigbuild) to build every +platform, and the [github cli](https://cli.github.com/), logged in, to create +the release: ```bash -brew install llvm gh +cargo install --locked cargo-zigbuild gh auth login ``` diff --git a/bin/release b/bin/release index 7ea81dc..642475d 100755 --- a/bin/release +++ b/bin/release @@ -57,8 +57,8 @@ main() { publish_verifications "v$version" } -# another rust earlier in the PATH (like homebrew's) ignores rust-toolchain.toml -# and the targets rustup adds. +# another rust earlier in the PATH (like a package manager's) ignores +# rust-toolchain.toml and the targets rustup adds. use_rustup_toolchain() { local cargo_path cargo_path=$(rustup which cargo) @@ -66,16 +66,18 @@ use_rustup_toolchain() { } check_tools() { - LLVM_BIN=${LLVM_BIN:-$(brew --prefix llvm 2> /dev/null || true)/bin} + if ! command -v zig > /dev/null; then + fail "zig is required to build every platform: https://ziglang.org/download/" + fi - if [[ ! -x $LLVM_BIN/clang || ! -x $LLVM_BIN/llvm-ar ]]; then - fail "llvm is required to build for linux: brew install llvm" + if ! command -v cargo-zigbuild > /dev/null; then + fail "cargo-zigbuild is required to build every platform: cargo install --locked cargo-zigbuild" fi } check_gh() { if ! command -v gh > /dev/null; then - fail "gh is required to create the release: brew install gh" + fail "gh is required to create the release: https://cli.github.com/" fi if ! gh auth status > /dev/null 2>&1; then @@ -123,15 +125,18 @@ check_release_commit() { fi } +# zig links macos binaries without an sdk, but targets its own minimum macos +# version, so this keeps rust's lower one. build() { local target=$1 case $target in *-apple-darwin) - cargo build --locked --release --target "$target" + env "$(rustc --print deployment-target --target "$target")" \ + cargo zigbuild --locked --release --target "$target" ;; *-unknown-linux-musl) - build_for_linux "$target" + cargo zigbuild --locked --release --target "$target" ;; *) fail "no way to build for $target" @@ -153,41 +158,18 @@ asset_name() { esac } -# ring's c is compiled without any libc headers, so no linux sysroot is needed. -# ring only does that itself for arm, so x86-64 also has to be freestanding to -# keep clang's intrinsics from including stdlib.h. -build_for_linux() { - local target=$1 - local env_target=${target//-/_} - local cargo_target - cargo_target=$(echo "$env_target" | tr '[:lower:]' '[:upper:]') - local cflags="--target=$target" - - if [[ $target == x86_64-* ]]; then - cflags+=" -ffreestanding -nostdlibinc -DRING_CORE_NOSTDLIBINC=1" - fi - - env \ - "CC_$env_target=$LLVM_BIN/clang" \ - "AR_$env_target=$LLVM_BIN/llvm-ar" \ - "CFLAGS_$env_target=$cflags" \ - "CARGO_TARGET_${cargo_target}_LINKER=rust-lld" \ - "CARGO_TARGET_${cargo_target}_RUSTFLAGS=-C link-self-contained=yes" \ - cargo build --locked --release --target "$target" -} - -# verifies the binaries with hasheus as built for this mac, once they're uploaded -# so their download urls work. +# verifies the binaries with hasheus as built for this machine, once they're +# uploaded so their download urls work. publish_verifications() { local tag=$1 - local host - host=$(rustc -vV | sed -n 's/^host: //p') + local hasheus + hasheus="$DIST_DIR/hasheus-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)" local binary name for binary in "$DIST_DIR"/hasheus-*; do name=${binary##*/} echo "verifying $name" - "target/$host/release/hasheus" publish --yes --url "$DOWNLOADS_URL/$tag/$name" "$binary" > /dev/null + "$hasheus" publish --yes --url "$DOWNLOADS_URL/$tag/$name" "$binary" > /dev/null done } From 0551f42daf5a9c93dc03d1e1e39abc50b57096a9 Mon Sep 17 00:00:00 2001 From: tinfoil hash <238757206+tinfoilhash@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:11:30 -0500 Subject: [PATCH 2/2] address feedback from codex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > made with claude code + tinfoil hash · session `2f2d708e-2590-4fbb-a068-cd4fdd452239` Co-Authored-By: Claude Opus 5.5 --- .vscode/settings.json | 1 - bin/release | 32 ++++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 731e9cc..cc3d763 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,7 +23,6 @@ "purplepag", "rpassword", "rustup", - "shasum", "strtime", "swatinem", "taiki", diff --git a/bin/release b/bin/release index 642475d..3b55657 100755 --- a/bin/release +++ b/bin/release @@ -25,9 +25,10 @@ main() { use_rustup_toolchain check_tools - local version + local version publisher version=$(read_version) if [[ $is_dry_run == false ]]; then + publisher=$(find_publisher) check_gh check_publishing_env check_release_commit "v$version" @@ -46,7 +47,7 @@ main() { cp "target/$target/release/hasheus" "$DIST_DIR/$name" done - (cd "$DIST_DIR" && shasum -a 256 hasheus-* > SHA256SUMS) + (cd "$DIST_DIR" && sha256sum hasheus-* > SHA256SUMS) if [[ $is_dry_run == true ]]; then echo "built v$version in $DIST_DIR" @@ -54,7 +55,7 @@ main() { fi gh release create "v$version" --verify-tag --generate-notes "$DIST_DIR"/* - publish_verifications "v$version" + publish_verifications "v$version" "$publisher" } # another rust earlier in the PATH (like a package manager's) ignores @@ -158,18 +159,33 @@ asset_name() { esac } -# verifies the binaries with hasheus as built for this machine, once they're -# uploaded so their download urls work. +# the binary built for this machine publishes the verifications, so a machine +# that isn't one of the targets fails here, before the release is created. +find_publisher() { + local name + name=hasheus-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) + + local target + for target in "${TARGETS[@]}"; do + if [[ $(asset_name "$target") == "$name" ]]; then + echo "$DIST_DIR/$name" + return + fi + done + + fail "no binary is built for this machine to publish the verifications with" +} + +# verifies the binaries once they're uploaded, so their download urls work. publish_verifications() { local tag=$1 - local hasheus - hasheus="$DIST_DIR/hasheus-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)" + local publisher=$2 local binary name for binary in "$DIST_DIR"/hasheus-*; do name=${binary##*/} echo "verifying $name" - "$hasheus" publish --yes --url "$DOWNLOADS_URL/$tag/$name" "$binary" > /dev/null + "$publisher" publish --yes --url "$DOWNLOADS_URL/$tag/$name" "$binary" > /dev/null done }