Skip to content

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

@jclapis

Description

@jclapis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions