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

How to add build targets to the Rust toolchain in the builder image? #32

Open
tangowithfoxtrot opened this issue Dec 7, 2024 · 2 comments

Comments

@tangowithfoxtrot
Copy link

In the README, there is an example that uses a MUSL target to create a statically-linked binary. I was just wondering, if that build target isn't already present in the default image, how would we add it?

For example, here is my repro-env.toml file:

[container]
image = "debian:trixie"

[packages]
system = "debian"
dependencies = ["ca-certificates", "musl-tools", "libc6-dev", "rust-all"]

I use this build command:

repro-env build -- cargo build --release --target aarch64-unknown-linux-musl

But the aarch64-unknown-linux-musl build target isn't available in the image by default, so I get the following error:

error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-unknown-linux-musl` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-unknown-linux-musl`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `memchr` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `regex-syntax` (lib) due to 1 previous error
Error: Failed to execute in container: ["cargo", "build", "--release", "--target", "aarch64-unknown-linux-musl"]

Caused by:
    Podman command (["container", "exec", "-w", "/build", "--", "b3b41540bbdb4f6e48e5061ba27314ed868587817f3f16b4439cc0d755a0da47", "cargo", "build", "--release", "--target", "aarch64-unknown-linux-musl"]) failed to execute: ExitStatus(unix_wait_status(25856))
@kpcyrd
Copy link
Owner

kpcyrd commented Jan 6, 2025

hi!

I'm currently using an Arch Linux build environment for my statically linked binaries. There's a rust-aarch64-musl package that can be used together with musl-aarch64.

Before this was a thing, I explicitly selected a non-rust docker image, added rustup as a package and then installed an explicit toolchain version, as noted in the readme:

# select a specific Rust release so it's documented which one has been used
rustup default 1.80.1
rustup target add aarch64-unknown-linux-musl
rustup target add x86_64-unknown-linux-musl

I don't know if rustup target add resolves to a deterministic version with regular Rust images, but could be worth a try.

I asked somebody from the debian-rust team and apparently it's also possible to use the dpkg multiarch feature to make a different build target available, but I'm not sure if this is currently properly implemented in repro-env (you may need to generate your own repro-env.lock).

I hope this helps, let me know if you have trouble getting this to work!

@kpcyrd
Copy link
Owner

kpcyrd commented Jan 6, 2025

Ah sorry, the readme I was referring to is from a different repository (apt.vulns.xyz), specifically this version of it:

https://github.com/kpcyrd/apt-vulns-xyz/tree/c8584ad731ae9edff6a1d8f3d408d622649b46ad

I've now updated it to the new Arch Linux instructions.

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

2 participants