emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

libinfer_schema_macros.so: undefined symbol: ASN1_STRING_length #30

Closed TheNeikos closed 6 years ago

TheNeikos commented 6 years ago

First of all, thanks for creating this!

I have tried to build my cargo binary with your docker image, it is sadly slightly out of date. (I need at least 2017-12-20 due to codegen deps) However I was able to fix that in my Dockerfile. However, then I get this error:

error: /home/rust/src/target/release/deps/libinfer_schema_macros-da12480521239fc5.so: undefined symbol: ASN1_STRING_length
  --> /home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel_infer_schema-1.0.0-beta1/src/lib.rs:15:1
   |
15 | extern crate infer_schema_macros;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Do you know what would fix this?

My Dockerfile:

FROM ekidd/rust-musl-builder:1.20.0 AS builder

ADD . ./

RUN sudo chown -R rust:rust /home/rust

RUN rustup default nightly-2017-12-20 &&  rustup target add x86_64-unknown-linux-musl

RUN cargo build --release

FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder \
    /home/rust/src/target/x86_64-unknown-linux-musl/release/fc \
    /usr/local/bin/
CMD /usr/local/bin/fc

This seems different from the pg-sys problem you mention in the Readme.

emk commented 6 years ago

This is possibly a nasty OpenSSL link error related to diesel's Postgres support.

diesel needs a very specific setup, as described here. Note that this may not always work with the latest version of pq-sys! You need to use a version of pq-sys with @golddranks's fixes applied. This is because upstream pq-sys didn't support cross-compilation the last time I checked.

TheNeikos commented 6 years ago

I've added the lines to my Cargo.toml but I still get the ASN1_STRING_length error.

Have you got a specific diesel version that you know works, or a mix of transitive dependencies?

I have just noticed that your diesel example has a Cargo.lock, so I'm trying those now.

My Cargo.toml looks like this right now:

[dependencies]
bcrypt = "0.1.5"
dotenv = "0.9.0"
error-chain = "0.11.0"
maud_lints = "0.17.0"
r2d2 = "0.8.1"
r2d2-diesel = "1.0.0-beta1"
rocket = "0.3.3"
rocket_codegen = "0.3.3"
openssl-sys = "0.9"

[dependencies.diesel]
features = ["postgres"]
version = "1.0.0-beta1"

[dependencies.diesel_infer_schema]
features = ["postgres"]
version = "1.0.0-beta1"

But I think that a transitive dependency is not compatible? I am not sure.

emk commented 6 years ago

I don't see the following anywhere:

[patch.crates-io]
# This is needed to handle cross-compilation of libpq.
pq-sys = { git = 'https://github.com/golddranks/pq-sys' }

Please read the link I sent you, and then try my example project, which should be compiled and checked before every release.

TheNeikos commented 6 years ago

Hm, I'm sorry I left out a few portions of it :sweat_smile: while pasting it here. I did have it at the bottom. I will try to investigate if maybe another crate tries to link to openssl.

emk commented 6 years ago

This example code compiles and links successfully with diesel, and I use code based on the PostgreSQL version in production systems.

TheNeikos commented 6 years ago

I am using nightly, is that maybe a problem?

emk commented 6 years ago

@TheNeikos At the very least, you'd need to try FROM ekidd/rust-musl-builder:nightly to have any chance of that working. Instead, you're manually running:

RUN rustup default nightly-2017-12-20 &&  rustup target add x86_64-unknown-linux-musl

...which means that you might be overriding some of the configuration I did to get everything working. It's certainly not a supported way to use the image at all.

You could try modifying https://github.com/emk/rust-musl-builder/blob/master/Dockerfile locally to set TOOLCHAIN=nightly-2017-12-20 and then re-run ./test-image to see if it works.

TheNeikos commented 6 years ago

You could try modifying https://github.com/emk/rust-musl-builder/blob/master/Dockerfile locally to set TOOLCHAIN=nightly-2017-12-20 and then re-run ./test-image to see if it works. I tried that, it solved the ASN1_STRING_length error while compiling libinfer_schema_macros

Now I am getting the SSL_* errors, while also using the patched pq-sys. So I guess this is not meant to be right now.

Thanks for your pointers though and happy holidays :christmas_tree:

emk commented 6 years ago

I'm not sure if there's anything else I can do to help you here, but if so, please feel free to reopen the issue.