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

Unable to build statically using an alpine image #460

Open
lielfr opened this issue Dec 1, 2024 · 1 comment
Open

Unable to build statically using an alpine image #460

lielfr opened this issue Dec 1, 2024 · 1 comment

Comments

@lielfr
Copy link

lielfr commented Dec 1, 2024

Hi,
I'm trying to statically embed Ruby within a Rust project using magnus, and it seems like I cannot get it to build using an alpine image.
I'm using Docker on M1, using the following Dockerfile:

FROM rust:alpine AS builder

RUN apk add musl-dev ruby clang17-static llvm17-static clang17-libclang

WORKDIR /usr/src/myapp

COPY . .

RUN cargo install --path .

FROM scratch

COPY --from=builder /usr/local/cargo/bin/myapp .

CMD ["myapp"]

My Cargo.toml looks like this:

[package]
name = "ruby-embed-test"
version = "0.1.0"
edition = "2021"

[dependencies]
magnus = { version = "0.7.1", features = ["embed"] }
rb-sys = { version = "*", default-features = false, features = ["ruby-static"] }

and the error I get is:

Unable to find libclang: "the `libclang` shared library at /usr/lib/llvm17/lib/libclang.so.17.0.6 could not be opened: Dynamic loading not supported"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: failed to compile `ruby-embed-test v0.1.0 (/usr/src/myapp)`, intermediate artifacts can be found at `/usr/src/myapp/target`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.`

I also tried to mess with the bindgen settings, but it seems like `rb-sys-build` uses the `runtime` feature, which is mutually exclusive with the `static` feature.

Is it possible to embed Ruby like this? Ideally, I would like to have just one self-contained binary (that can be used without glibc).
@ianks
Copy link
Collaborator

ianks commented Dec 11, 2024

According to the clang-sys docs, looks like you may need to set LIBCLANG_STATIC_PATH or something, but I've never done this myself so I'm not sure.

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