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

Can't build on Alpine: target aarch64-unknown-linux-musl does not support these crate types #823

Closed
gitmalong opened this issue Nov 10, 2021 · 3 comments

Comments

@gitmalong
Copy link

Dockerfile

FROM rust:alpine3.14 as builder
WORKDIR /usr/src/myapp
COPY src_rust/ .
RUN npm run build-release --prefix my-app-rust-bindings

Error

error: cannot produce cdylib for `my-app-rust-bindings v0.1.0 (/usr/src/myapp/my-app-rust-bindings)` as the target `aarch64-unknown-linux-musl` does not support these crate types
Did not copy "cdylib:my-app-rust-bindings"

While the local build on my machine works with npm run build-release --prefix my-app-rust-bindings

@kjvalencik
Copy link
Member

kjvalencik commented Nov 10, 2021

Building cdylib with Rust is not fully supported. See rust-lang/rust#59302 for more details.

There is some support by using the crt-static feature to switch to dynamic linking the C runtime (default is static). This can be set either with the environment variable RUSTFLAGS="-C target-feature=-crt-static" or with a .cargo/config.toml. Please note that you will also need apk add musl-dev to build with this flag.

[build]
rustflags = ["-C", "target-feature=-crt-static"]

After adding that flag, I am able to successfully build and execute a simple Neon module. However, since this is not a fully implemented feature, you may run into other issues. For dockerizing Neon apps, I highly recommend using debian:stable-slim docker container. It's nearly as small alpine, but since it's glibc based instead of musl, it won't have as many issues building native code.

Thanks for your interest. I'm going to close this issue since it is a limitation of Rust and outside the scope of Neon.

@rtritto
Copy link

rtritto commented Oct 30, 2024

@kjvalencik currently what's the best distro to use with Docker and build with cross-compiling all tier 1 platforms?
Alpine still have some issue?

@kjvalencik
Copy link
Member

I believe alpine works these days with cdylib targets.

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

3 participants