diff --git a/.vscode/settings.json b/.vscode/settings.json index 84f5614..cc3d763 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", @@ -25,7 +23,6 @@ "purplepag", "rpassword", "rustup", - "shasum", "strtime", "swatinem", "taiki", @@ -36,6 +33,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..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,11 +55,11 @@ 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 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 +67,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 +126,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 +159,33 @@ 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" +# 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) - if [[ $target == x86_64-* ]]; then - cflags+=" -ffreestanding -nostdlibinc -DRING_CORE_NOSTDLIBINC=1" - fi + local target + for target in "${TARGETS[@]}"; do + if [[ $(asset_name "$target") == "$name" ]]; then + echo "$DIST_DIR/$name" + return + fi + done - 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" + fail "no binary is built for this machine to publish the verifications with" } -# verifies the binaries with hasheus as built for this mac, once they're uploaded -# so their download urls work. +# verifies the binaries 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 publisher=$2 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 + "$publisher" publish --yes --url "$DOWNLOADS_URL/$tag/$name" "$binary" > /dev/null done }