Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiangzhai mysqlclient 8.3 #4027

Merged
merged 10 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 71 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 "MYSQLCLIENT_VERSION=10.5" >> $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,74 @@ 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 llvm
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
RUST_TEST_THREADS: 1
ASAN_OPTIONS: symbolize=1,detect_stack_use_after_return=1
ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer
LSAN_OPTIONS: suppressions=/tmp/suppr.txt
run: |
echo "leak:mysql_server_init" > /tmp/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
RUST_TEST_THREADS: 1
ASAN_OPTIONS: symbolize=1,detect_stack_use_after_return=1
ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer
LSAN_OPTIONS: suppressions=/tmp/suppr.txt
run: |
echo "leak:mysql_server_init" > /tmp/suppr.txt
cargo +stable -Z build-std test --manifest-path diesel/Cargo.toml --no-default-features --features "mysql 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 = { version = "0.2.5", optional = true }
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.7.0", optional = true }
pq-src = { version = "0.1", optional = true }
quickcheck = { version = "1.0.3", optional = true }
Expand Down
25 changes: 16 additions & 9 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: 0,
is_truncated: Some(0),
is_null: ffi::FALSE,
is_truncated: Some(ffi::FALSE),
}
}

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

fn is_fixed_size_buffer(&self) -> bool {
Expand Down Expand Up @@ -423,7 +423,7 @@ impl BindData {
}

pub(super) fn is_null(&self) -> bool {
self.is_null != 0
self.is_null != ffi::my_bool::default()
}

fn update_buffer_length(&mut self) {
Expand Down Expand Up @@ -711,6 +711,13 @@ impl From<(ffi::enum_field_types, Flags)> for MysqlType {
something has gone wrong. Please open an issue at \
the diesel github repo."
),

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 @@ -1261,7 +1268,7 @@ mod tests {
capacity,
length,
flags,
is_null: 0,
is_null: ffi::FALSE,
is_truncated: None,
};

Expand All @@ -1277,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()) != 0 }
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
4 changes: 3 additions & 1 deletion diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ url = { version = "2.2.2" }
libsqlite3-sys = { version = ">=0.17.2, <0.29.0", optional = true }
pq-sys = { version = ">=0.4, <0.7.0", optional = true }
openssl-sys = { version = "0.9.93", features = ["vendored"], 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,7 +67,8 @@ 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", "openssl-sys"]
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