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

Merged
merged 28 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0b26e97
feat: use cross for multiplatform builds
merklefruit Nov 15, 2024
68f11f0
feat: zigbuild
merklefruit Nov 15, 2024
f1b55b9
fix: build-arg
merklefruit Nov 15, 2024
29aa316
fix: target path
merklefruit Nov 15, 2024
c0f6881
chore: fixes
merklefruit Nov 15, 2024
2a0accc
feat: use base dir to hold binaries
merklefruit Nov 15, 2024
0671f11
fix: adjust copy path in cross build file
merklefruit Nov 15, 2024
93117cc
fix: use static name for binary output file
merklefruit Nov 15, 2024
7211b15
fix: attempt at native cargo on native arch
merklefruit Nov 15, 2024
738f7f8
chore: rm shell
merklefruit Nov 15, 2024
c64c253
chore: debug logs
merklefruit Nov 15, 2024
4697777
chore: handle edge case with cargo
merklefruit Nov 15, 2024
6c97f61
chore: typo
merklefruit Nov 15, 2024
9e3704c
feat: add cross compiled openssl path
merklefruit Nov 18, 2024
da19682
chore: fix cross compile script
merklefruit Nov 18, 2024
556468d
chore: adjust openssl paths
merklefruit Nov 18, 2024
4519cbc
fix: more fixes to cross build script
merklefruit Nov 18, 2024
97255ca
fix: use correct compiler
merklefruit Nov 18, 2024
f71fa98
chore: more cross compilation tests
merklefruit Nov 18, 2024
966de9e
chore: more cross compilation tests
merklefruit Nov 18, 2024
ec349f7
chore: use cross for bolt-sidecar
merklefruit Nov 18, 2024
2d3d7b5
chore: typo
merklefruit Nov 18, 2024
38acf9f
chore: typo
merklefruit Nov 18, 2024
e019f4f
chore: only arm64 with cross
merklefruit Nov 18, 2024
4df28d6
feat: use cross for everything with openssl cross compiled lib
merklefruit Nov 18, 2024
3c88a0e
fix: cargo clean between builds, use more recent gcc
merklefruit Nov 18, 2024
3e565c1
chore: rm compilation support script, update docs
merklefruit Nov 18, 2024
c9fc73f
chore: add troubleshooting tips
merklefruit Nov 19, 2024
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
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# log files
*_dump.log
logs/
target/

# environment secrets
.env

# IDEs
.vscode
.idea

# build artifacts
target/
dist/

# other
.DS_Store
.env
11 changes: 5 additions & 6 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Pay special attention to the `README` and `docker-compose` files.
For instance, for the Bolt sidecar this is in `bolt-sidecar/Cargo.toml`.
Similar changes should be made in the other packages getting updated.

We don't currently keep track of the version for flashbots forks.

Next, update the version of the Docker images used in any `docker-compose` files.
These currently only live inside the `testnets/` dir.

Expand All @@ -29,9 +27,10 @@ We use the built-in Github changelog feature to generate the changelog.

## 3. Build new Docker images

You can build new Docker images with the `just release <tag>` recipe.
You can build new Docker images with the `just build-and-push-all-images <tag>` recipe.

Example: `just release v0.2.0-alpha` will build and push the Docker images
Example: `just build-and-push-all-images v0.2.0-alpha` will build and push the Docker images
for all Bolt components with the tag `v0.2.0-alpha` for both `arm64` and `amd64`
architectures. This can take a long time... We recommend building from an ARM machine
because cross-compiling from x86 into ARM is slow as hell.
architectures. This can take a long time.

Since we use cross compilation, we recommend running this from an x86_64 linux box.
74 changes: 38 additions & 36 deletions bolt-boost/Cargo.lock

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

8 changes: 5 additions & 3 deletions bolt-boost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "bolt-boost"
version = "0.3.0-alpha"
edition = "2021"

[profile.release]
lto = true
debug = true

[dependencies]
# core
tokio = { version = "1", features = ["full"] }
Expand All @@ -15,9 +19,7 @@ thiserror = "1.0.63"
reqwest = "0.12.7"

# crypto
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "ec3073e", features = [
"sha2-asm",
] }
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "ec3073e" }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to remove the ssz-rs sha2-asm feature as it was breaking for cross-compiled aarch64.
There might be a way to do it but for now I had to disable it

tree_hash = "0.8"

# tracing & metrics
Expand Down
7 changes: 7 additions & 0 deletions bolt-boost/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
pre-build = [
# We depend on openssl for the build, so we need to install its cross-compiled version
# more info at: https://github.com/cross-rs/cross/wiki/Configuration#build
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get --assume-yes --no-install-recommends install libssl-dev:$CROSS_DEB_ARCH"
]
4 changes: 4 additions & 0 deletions bolt-sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ version = "0.3.0-alpha"
edition = "2021"
default-run = "bolt-sidecar"

[profile.release]
lto = true
debug = true

[dependencies]
# core
clap = { version = "4.5.20", features = ["derive", "env"] }
Expand Down
11 changes: 11 additions & 0 deletions bolt-sidecar/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build]
pre-build = [
# We depend on openssl for the build, so we need to install its cross-compiled version
# more info at: https://github.com/cross-rs/cross/wiki/Configuration#build
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get --assume-yes --no-install-recommends install libssl-dev:$CROSS_DEB_ARCH",

# Update the default gcc and g++ to 10 to avoid a bug in gcc 9 that causes a build failure
# more info at: https://github.com/cross-rs/cross/issues/1565#issuecomment-2483968180
"apt-get --assume-yes --no-install-recommends install gcc-10 g++-10 && ln -sf /usr/bin/gcc-10 /usr/bin/gcc && ln -sf /usr/bin/g++-10 /usr/bin/g++"
]
50 changes: 39 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,51 @@ send-blob-preconf count='1':
--count {{count}}

# build all the docker images locally
build-images:
@just build-sidecar
@just build-bolt-boost
build-local-images:
@just build-local-sidecar
@just build-local-bolt-boost

# build the docker image for the bolt sidecar
[private]
build-sidecar:
build-local-sidecar:
cd bolt-sidecar && docker build -t ghcr.io/chainbound/bolt-sidecar:0.1.0 . --load

# build the docker image for bolt-boost
[private]
build-bolt-boost:
build-local-bolt-boost:
cd bolt-boost && docker build -t ghcr.io/chainbound/bolt-boost:0.1.0 . --load

# build and push multi-platform docker images to GHCR with the provided tag
[confirm("are you sure? this will build and push new images on ghcr.io")]
release tag:
chmod +x ./scripts/check_version_bumps.sh && ./scripts/check_version_bumps.sh {{tag}}
cd bolt-sidecar && docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/chainbound/bolt-sidecar:{{tag}} --push .
cd bolt-boost && docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/chainbound/bolt-boost:{{tag}} --push .

# Cross platform compilation with cargo cross.
# Install cross with: `cargo install cross --git https://github.com/cross-rs/cross`.
#
# Troubleshooting tips:
# * We have to clean the target directory before building for different targets because
# of a rustc incremental compilation bug. See: https://github.com/cross-rs/cross/issues/724#issuecomment-1484065725
# * If incurring into issues related to building `aws-lc-rs`, check this out:
# https://github.com/cross-rs/cross/issues/1565#issuecomment-2483968180
# * If incurring into issues related to building `sha2-asm`, make sure the "sha2-asm" feature
# is disabled in the `Cargo.toml` file you are trying to build.
#
# build the cross platform binaries for a package by name. available: "bolt-sidecar", "bolt-boost".
[private]
cross-compile package target_arch release_dir:
cd {{package}} && cargo clean && cross build --release --target {{target_arch}}
mkdir -p {{release_dir}} && cp {{package}}/target/{{target_arch}}/release/{{package}} {{release_dir}}

# build and push multi-platform docker images to GHCR for a package. available: "bolt-sidecar", "bolt-boost".
build-and-push-image package tag:
@just cross-compile {{package}} x86_64-unknown-linux-gnu amd64
@just cross-compile {{package}} aarch64-unknown-linux-gnu arm64

docker buildx build \
--build-arg BINARY={{package}} \
--file ./scripts/cross.Dockerfile \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/chainbound/{{package}}:{{tag}} \
--push .

# build and push all the available packages to GHCR with the provided tag
build-and-push-all-images tag='latest':
@just build-and-push-image bolt-sidecar {{tag}}
@just build-and-push-image bolt-boost {{tag}}
18 changes: 18 additions & 0 deletions scripts/cross.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This image is meant to enable cross-architecture builds.
# It assumes the binary has already been compiled for `$TARGETPLATFORM` and is
# locatable in `./dist/bin/$TARGETARCH/$BINARY`.

FROM --platform=$TARGETPLATFORM ubuntu:22.04

LABEL org.opencontainers.image.source=https://github.com/chainbound/bolt
LABEL org.opencontainers.image.licenses="MIT"

# Filled by docker buildx
ARG TARGETARCH

# Should be set by the caller when building the image
ARG BINARY

COPY ./dist/bin/$TARGETARCH/$BINARY /usr/local/bin/bolt

ENTRYPOINT ["/usr/local/bin/bolt"]