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

Build with musl (similar to rust-musl-cross ) #230

Open
igor-hnizdo opened this issue Sep 7, 2022 · 0 comments
Open

Build with musl (similar to rust-musl-cross ) #230

igor-hnizdo opened this issue Sep 7, 2022 · 0 comments

Comments

@igor-hnizdo
Copy link

igor-hnizdo commented Sep 7, 2022

It would be nice if this package could build with musl instead of glibc.

Musl has the upside that it produces static library, always.

Rust has these docker images/repo

https://github.com/messense/rust-musl-cross
https://hub.docker.com/r/messense/rust-musl-cross/

which is based on this repo

https://github.com/richfelker/musl-cross-make

The nice thing is - you can actually steal this work very easily. :) these rust repos have very little to do with actual rust; they install rust sure, but the main logic is the builds and cross-builds, which is already done.


I have been able to build with go+musl myself like this:

Dockerfile:

FROM messense/rust-musl-cross:aarch64-musl AS go-arm64-musl
COPY --from=golang:1.19.1 /usr/local/go/ /usr/local/go/
#that's it... I just "steal" the rust image for go purposes

Bash script to run:

CGO_ENABLED=1 CC="/usr/local/musl/bin/aarch64-unknown-linux-musl-gcc" GOARCH=arm64 \
    go build --ldflags '-linkmode external -extldflags "-static" -extld /usr/local/musl/bin/aarch64-unknown-linux-musl-gcc' \
    -o <output here>

This will use musl and build arm64 static library. I am actually not sure if the extldflags "-static" is necessary or not :)

Note that it works on both ARM and AMD64 host PC, as the rust base images are built for both ARM and AMD64.

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

1 participant