Skip to content

Commit

Permalink
Add a script to repeatably generate linux-arm64 and darwin-arm64
Browse files Browse the repository at this point in the history
…builds (#380)

* Simplify Builds

* Copy out caching

* Copy out caching

* Safer rm

* Use pnpm

* Add ARM check
  • Loading branch information
penalosa authored Feb 15, 2023
1 parent 4a047a7 commit 65273d9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 72 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ node_modules
/rust-project.json
# Directory where clangd puts its indexing work
/.cache/

/.bazel-cache

/workerd-*
17 changes: 17 additions & 0 deletions Dockerfile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:bullseye AS builder

WORKDIR /workerd

RUN apt-get update
RUN apt-get install -y curl clang libc++-dev libc++abi-dev

COPY . .
COPY .bazel-cache /bazel-disk-cache
RUN npm install -g pnpm
RUN pnpm install

RUN pnpm exec bazelisk build --disk_cache=/bazel-disk-cache -c opt //src/workerd/server:workerd

FROM scratch as artifact
COPY --from=builder /workerd/bazel-bin/src/workerd/server/workerd /workerd-linux-arm64
COPY --from=builder /bazel-disk-cache /.bazel-cache
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The primary distribution channel for `workerd` right now is through `npm`. We us

## Releases

This is pretty simple, and completely automatic—every time the compatibility date in [compatibility-date.capnp](src/workerd/io/compatibility-date.capnp) changes, a new release is generated, along with the built binaries for `linux-64` and `darwin-64`. This is governed by the [release.yml](.github/workflows/release.yml) GitHub Action. Since this only generates binaries for `darwin-64` and `linux-64`, binaries for `darwin-arm64` and `linux-arm64` need to be built manually on local machines. The generated GitHub release should be edited, with the built binaries uploaded as extra assets (named `workerd-darwin-arm64` and `workerd-linux-arm64` respectively).
This is pretty simple, and completely automatic—every time the compatibility date in [compatibility-date.capnp](src/workerd/io/compatibility-date.capnp) changes, a new release is generated, along with the built binaries for `linux-64` and `darwin-64`. This is governed by the [release.yml](.github/workflows/release.yml) GitHub Action. Since this only generates binaries for `darwin-64` and `linux-64`, binaries for `darwin-arm64` and `linux-arm64` need to be built manually on local machines. These can be generated from a local checkout of `workerd` using the `build-release.sh` script. This must be run on an Apple Silicon machine, and will generate binaries for the latest release on GitHub. The generated GitHub release should be edited, with the built binaries uploaded as extra assets (named `workerd-darwin-arm64` and `workerd-linux-arm64` respectively).
## Publishing `workerd`

Since the "Release" stage requires manual upload of binaries, this "Publish" stage requires a manual run of a GitHub Action—the [Publish to NPM](.github/workflows/npm.yml) action. This action has a `workflow_dispatch` trigger that can be activated from within the GitHub UI, and takes two parameters; the patch version, and whether this release is a prerelease. If it _is_ a prerelease, the published NPM version will be tagged with `beta`, and have a version number starting with `0.`. Otherwise, the published NPM version will be tagged `latest`, and have a version number starting with `1.`.
Expand Down
71 changes: 0 additions & 71 deletions build-npm-package.sh

This file was deleted.

22 changes: 22 additions & 0 deletions build-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/bash
set -euo pipefail

if [[ $(uname -m) == 'x86_64' ]]; then
echo "This _must_ be run on an Apple Silicon machine, since the macOS ARM build cannot be dockerised due to macOS license restrictions"
exit 1
fi

rm -f workerd-darwin-arm64
rm -f workerd-linux-arm64

# Get the tag associated with the latest release, to ensure parity between binaries
TAG_NAME=$(curl -sL https://api.github.com/repos/cloudflare/workerd/releases/latest | jq -r ".tag_name")

git checkout $TAG_NAME

# Build macOS binary
pnpm exec bazelisk build --disk_cache=./.bazel-cache -c opt //src/workerd/server:workerd

cp bazel-bin/src/workerd/server/workerd ./workerd-darwin-arm64

docker buildx build --platform linux/arm64 -f Dockerfile.release -t workerd:$TAG_NAME --target=artifact --output type=local,dest=$(pwd) .
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"typescript": "~4.7.4"
},
"devDependencies": {
"@bazel/bazelisk": "1.12",
"@types/debug": "^4.1.7",
"@types/node": "^18.7.18",
"@types/prettier": "^2.7.1",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65273d9

Please sign in to comment.