rust-lang / docker-rust

The official Docker images for Rust
436 stars 88 forks source link

Alpine missing libc-dev #94

Open misalcedo opened 2 years ago

misalcedo commented 2 years ago

I tried building executables using the alpine latest and the build failed unless I added RUN apk add libc-dev to my builder image. See https://github.com/misalcedo/kv-store for a sample repo that fails to build. Another one of my repos also failed.

The basic hello-world crate does build in this base image.

Looking at the debian-based images we do install libc-dev there. Is there any reason not to include it for Alpine?

I am new to compiling Rust with MUSL, so there may very well be a better way to do this.

sfackler commented 2 years ago

The Alpine images are significantly more minimal than the standard Debian images - the slim Debian images are a better reference. libc-dev is only required when building C code as part of the compilation process.

misalcedo commented 2 years ago

It's good to know that it's a conscious choice to keep the alpine image size down. Would be good to document that somewhere though. Took me a long time to figure out why the builds were broken as most rust alpine examples don't seem to compile c code so I didn't have much reference material to borrow from.

Granted this is my first time trying to create a scratch image from Rust, but if it's a common use case others may have the same problem.

danielecr commented 7 months ago

The Alpine images are significantly more minimal than the standard Debian images - the slim Debian images are a better reference. libc-dev is only required when building C code as part of the compilation process.

Why? I mean, I want to discuss real foundation of this choice. I bring two use cases as examples.

I use rust:1.75-alpine3.19 to build an executable:

FROM rust:1.75-alpine3.19

RUN cargo build --release

RUN mv target/release/myapp /myapp

FROM scratch as distro

COPY --from=builder /myapp /myapp

build and tag it with myapp:v0.1-alpine

From another image define

FROM myapp:v0.1-alpine as builder
## just be sure is there
RUN ls /myapp

FROM alpine:latest

COPY --from=builder /myapp /usr/local/bin/myapp
## etc

A second use case is to build inside the first of 2-stage Dockerfile directly. Ending with a slim image anyway.

What I am asking is: there are other real scenario in use? Who is using the rust image for something else than "compile-then-move-away"?

An image supposed to be useful for building rust code currently misses also the musl-dev package, and it is building for a musl architecture.

How much minimal should be? (or should it be really minimal at all?)

randomairborne commented 6 months ago

just want to drop my opinion here- yeah, i don't think it being minimal makes sense. rustc is huge.

danielecr commented 2 months ago

just want to drop my opinion here- yeah, i don't think it being minimal makes sense. rustc is huge.

yep, I see your point. My comments was meaningless. Sorry.