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

Cross compiling on x64 for arm64 via docker buildx runs out of memory #4827

Open
jclapis opened this issue Oct 11, 2023 · 0 comments
Open

Cross compiling on x64 for arm64 via docker buildx runs out of memory #4827

jclapis opened this issue Oct 11, 2023 · 0 comments

Comments

@jclapis
Copy link
Contributor

jclapis commented Oct 11, 2023

Description

This is a fun one. While I know cross is supposed to be used for cross-compiling (which invokes its own Docker process), I am trying to build the arm64 image directly via buildx. If you attempt to cross-compile Lighthouse on an x64 box via the following:

docker buildx build --platform=linux/arm64 -t jclapis/lighthouse:test-arm64 -f Dockerfile --load .

It will get stuck pulling the submodules for a few minutes while QEMU eats all of the system's RAM:

1.247   Installing lighthouse v4.5.0 (/lighthouse/lighthouse)
1.429     Updating git repository `https://github.com/sigp/milagro_bls`
2.399     Updating git submodule `https://github.com/sigp/incubator-milagro-crypto-rust`
3.570     Updating crates.io index
136.3 Killed
136.3 make: *** [Makefile:48: install] Error 137

image

The problem ends up being a possible bug in libgit2 itself, which cargo uses as part of updating the submodules. This is well-documented by the Rust community already and there's a simple workaround for it which they describe in that issue: tell cargo to use the git CLI for pulling submodules instead of the git library itself.

I have a PR coming that will resolve it with a simple (optional) build-arg in the Dockerfile to remedy this, though one could probably argue that making this the default behavior would fix the issue and wouldn't adversely affect the standard Lighthouse build process.

Version

v4.5.0 and likely many versions prior; the bug was first reported in 2022.

Present Behaviour

Building the image results in an out-of-memory error and the build process gets killed.

Expected Behaviour

Building the image should complete successfully.

Steps to resolve

PR pending, it'll reference this issue once it's in.

bors bot pushed a commit that referenced this issue Oct 19, 2023
…ing cross-compiling (#4828)

## Issue Addressed
#4827 

## Proposed Changes

This PR introduces a new build-arg to the Lighthouse Dockerfile: `CARGO_USE_GIT_CLI`. This arg will be passed into the `CARGO_NET_GIT_FETCH_WITH_CLI` [environment variable](https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli), which instructs `cargo` to use the git CLI during `fetch` operations instead of the git library. Doing so works around [a bug](rust-lang/cargo#10583) with the git library that causes it to go OOM during `fetch` operations on `arm64` platforms.

The default value is `false` so this doesn't affect Lighthouse builds or the CI pipeline. Running a build with `--build-arg CARGO_USE_GIT_CLI=true` will activate it, which is necessary to cross-compile the `arm64` binary when not using `cross` (i.e., when building via the Dockerfile instead of natively if you don't have a rust environment ready to go).

Special thanks to @michaelsproul for helping me repro the initial problem.

Co-authored-by: Michael Sproul <micsproul@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant