Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"damus",
"darwin",
"eose",
"ffreestanding",
"hasheus",
"jiff",
"llvm",
"localappdata",
"musl",
"nak",
"ncryptsec",
"nostdlibinc",
"nostr",
"npub",
"nsec",
Expand All @@ -25,7 +23,6 @@
"purplepag",
"rpassword",
"rustup",
"shasum",
"strtime",
"swatinem",
"taiki",
Expand All @@ -36,6 +33,7 @@
"xattr",
"xdg",
"yansi",
"zigbuild",
"zstd"
]
}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
68 changes: 33 additions & 35 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,36 +47,38 @@ 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"
return
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)
PATH="$(dirname "$cargo_path"):$PATH"
}

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
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand Down