Skip to content

Commit

Permalink
feat: build F3 sidecar FFI in Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 committed Sep 12, 2024
1 parent ea2b7fa commit 80050b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
build-and-push-docker-image:
# Run the job only if the PR is not a draft.
# This is done to limit the runner cost.
if: github.event.pull_request.draft == false
# if: github.event.pull_request.draft == false
name: Build images and push to GHCR
# Change to `buildjet-8vcpu-ubuntu-2204` if `fuzzy` is down.
# runs-on: fuzzy
Expand Down Expand Up @@ -83,7 +83,8 @@ jobs:
labels: ${{ steps.metafat.outputs.labels }}
push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
# Compile Docker image only for AMD64 for a regular PR to save some CI time.
platforms: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
# platforms: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
platforms: 'linux/amd64,linux/arm64'
target: fat-image

# This step yields the following labels
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ RUN apt-get update && \
apt-get install --no-install-recommends -y build-essential clang curl git ca-certificates
RUN update-ca-certificates

# install Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --profile minimal
ENV PATH="/root/.cargo/bin:${PATH}"

# install Go. Note that F3 sidecar is not enabled for arm64, see `build.rs`
RUN curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
RUN "${HOME}/.g/bin/g" install 1.21 && ln -sf "${HOME}/.g/go/bin/go" /usr/local/bin/go && go version

# Copy the cross-compilation scripts
COPY --from=xx / /

Expand All @@ -46,9 +51,6 @@ RUN xx-apt-get update && \
WORKDIR /forest
COPY . .

# TODO(forest): https://github.com/ChainSafe/forest/issues/4758
ENV FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT=1

# Install Forest. Move it out of the cache for the prod image.
RUN --mount=type=cache,sharing=private,target=/root/.cargo/registry \
--mount=type=cache,sharing=private,target=/root/.rustup \
Expand Down
10 changes: 8 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ fn is_docs_rs() -> bool {
std::env::var("DOCS_RS").is_ok()
}

// Note: arm64 is disabled for now as cross-compilation is not yet supported in rust2go
fn is_sidecar_ffi_enabled() -> bool {
// Opt-out building the F3 sidecar staticlib
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"),
_ => true,
_ => {
if cfg!(target_arch = "x86_64") {
true
} else {
false
}
}
}
}

0 comments on commit 80050b9

Please sign in to comment.