Skip to content

Commit

Permalink
diesel requires openssl now to work - for #49
Browse files Browse the repository at this point in the history
better to have openssl support and require the crate to be pulled in,
than to not require the crate, but not support sslmode=require.
  • Loading branch information
clux committed Apr 25, 2019
1 parent 28e1e4c commit 740221b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 71 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ RUN curl -sSL https://curl.haxx.se/download/curl-$CURL_VER.tar.gz | tar xz && \
cd .. && rm -rf curl-$CURL_VER

# 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 && \
CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ test-pq:
./test.sh pq
test-dieselpg:
./test.sh dieselpg
test-dieselpgssl:
./test.sh dieselpgssl
test-dieselsqlite:
./test.sh dieselsqlite
test-ssl:
Expand All @@ -41,6 +39,6 @@ clean-builds:
sudo rm -f test/dieselsqlitecrate/main.db
clean: clean-docker clean-lock clean-builds

test: test-plain test-ssl test-pq test-serde test-curl test-zlib test-hyper test-dieselpgssl test-dieselsqlite
test: test-plain test-ssl test-pq test-serde test-curl test-zlib test-hyper test-dieselpg test-dieselsqlite
.PHONY: test-plain test-ssl test-pq test-rocket test-serde test-curl test-zlib test-hyper test-dieselpg test-dieselsqlite

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ Works without fork now. See the [test/dieselpgcrate](./test/dieselpgcrate) for h

For stuff like `infer_schema!` to work you need to explicitly pass on `-e DATABASE_URL=$DATABASE_URL` to the `docker run`. It's probably easier to just make `diesel print-schema > src/schema.rs` part of your migration setup though.

Note that diesel compiles with `openssl` statically since `1.34.0`, so you need to include the `openssl` crate **before** `diesel` due to [pq-sys#25](https://github.com/sgrif/pq-sys/issues/25):

```rs
extern crate openssl;
#[macro_use] extern crate diesel;
```

This is true even if you connect without `sslmode=require`.

## Caching Cargo Locally
Repeat builds locally are always from scratch (thus slow) without a cached cargo directory. You can set up a docker volume by just adding `-v cargo-cache:/root/.cargo/registry` to the docker run command.

Expand Down
3 changes: 2 additions & 1 deletion test/dieselpgcrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ name = "dieselpgcrate"
version = "0.1.0"

[dependencies]
diesel = { version = "1.2.*", features = ["postgres"] }
diesel = { version = "1.4.*", features = ["postgres"] }
openssl = "*"
9 changes: 6 additions & 3 deletions test/dieselpgcrate/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[macro_use]
extern crate diesel;
// The order of these extern crate lines matter for ssl!
extern crate openssl;
#[macro_use] extern crate diesel;
// openssl must be included before diesel atm.

mod schema {
table! {
Expand Down Expand Up @@ -35,7 +37,8 @@ use diesel::prelude::*;
use diesel::pg::PgConnection;

fn main() {
let database_url = std::env::var("DATABASE_URL").unwrap_or("postgres://localhost?connect_timeout=1".into());
let database_url = std::env::var("DATABASE_URL")
.unwrap_or("postgres://localhost?connect_timeout=1&sslmode=require".into());
match PgConnection::establish(&database_url) {
Err(e) => {
println!("Should fail to connect here:");
Expand Down
12 changes: 0 additions & 12 deletions test/dieselpgsslcrate/Cargo.toml

This file was deleted.

15 changes: 0 additions & 15 deletions test/dieselpgsslcrate/src/db.rs

This file was deleted.

30 changes: 0 additions & 30 deletions test/dieselpgsslcrate/src/main.rs

This file was deleted.

6 changes: 0 additions & 6 deletions test/dieselpgsslcrate/src/schema.rs

This file was deleted.

0 comments on commit 740221b

Please sign in to comment.