Skip to content

Unable to build statically using an alpine image #460

@lielfr

Description

@lielfr

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions