Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fast multi-platform build #389

Open
wants to merge 13 commits into
base: unstable
Choose a base branch
from
Open

Conversation

merklefruit
Copy link
Collaborator

@merklefruit merklefruit commented Nov 15, 2024

After several failed attempts (cross, xx-cargo, etc) we can finally build our rust binaries for both x86 and arm targets!
We now use cargo-zigbuild which swaps out the linker used by Cargo with Zig.

Benefits:

  • builds are very fast: ~2 minutes to build a release binary of the bolt-sidecar! 🏎️
  • no linker errors: zig has solved some of the nasty linker errors we were getting with other approaches
  • no Docker overhead for build contexts, meaning also no need for janky docker cache layers
  • super lightweight output images, because we only ship the binary inside them, no need for anything else

Downsides:

  • since the images only contain the binary, it's harder to verify that they are running the correct binary. This is not a big issue because anyone wanting to verify their image integrity can build it locally from source.
  • builds for aarch64-unknown-linux-gnu are failing on my Macbook with M2 chip. When building on an x86-based server everything runs smooth for all our targets though. The most likely cause is that macOS uses a different ABI (Mach-O) and libc (libSystem), which doesn’t satisfy what the GNU environment for aarch64 requires. Zig isn’t fully substituting for these missing components, which causes the error.

Usage

Available packages that can be built from this repo (so far): bolt-sidecar, bolt-boost.

Example to produce a cross-platform docker image with tag unstable:

just build-and-push-image bolt-sidecar unstable

Example to produce cross-platform docker images for all available packages mentioned above with tag unstable:

just build-and-push-all-images unstable

Requisites to build images

  • cargo
  • zig
  • cargo-zigbuild
  • docker buildx

@merklefruit merklefruit added the A: infra Area: Infrastructure label Nov 15, 2024
@merklefruit merklefruit self-assigned this Nov 15, 2024
Copy link
Contributor

@thedevbirb thedevbirb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, super happy we got it working with the binary-based approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: infra Area: Infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants