Closed manifest closed 5 years ago
The same error with the command:
OPENSSL_STATIC=yes OPENSSL_LIB_DIR=/musl/lib/ OPENSSL_INCLUDE_DIR=/musl/include PQ_LIB_STATIC=yes PQ_LIB_DIR=/musl/lib/ cargo build --release
And Cargo.toml
[dependencies]
diesel = { version = "1.3.3", features = ["postgres", "uuid", "serde_json", "r2d2"] }
openssl = "*"
pq-sys = "*"
[patch.crates-io]
diesel = { git = "https://github.com/diesel-rs/diesel", rev = "59aa49b" }
diesel_derives = { git = "https://github.com/diesel-rs/diesel", rev = "59aa49b" }
I've played around libpg compilation adding --with-openssl
to postgresql`s configure script and start getting an error on compilation
= note: /build/target/x86_64-unknown-linux-musl/release/deps/libpq_sys-784bf4f1583faa91.rlib(fe-secure-openssl.o): In function `pgtls_init':
fe-secure-openssl.c:(.text+0xf48): undefined reference to `OPENSSL_config'
collect2: error: ld returned 1 exit status
cd postgresql-$PQ_VER && \
CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \
+ --with-openssl \
Hey, thanks for raising this! This should indeed be supported. curl goes through the same dance.
It's probably a bit annoying to get it to work though. I'll try to have a look on the weekend, but can't promise anything.
In the mean time, any chance you can commit what you have as a test case in a PR?
@clux I've published a test case for the issue here.
Steps to reproduce:
Create a database
## Database conenction URL must contain `?sslmode=require`
## query string parameter to reproduce the issue
export DATABASE_URL='postgres://localhost:5432/diesel-muslrust-example?sslmode=require'
diesel setup --database-url ${DATABASE_URL}
Build and run a docker container
docker build -t diesel-muslrust-example -f docker/Dockerfile .
docker run --rm -ti --entrypoint=/bin/sh diesel-muslrust-example
Run the example app from within the container
## The app reads 'DATABASE_URL' from environment variable, so it should be exported
export DATABASE_URL=''
RUST_LOG=diesel_muslrust_example=info /app/diesel-muslrust-example
You should see an error after connection will fail with timeout
thread 'main' panicked at 'Error creating a database pool: Error(Some("sslmode value \"require\" invalid when SSL support is not compiled in\n"))', src/libcore/result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
@clux have you had time to take a look on this one?
Ah, sorry not yet. Busy weeks :slightly_frowning_face:
Had a bit of a go today and added failing tests from your code in https://github.com/clux/muslrust/commit/16774454b092795300f94c6c39d7f7233a121140
Unfortunately, no matter what permutations i tried libpq
will build, but cargo build will fail to link due to missing SSL_ symbols. Leaving a comment for the future with current status.
Testing method now is:
Dockerfile
make clean
make build
make test-dieselpgssl
There's quite a lot of flags in libpq's ./configure
though:
There might be one in there that'll fix it. Otherwise, there might be some magic in https://github.com/sgrif/pq-sys/blob/master/build.rs that we can use.
oh, and saw this once during compilation of libpq:
configure: WARNING: openssl/ssl.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: openssl/ssl.h: proceeding with the compiler's result
got rid of this warning by passing:
--with-libraries=$PREFIX/lib \
--with-includes=$PREFIX/include \
to ./configure
. didn't seem to help any further though.
Another diff that may or may not help bring this closer:
diff --git a/Dockerfile b/Dockerfile
index 9899a4f..46448c1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -45,7 +45,7 @@ RUN curl https://sh.rustup.rs -sSf | \
ENV SSL_VER="1.0.2q" \
CURL_VER="7.64.0" \
ZLIB_VER="1.2.11" \
- PQ_VER="10.6" \
+ PQ_VER="9.6.8" \
SQLITE_VER="3270200" \
CC=musl-gcc \
PREFIX=/musl \
@@ -91,10 +91,14 @@ RUN curl -sSL https://curl.haxx.se/download/curl-$CURL_VER.tar.gz | tar xz && \
# Build libpq
# TODO: fix so that --with-openssl works with pqssl tests
-RUN curl -sSL https://ftp.postgresql.org/pub/source/v$PQ_VER/postgresql-$PQ_VER.tar.gz | tar xz && \
- cd postgresql-$PQ_VER && \
+RUN curl -sSL https://ftp.postgresql.org/pub/source/v$PQ_VER/postgresql-$PQ_VER.tar.gz | tar xz
+RUN cd postgresql-$PQ_VER && \
CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \
--without-readline \
+ --with-openssl \
+ --with-libraries=$PREFIX/lib \
+ --with-includes=$PREFIX/include \
+ --oldincludedir=/usr/include \
--prefix=$PREFIX --host=x86_64-unknown-linux-musl && \
cd src/interfaces/libpq make -s -j$(nproc) all-static-lib && make -s install install-lib-static && \
cd ../../bin/pg_config && make -j $(nproc) && make install && \
@@ -121,13 +125,19 @@ ENV PATH=$PREFIX/bin:$PATH \
PKG_CONFIG_ALLOW_CROSS=true \
PKG_CONFIG_ALL_STATIC=true \
PQ_LIB_STATIC_X86_64_UNKNOWN_LINUX_MUSL=true \
+ PQ_LIB_STATIC=true \
+ PQ_LIB_DIR=$PREFIX/lib/ \
+ OPENSSL_LIB_DIR=$PREFIX/lib/ \
+ OPENSSL_INCLUDE_DIR=$PREFIX/include \
+ DEP_OPENSSL_INCLUDE=$PREFIX/include/ \
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
OPENSSL_STATIC=true \
OPENSSL_DIR=$PREFIX \
SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt \
SSL_CERT_DIR=/etc/ssl/certs \
- LIBZ_SYS_STATIC=1
+ LIBZ_SYS_STATIC=1 \
+ TARGET=musl
# Allow ditching the -w /volume flag to docker run
WORKDIR /volume
the issue might be libpq
configuration based on this output from its detection:
checking for CRYPTO_new_ex_data in -lcrypto... yes
checking for SSL_new in -lssl... yes
checking for SSL_get_current_compression... yes
checking for OPENSSL_init_ssl... no
checking for BIO_get_data... no
checking for BIO_meth_new... no
checking for ASN1_STRING_get0_data... no
checking for RAND_OpenSSL... no
checking for CRYPTO_lock... yes
but maybe that's just openssl 1.1 stuff it's testing for :face_with_head_bandage:
Hello! I'm the maintainer of rust-musl-builder
, and we ran into this problem lately. You might be interested in the following issues:
TL;dr: It's possible to work around this by adding this to main.rs
:
extern crate openssl;
#[macro_use]
extern crate diesel;
...but the workaround might break with certain projects or releases of Rust. I've filed a bug upstream to investigate further: https://github.com/sgrif/pq-sys/issues/25
Oh wow, thanks a lot @emk ! It does look like the order of the includes actually fixes this!
Had a quick check compiling pg with --with-openssl
and make test-dieselpgssl
now both links and runs in this repo without ssl errors.
Have made openssl required now, since there's now way of having the support without pulling in the crate, but it's documented in the main README. Will keep an eye on pq-sys#25 for a potential future improvement on this.
I'm getting an error from the application with Diesel dependency that should have compiled statically with SSL
I've compiled application with the following command
Entire Dockerfile
App's Cargo.toml