Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed May 18, 2024
1 parent 59632a3 commit eee16be
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 28 deletions.
80 changes: 69 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ jobs:
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://runner@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://runner@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/usr/local/opt/[email protected]/lib" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/usr/local/opt/[email protected]/lib/pkgconfig" >> $GITHUB_ENV
- name: Install mysql (MacOS M1)
if: matrix.os == 'macos-14' && matrix.backend == 'mysql'
Expand All @@ -169,6 +171,7 @@ jobs:
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://runner@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://runner@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/opt/homebrew/opt/[email protected]/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=10.5" >> $GITHUB_ENV
- name: Install sqlite (Windows)
if: runner.os == 'Windows' && matrix.backend == 'sqlite'
Expand Down Expand Up @@ -213,6 +216,7 @@ jobs:
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=C:\tools\mysql\current\lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=8.0.31" >> $GITHUB_ENV
echo "C:\tools\mysql\current\lib" >> $GITHUB_PATH
echo "C:\tools\mysql\current\bin" >> $GITHUB_PATH
dir "C:\tools\mysql\current\lib"
Expand Down Expand Up @@ -421,43 +425,45 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: "rust-src"
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
key: sqlite_bundled-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Test diesel-cli
run: cargo +nightly test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "sqlite-bundled"
run: cargo +stable test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "sqlite-bundled"

- name: Run diesel_tests with ASAN enabled
env:
RUSTC_BOOTSTRAP: 1
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 "sqlite libsqlite3-sys libsqlite3-sys/bundled libsqlite3-sys/with-asan" --target x86_64-unknown-linux-gnu
run: cargo +stable -Z build-std test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "sqlite libsqlite3-sys libsqlite3-sys/bundled libsqlite3-sys/with-asan" --target x86_64-unknown-linux-gnu

- name: Run diesel tests with ASAN enabled
env:
RUSTC_BOOTSTRAP: 1
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 "sqlite extras libsqlite3-sys libsqlite3-sys/bundled libsqlite3-sys/with-asan" --target x86_64-unknown-linux-gnu
run: cargo +stable -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@master
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: "rust-src"
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
key: postgres_bundled-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Install postgres (Linux)
run: |
sudo apt-get update
Expand All @@ -470,20 +476,72 @@ jobs:
echo $PG_DATABASE_URL
- name: Test diesel-cli
run: cargo +nightly test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "postgres-bundled"
run: cargo +stable test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "postgres-bundled"

- name: Run diesel_tests with ASAN enabled
env:
RUSTC_BOOTSTRAP: 1
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
run: cargo +stable -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:
RUSTC_BOOTSTRAP: 1
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
run: cargo +stable -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

mysql_bundled:
name: Check mysql bundled + Mysql with asan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: "rust-src"
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
key: mysql_bundled-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Install Mysql (Linux)
run: |
sudo systemctl start mysql.service
sudo apt-get update
sudo apt-get -y install libmysqlclient-dev
mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot -proot
echo "MYSQL_DATABASE_URL=mysql://root:[email protected]/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root:[email protected]/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root:[email protected]/diesel_unit_test" >> $GITHUB_ENV
- name: Test diesel-cli
env:
RUST_TEST_THREADS: 1
run: cargo +stable test --manifest-path diesel_cli/Cargo.toml --no-default-features --features "mysql-bundled"

- name: Run diesel_tests with ASAN enabled
env:
RUSTC_BOOTSTRAP: 1
RUSTFLAGS: -Zsanitizer=address
ASAN_OPTIONS: detect_stack_use_after_return=1
LSAN_OPTIONS: suppressions=suppr.txt
RUST_TEST_THREADS: 1
run: |
echo "leak:mysql_server_init" > suppr.txt
cargo +stable -Z build-std test --manifest-path diesel_tests/Cargo.toml --no-default-features --features "mysql mysqlclient-sys mysqlclient-sys/bundled mysqlclient-src/with-asan" --target x86_64-unknown-linux-gnu
- name: Run diesel tests with ASAN enabled
env:
RUSTC_BOOTSTRAP: 1
RUSTDOCFLAGS: -Zsanitizer=address
RUSTFLAGS: -Zsanitizer=address
ASAN_OPTIONS: detect_stack_use_after_return=1
LSAN_OPTIONS: suppressions=suppr.txt
RUST_TEST_THREADS: 1
run: |
echo "leak:mysql_server_init" > suppr.txt
cargo +stable -Z build-std test --manifest-path diesel/Cargo.toml --no-default-features --features "mysqlclient mysqlclient-sys mysqlclient-sys/bundled mysqlclient-src/with-asan" --target x86_64-unknown-linux-gnu
minimal_rust_version:
name: Check Minimal supported rust version (1.78.0)
Expand Down
3 changes: 2 additions & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ byteorder = { version = "1.0", optional = true }
chrono = { version = "0.4.20", optional = true, default-features = false, features = ["clock", "std"] }
libc = { version = "0.2.0", optional = true }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true, features = ["bundled_bindings"] }
mysqlclient-sys = { git = "https://github.com/xiangzhai/mysqlclient-sys.git", branch = "diesel-3929", optional = true, features = ["buildtime_bindgen"] }
mysqlclient-sys = { version = ">=0.2.5, <0.4.0", optional = true }
mysqlclient-src = { version = "0.1.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 }
Expand Down
25 changes: 13 additions & 12 deletions diesel/src/mysql/connection/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ impl BindData {
}

fn from_tpe_and_flags((tpe, flags): (ffi::enum_field_types, Flags)) -> Self {
let mut bytes = known_buffer_size_for_ffi_type(tpe)
.map(|len| vec![0; len])
.unwrap_or_default();
// newer mysqlclient versions do not accept a zero sized buffer
let len = known_buffer_size_for_ffi_type(tpe).unwrap_or(1);
let mut bytes = vec![0; len];
let length = bytes.len() as libc::c_ulong;
let capacity = bytes.capacity();
let ptr = NonNull::new(bytes.as_mut_ptr());
Expand All @@ -389,13 +389,13 @@ impl BindData {
length,
capacity,
flags,
is_null: ffi::my_bool::default(),
is_truncated: Some(ffi::my_bool::default()),
is_null: ffi::FALSE,
is_truncated: Some(ffi::FALSE),
}
}

fn is_truncated(&self) -> bool {
self.is_truncated.unwrap_or(ffi::my_bool::default()) != ffi::my_bool::default()
self.is_truncated.unwrap_or(ffi::FALSE) != ffi::FALSE
}

fn is_fixed_size_buffer(&self) -> bool {
Expand Down Expand Up @@ -712,10 +712,11 @@ impl From<(ffi::enum_field_types, Flags)> for MysqlType {
the diesel github repo."
),

_ => unreachable!(
"MYSQL_TYPE_INVALID enumerate value is 243 \
MYSQL_TYPE_BOOL Currently just a placeholder \
MYSQL_TYPE_TYPED_ARRAY Used for replication only."
t => unreachable!(
"Unsupported type encountered: {t:?}. \
If you ever see this error, something has gone wrong. \
Please open an issue at the diesel github \
repo in this case."
),
}
}
Expand Down Expand Up @@ -1267,7 +1268,7 @@ mod tests {
capacity,
length,
flags,
is_null: 0,
is_null: ffi::FALSE,
is_truncated: None,
};

Expand All @@ -1283,7 +1284,7 @@ mod tests {
capacity,
length,
flags: Flags::empty(),
is_null: 0,
is_null: ffi::FALSE,
is_truncated: None,
};

Expand Down
4 changes: 2 additions & 2 deletions diesel/src/mysql/connection/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl RawConnection {
}

fn more_results(&self) -> bool {
unsafe { ffi::mysql_more_results(self.0.as_ptr()) != ffi::my_bool::default() }
unsafe { ffi::mysql_more_results(self.0.as_ptr()) != ffi::FALSE }
}

fn next_result(&self) -> QueryResult<()> {
Expand Down Expand Up @@ -243,7 +243,7 @@ impl Drop for RawConnection {
/// > to protect the `mysql_library_init()` call. This should be done prior to
/// > any other client library call.
///
/// <https://dev.mysql.com/doc/refman/5.7/en/mysql-init.html>
/// <https://dev.mysql.com/doc/c-api/8.4/en/mysql-init.html>
static MYSQL_THREAD_UNSAFE_INIT: Once = Once::new();

fn perform_thread_unsafe_library_initialization() {
Expand Down
2 changes: 2 additions & 0 deletions diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ toml = "0.8"
url = { version = "2.2.2" }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true }
pq-sys = { version = ">=0.4, <0.6.0", optional = true }
mysqlclient-sys = { version = ">=0.2.5, <0.4.0", optional = true }
diffy = "0.3.0"
regex = "1.0.6"
serde_regex = "1.1"
Expand Down Expand Up @@ -66,6 +67,7 @@ sqlite = ["diesel/sqlite"]
mysql = ["diesel/mysql", "uses_information_schema"]
sqlite-bundled = ["sqlite", "libsqlite3-sys/bundled"]
postgres-bundled = ["postgres", "pq-sys/bundled"]
mysql-bundled = ["mysql", "mysqlclient-sys/bundled"]
uses_information_schema = []

[[test]]
Expand Down
4 changes: 2 additions & 2 deletions diesel_compile_tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions diesel_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ rand = "0.8.4"
libsqlite3-sys = { version = "0.28", optional = true }
pq-sys = { version = "0.5", optional = true }
pq-src = { version = "0.1.1", optional = true }
mysqlclient-sys = { version = ">=0.2.5, <0.4.0", optional = true }
mysqlclient-src = { version = "0.1.0", optional = true }

[features]
default = []
Expand Down

0 comments on commit eee16be

Please sign in to comment.