cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.79k stars 379 forks source link

apt-get not work in dockerfile #1552

Closed h3zh1 closed 2 months ago

h3zh1 commented 2 months ago

Checklist

Describe your issue

I tried to build the docker image locally, I used apt to download g++-x86-64-linux-gnu and protobuf-compiler etc. But these don't seem to take effect. Can I only define them in pre-build or .sh? cargo build image: image the content in Dockerfile image But apt cannot find it image

What target(s) are you cross-compiling for?

x86_64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5 (d8631fe 2024-08-17)

Example

No response

Additional information / notes

No response

Emilgardis commented 2 months ago

I'm not sure what these screenshots are supposed to show. Where is the installation logs? Why is RUN /xargo.sh underlined?

h3zh1 commented 2 months ago

Sorry, my picture is not particularly accurate. The underline is to show that RUN apt... is not executed under cargo. pic1: I pulled the image from ghcr.io and ran apt list to find it. I couldn't find the corresponding package "https://github.com/cross-rs/cross/blob/main/docker/Dockerfile.x86_64-unknown-linux-gnu#L15" image pic2: I re-run cargo build-docker-image x86_64-unknown-linux-gnu --tag latest --no -cache, the new screenshot is as follows image

Emilgardis commented 2 months ago

the image built with cargo build-docker-image is tagged with :local, not :main There's also some confusion here about what Dockerfile cargo build-docker-image x86-64-unknown-linux-gnu uses, it actually uses Dockerfile.native when target=platform

h3zh1 commented 2 months ago

Oh, it seems that he parsed Dockerfile.native instead of "Dockerfile.x86_64-unknown-linux-gnu"

h3zh1 commented 2 months ago

When the target is "x86_64-unknown-linux-gnu", Dockerfile.native is loaded. But when the target is "i686-unknown-linux-gnu", Dockerfile.i686-unknown-linux-gnu is loaded correctly. image

And I tried to use another ubuntu to execute cargo build-docker-image i686-unknown-linux-gnu --tag local and cargo build-docker-image x86_64-unknown-linux-gnu --tag local, error still exists image

Emilgardis commented 2 months ago

Yes, that is not a problem, it's supposed to be that way.

I'm not sure what this issue is about anymore, can we close it?

h3zh1 commented 2 months ago

Now I understand the usage, but loading Dockerfile.native is a little uncomfortable when I build image for "x86_64-unknown-linux-gnu" locally. Thanks, we can close it.

Emilgardis commented 2 months ago

To explain a bit, the reason .native is used is because we want to support using the images for other platforms. On x86_64-unknown-linux-gnu we cant install libc6-dev-amd64-cross, we just install libc6, so to make it easy, when image platform=target, we switch to .native