cargo: Value too large for defined data type when cargo build on armv7 with qemu

Problem

Trying to build an app for armv7 in a docker container with qemu. The current result is explained here with the steps to reproduce it : https://github.com/jdrouet/docker-bug-value-too-long

Steps

  1. install docker
  2. install docker-buildx
  3. follow the steps here

Possible Solution(s) No idea.

Notes The guys from docker claim it’s coming from cargo.

Output of cargo version:

The one from the docker image rust:1-slim-buster

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 15
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

If you can’t make the above Dockerfile-based workaround, what works as well is using tmpfs for the whole /var/lib/docker on the build host. For GitHub actions, I’ve done that here: https://github.com/WeblateOrg/docker/pull/1274

Very nice @nijel! I used your example and made a reusable Action for those affected by this issue 😃

If someone is coming here and also needs a workaround for a docker build: Put this in the beginning of the Dockerfile: # syntax = docker/dockerfile:experimental Then do something like this: RUN --security=insecure mkdir -p /root/.cargo && chmod 777 /root/.cargo && mount -t tmpfs none /root/.cargo && some_command_that_uses_cargo

Since cargo (stable) now supports the sparse registry protocol, the easiest workaround is to set the envinronment variable CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse. This avoids the problematic call to libgit2 altogether. You have to make sure the git binary is installed though, but that shouldn’t be a problem.

If you are using buildkit, there is a much cleaner workaround than using the --security=insecureoption. Just use RUN --mount like this:

RUN --mount=type=tmpfs,target=/root/.cargo some_command_that_uses_cargo

For anyone having this issue, in the end I went to the path of making a Dockerfile with multi-stage builds that will cross-compile for all the architectures I need on the architecture of the pipeline agent and scrapped using qemu for the cargo build, I only use it to run apt install and other small stuff at the end.

If you project allows for this route, you can follow my Dockerfile as guidance

https://github.com/madiele/vod2pod-rss/blob/cac3d27c415ed8341fa8da738e4604b7427c04ae/Dockerfile

I went form 2+ hours build times to 5-10 minutes build times, it was worth the effort.

If you are using buildkit, there is a much cleaner workaround than using the --security=insecureoption. Just use RUN --mount like this:

RUN --mount=type=tmpfs,target=/root/.cargo some_command_that_uses_cargo

I had to adapt this slightly to use a different directory for cargo to get it working with the rust base image to build a rust project.

RUN --mount=type=tmpfs,target=/.cargo CARGO_HOME=/.cargo cargo build --release