We need to have risc0 available in docker containers. Modern macs are aarch64 machines. When you run docker on mac, a aarch64 VM will be used. It's possible to use x86-64, but those would run slower.
Unfortunately, risc0 binaries are not built for aarch64 linux. risc0/risc0#1286
There are two general approaches that I found.
It's possible to use qemu for system emulation. I managed to build both on macOS and on nixOS.
docker buildx create --name builder-arm64-amd64 --use
# ↓ only required on nixOS to register qemu
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
Then build the images with:
docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/pepyakin/risczero --push -f docker/risczero.Dockerfile .
The downsides of this approach are:
- Obviously emulation is not the fastest,
- --mount=type=cache is not that useful since it will be shared between the both builds and a really coarse grained lock will be used. Although may be worked around with different assigning different paths.
Another approach is to build the images on the native machines (arm64/linux on macOS and amd64/linux on linux), push those two images and then stitch them together.
docker manifest create ghcr.io/pepyakin/risczero:latest \
ghcr.io/pepyakin/risczero:latest-arm64 \
ghcr.io/pepyakin/risczero:latest-amd64
docker manifest annotate ghcr.io/pepyakin/risczero:latest \
ghcr.io/pepyakin/risczero:latest-arm64 --arch arm64
docker manifest annotate ghcr.io/pepyakin/risczero:latest \
ghcr.io/pepyakin/risczero:latest-amd64 --arch amd64
docker manifest push ghcr.io/pepyakin/risczero:latest