1

I have this in a Cargo.toml

rdkafka = { version = "0.29.0", features = [ "ssl", "cmake-build"] }

I tried to compile to x86_64-unknown-linux-musl using 2 options. Both failed.

cargo build --target x86_64-unknown-linux-musl --release

OUTPUT:

linking with cc failed: exit status: 1
rdkafka_ssl.c:(.text.rd_kafka_ssl_ctx_term+0x2b): undefined reference to `ENGINE_free'
collect2: error: ld returned 1 exit status
cross build --target=x86_64-unknown-linux-musl --release

OUTPUT:

rdkafka_ssl.c:(.text.rd_kafka_ssl_ctx_term+0x2b): undefined reference to `ENGINE_free'
collect2: error: ld returned 1 exit status

They both give the same error.

Does anyone know how to fix this? Or can someone try this on their machine.. I'd really appreciate it.

I expected the build to pass.

POST

I have added github repo and recreated the issue. It uses Dockerfile https://github.com/0xDjole/rust-rdkafka-musl To test just docker build -t muslkafka .

Here is the screenshot of the issue

enter image description here

0xDjole
  • 25
  • 3

1 Answers1

0

I am able to build a rust crate depending on rdkafka on x86_64-unknown-linux-musl by disabling the cmake-build feature flag and using the following Dockerfile:

FROM clux/muslrust:1.63.0 AS chef
RUN cargo install cargo-chef --locked
RUN ln -s /usr/bin/musl-gcc /usr/bin/musl-g++
WORKDIR /usr/src/foo

FROM chef AS planner
COPY . .
RUN cargo chef prepare

FROM chef AS builder 
COPY --from=planner /usr/src/foo/recipe.json recipe.json
RUN cargo chef cook --release
COPY . .
RUN cargo build --release \
    && strip --strip-debug target/*/release/foo \
    && cp target/*/release/foo /usr/local/bin/

FROM alpine as final
COPY --from=builder /usr/local/bin/foo /usr/local/bin
ENTRYPOINT ["/usr/local/bin/foo"]

(I'm somewhat surprised to see that this does seem to work with the ssl feature and produces a statically linked binary, I hadn't tested this before and openssl is notorious for being "difficult". I can't test right now whether said binary also actually works, so… please test.)

Caesar
  • 6,733
  • 4
  • 38
  • 44
  • tried it and it doesn't work – 0xDjole Dec 14 '22 at 16:11
  • If you just say "doesn't work" then it's gonna stay that way. If you want to get to the bottom of it, tell where it fails, show error messages, and maybe paste your Cargo.lock somewhere. Also, have you adjusted `foo` for your project/binary name? (For me, this works if I `cargo new foo && cd foo && cargo add rdkafka --features ssl && cat $the_above >Dockerfile && docker build .`) – Caesar Dec 15 '22 at 00:22
  • I created github repo and posted a screenshot of the error I am getting. Any suggestions on what to update? – 0xDjole Dec 15 '22 at 00:42
  • 1
    An MNWE! 0xDjole++. [zing](https://github.com/jcaesar/rust-rdkafka-static-example/commit/0e195b451cd26cd046852e1258868ed880961f92) In short: Substitute `ssl-vendored, cmake-build` for `ssl`, and substitute `ekidd/rust-musl-builder` (which is [unmaintained](https://github.com/emk/rust-musl-builder/issues/147) and only works for older versions of rdkafka like 0.24 if memory serves right) with `clux/muslrust`. – Caesar Dec 15 '22 at 04:04
  • Hey it works!!! However I had another issue that is I had to remove openssl package I had in Cargo.toml so that might have been the issue all along. THANK YOU ANYWAYS!!!! – 0xDjole Dec 15 '22 at 06:52