Skip to content

Commit

Permalink
Bump pq-sys to 0.5
Browse files Browse the repository at this point in the history
This commit increases the maximal supported version of pq-sys to include
support for 0.5. That release contains bundling support for libpq and
support for building with address sanitizers enabled. This PR adds the
relevant features to diesel_cli to allow using the bundling support + it
adds a CI job for also running tests with address sanitizers enabled.
  • Loading branch information
weiznich committed Feb 7, 2024
1 parent 1c24bf6 commit 6f4b3bb
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 19 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:
jobs:
check_and_test:
name: Check
needs: [sqlite_bundled, rustfmt_and_clippy]
needs: [sqlite_bundled, rustfmt_and_clippy, postgres_bundled]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -443,6 +443,48 @@ jobs:
RUSTFLAGS: -Zsanitizer=address
ASAN_OPTIONS: detect_stack_use_after_return=1
run: cargo +nightly -Z build-std test --manifest-path diesel/Cargo.toml --no-default-features --features "sqlite extras libsqlite3-sys libsqlite3-sys/bundled libsqlite3-sys/with-asan" --target x86_64-unknown-linux-gnu
postgres_bundled:
name: Check postgres bundled + Postgres with asan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
components: "rust-src"
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: postgres_bundled-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Install postgres (Linux)
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql valgrind
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/10/main/pg_hba.conf
sudo service postgresql restart && sleep 3
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo service postgresql restart && sleep 3
echo "PG_DATABASE_URL=postgres://postgres:postgres@localhost/" >> $GITHUB_ENV
- name: Install cargo valgrind
run: cargo +nightly install cargo-valgrind
- name: Test diesel-cli
run: cargo +nightly valgrind test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "postgres-bundled"

- name: Run diesel_tests with ASAN enabled
env:
RUSTFLAGS: -Zsanitizer=address
ASAN_OPTIONS: detect_stack_use_after_return=1
run: cargo +nightly -Z build-std test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "postgres pq-sys pq-sys/bundled pq-src/with-asan" --target x86_64-unknown-linux-gnu

- name: Run diesel tests with ASAN enabled
env:
RUSTDOCFLAGS: -Zsanitizer=address
RUSTFLAGS: -Zsanitizer=address
ASAN_OPTIONS: detect_stack_use_after_return=1
run: cargo +nightly -Z build-std test --manifest-path diesel/Cargo.toml --no-default-features --features "postgres pq-sys pq-sys/bundled pq-src/with-asan" --target x86_64-unknown-linux-gnu

minimal_rust_version:
name: Check Minimal supported rust version (1.70.0)
Expand Down
3 changes: 2 additions & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ chrono = { version = "0.4.20", optional = true, default-features = false, featur
libc = { version = "0.2.0", optional = true }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true, features = ["bundled_bindings"] }
mysqlclient-sys = { version = "0.2.5", optional = true }
pq-sys = { version = "0.4.0", optional = true }
pq-sys = { version = ">=0.4.0, <0.6.0", optional = true }
pq-src = { version = "0.1", optional = true }
quickcheck = { version = "1.0.3", optional = true }
serde_json = { version = ">=0.8.0, <2.0", optional = true }
url = { version = "2.1.0", optional = true }
Expand Down
13 changes: 7 additions & 6 deletions diesel/src/pg/types/floats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum PgNumeric {
}

#[derive(Debug, Clone, Copy)]
#[allow(dead_code)] // it's there for debug
struct InvalidNumericSign(u16);

impl ::std::fmt::Display for InvalidNumericSign {
Expand All @@ -62,14 +63,14 @@ impl FromSql<sql_types::Numeric, Pg> for PgNumeric {

match sign {
0 => Ok(PgNumeric::Positive {
weight: weight,
scale: scale,
digits: digits,
weight,
scale,
digits,
}),
0x4000 => Ok(PgNumeric::Negative {
weight: weight,
scale: scale,
digits: digits,
weight,
scale,
digits,
}),
0xC000 => Ok(PgNumeric::NaN),
invalid => Err(Box::new(InvalidNumericSign(invalid))),
Expand Down
4 changes: 3 additions & 1 deletion diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde = { version = "1.0.0", features = ["derive"] }
toml = "0.8"
url = { version = "2.2.2" }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true }
pq-sys = { version = "0.5.0", optional = true }
diffy = "0.3.0"
regex = "1.0.6"
serde_regex = "1.1"
Expand Down Expand Up @@ -61,13 +62,14 @@ postgres = ["diesel/postgres", "uses_information_schema"]
sqlite = ["diesel/sqlite"]
mysql = ["diesel/mysql", "uses_information_schema"]
sqlite-bundled = ["sqlite", "libsqlite3-sys/bundled"]
postgres-bundled = ["postgres", "pq-sys/bundled"]
uses_information_schema = []

[[test]]
name = "tests"

[package.metadata.dist]
features = ["sqlite-bundled"]
features = ["sqlite-bundled", "postgres-bundled"]

[package.metadata.dist.dependencies.apt]
libpq-dev = '*'
Expand Down
6 changes: 3 additions & 3 deletions diesel_derives/src/parsers/belongs_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::{Ident, TypePath};
use crate::util::{parse_eq, unknown_attribute, BELONGS_TO_NOTE};

enum Attr {
ForeignKey(Ident, Ident),
ForeignKey(Ident),
}

impl Parse for Attr {
Expand All @@ -15,7 +15,7 @@ impl Parse for Attr {
let name_str = name.to_string();

match &*name_str {
"foreign_key" => Ok(Attr::ForeignKey(name, parse_eq(input, BELONGS_TO_NOTE)?)),
"foreign_key" => Ok(Attr::ForeignKey(parse_eq(input, BELONGS_TO_NOTE)?)),

_ => Err(unknown_attribute(&name, &["foreign_key"])),
}
Expand All @@ -39,7 +39,7 @@ impl Parse for BelongsTo {

for attr in Punctuated::<Attr, Comma>::parse_terminated(input)? {
match attr {
Attr::ForeignKey(_, value) => foreign_key = Some(value),
Attr::ForeignKey(value) => foreign_key = Some(value),
}
}

Expand Down
6 changes: 3 additions & 3 deletions diesel_derives/src/parsers/mysql_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::{Ident, LitStr};
use crate::util::{parse_eq, unknown_attribute, MYSQL_TYPE_NOTE};

enum Attr {
Name(Ident, LitStr),
Name(LitStr),
}

impl Parse for Attr {
Expand All @@ -15,7 +15,7 @@ impl Parse for Attr {
let name_str = name.to_string();

match &*name_str {
"name" => Ok(Attr::Name(name, parse_eq(input, MYSQL_TYPE_NOTE)?)),
"name" => Ok(Attr::Name(parse_eq(input, MYSQL_TYPE_NOTE)?)),

_ => Err(unknown_attribute(&name, &["name"])),
}
Expand All @@ -32,7 +32,7 @@ impl Parse for MysqlType {

for attr in Punctuated::<Attr, Comma>::parse_terminated(input)? {
match attr {
Attr::Name(_, value) => name = Some(value),
Attr::Name(value) => name = Some(value),
}
}

Expand Down
6 changes: 3 additions & 3 deletions diesel_derives/src/parsers/sqlite_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use syn::{Ident, LitStr};
use crate::util::{parse_eq, unknown_attribute, SQLITE_TYPE_NOTE};

enum Attr {
Name(Ident, LitStr),
Name(LitStr),
}

impl Parse for Attr {
Expand All @@ -15,7 +15,7 @@ impl Parse for Attr {
let name_str = name.to_string();

match &*name_str {
"name" => Ok(Attr::Name(name, parse_eq(input, SQLITE_TYPE_NOTE)?)),
"name" => Ok(Attr::Name(parse_eq(input, SQLITE_TYPE_NOTE)?)),

_ => Err(unknown_attribute(&name, &["name"])),
}
Expand All @@ -32,7 +32,7 @@ impl Parse for SqliteType {

for attr in Punctuated::<Attr, Comma>::parse_terminated(input)? {
match attr {
Attr::Name(_, value) => name = Some(value),
Attr::Name(value) => name = Some(value),
}
}

Expand Down
2 changes: 2 additions & 0 deletions diesel_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ ipnetwork = ">=0.12.2, <0.21.0"
bigdecimal = ">= 0.0.13, < 0.5.0"
rand = "0.8.4"
libsqlite3-sys = { version = "0.28", optional = true }
pq-sys = { version = "0.5", optional = true }
pq-src = { version = "0.1", optional = true }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/composite_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "2.1", features = ["postgres" ] }
diesel = { version = "2.1", path = "../../../diesel", features = ["postgres" ] }
dotenvy = "0.15"

0 comments on commit 6f4b3bb

Please sign in to comment.