Skip to content

Commit

Permalink
Merge pull request #394 from blackbeam/default-features
Browse files Browse the repository at this point in the history
Reduce the set of default features
  • Loading branch information
blackbeam authored Jan 17, 2025
2 parents d3e16d9 + cf338de commit bf8640d
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 162 deletions.
95 changes: 34 additions & 61 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,32 @@ path = "src/lib.rs"
debug = true

[features]
default = [
"native-tls",
default = ["minimal", "derive", "buffer-pool"]
default-rust = ["minimal-rust", "derive", "buffer-pool"]

# It is necessary to choose one of `flate2` backends.
"flate2/zlib",

# set of enabled-by-default mysql_common features
"bigdecimal",
"rust_decimal",
"time",
"frunk",
"binlog",

"derive",
# use global buffer pool by default
"buffer-pool",
]
default-rustls = [
"rustls-tls",

# default-rustls uses rust_backend for flate2.
"flate2/rust_backend",

"bigdecimal",
"rust_decimal",
"time",
"frunk",
"binlog",

"derive",
"buffer-pool",
]
# minimal feature set with system flate2 impl
minimal = ["flate2/zlib"]
# minimal feature set with rust flate2 impl
minimal-rust = ["flate2/rust_backend"]
rustls-tls = ["rustls", "webpki", "webpki-roots", "rustls-pemfile"]

# native TLS backend
native-tls = ["dep:native-tls"]
# rustls TLS backend with aws_lc_rs provider
rustls-tls = ["rustls", "rustls/aws_lc_rs"]
# rustls TLS backend with ring provider
rustls-tls-ring = ["rustls", "rustls/ring"]
# rustls TLS backend (no provider)
rustls = [
"dep:rustls",
"rustls/logging",
"rustls/std",
"rustls/tls12",
"webpki",
"webpki-roots",
"rustls-pemfile",
]

# global buffer pool
buffer-pool = []
nightly = []

Expand All @@ -75,47 +64,31 @@ frunk = ["mysql_common/frunk"]
binlog = ["mysql_common/binlog"]

[dev-dependencies]
mysql_common = { version = "0.34", features = ["time", "frunk"] }
rand = "0.8.2"
serde_derive = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
time = "0.3"
frunk = "0.4"

[dependencies]
bufstream = "~0.1"
bytes = "1.0.1"
crossbeam = "0.8.1"
io-enum = "1.0.0"
crossbeam-queue = "0.3.12"
flate2 = { version = "1.0", default-features = false }
lru = "0.12"
mysql_common = { version = "0.32", default-features = false }
socket2 = "0.5.2"
io-enum = "1.0.0"
lru = { version = "0.12", default-features = false }
mysql_common = { version = "0.34", default-features = false }
native-tls = { version = "0.2.3", optional = true }
pem = "3"
percent-encoding = "2.1.0"
serde = "1"
serde_json = "1"
rustls = { version = "0.23", optional = true, default-features = false }
rustls-pemfile = { version = "2.1", optional = true }
socket2 = "0.5.2"
twox-hash = { version = "2", default-features = false, features = ["xxhash64"] }
url = "2.1"

[dependencies.native-tls]
version = "0.2.3"
optional = true

[dependencies.rustls]
version = "0.23"
optional = true

[dependencies.rustls-pemfile]
version = "2.1"
optional = true

[dependencies.webpki]
version = "0.22.0"
features = ["std"]
optional = true

[dependencies.webpki-roots]
version = "0.26"
optional = true
webpki = { version = "0.22", features = ["std"], optional = true }
webpki-roots = { version = "0.26", optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
named_pipe = "~0.4"
Expand Down
84 changes: 46 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This crate offers:
Features:

* macOS, Windows and Linux support;
* TLS support via **nativetls** or **rustls** (see the [SSL Support](#ssl-support) section);
* TLS support via **native-tls** or **rustls** (see the [SSL Support](#ssl-support) section);
* MySql text protocol support, i.e. support of simple text queries and text result sets;
* MySql binary protocol support, i.e. support of prepared statements and binary result sets;
* support of multi-result sets;
Expand Down Expand Up @@ -110,45 +110,44 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {

* feature sets:

* **default** – includes default `mysql_common` features, `native-tls`, `buffer-pool`,
`flate2/zlib` and `derive`
* **default-rustls** - same as `default` but with `rustls-tls` instead of `native-tls`
and `flate2/rust_backend` instead of `flate2/zlib`
* **minimal** - includes `flate2/zlib`
* **default** – includes `buffer-pool` `flate2/zlib` and `derive`
* **default-rust** - same as `default` but with `flate2/rust_backend` instead of `flate2/zlib`
* **minimal** - includes `flate2/zlib` only
* **minimal-rust** - includes `flate2/rust_backend` only

* crate's features:

* **native-tls** (enabled by default) – specifies `native-tls` as the TLS backend
(see the [SSL Support](#ssl-support) section)
* **rustls-tls** (disabled by default) – specifies `rustls` as the TLS backend
(see the [SSL Support](#ssl-support) section)
* **buffer-pool** (enabled by default) – enables buffer pooling
* features:
* **buffer-pool** – enables buffer pooling
(see the [Buffer Pool](#buffer-pool) section)
* **derive** (enabled by default) – reexports derive macros under `prelude`
* **derive** – reexports derive macros under `prelude`
(see [corresponding section][derive_docs] in the `mysql_common` documentation)

* external features enabled by default:
* TLS/SSL related features:

* for the `flate2` crate (please consult `flate2` crate documentation for available features):

* **flate2/zlib** (necessary) – `zlib` backend is chosed by default.
* **native-tls** – specifies `native-tls` as the TLS backend
(see the [SSL Support](#ssl-support) section)
* **rustls-tls** – specifies `rustls` as the TLS backend using `aws-lc-rs` crypto provider
(see the [SSL Support](#ssl-support) section)
* **rustls-tls-ring** – specifies `rustls` as the TLS backend using `ring` crypto provider
(see the [SSL Support](#ssl-support) section)
* **rustls** - specifies `rustls` as the TLS backend without crypto provider
(see the [SSL Support](#ssl-support) section)

* for the `mysql_common` crate (please consult `mysql_common` crate documentation for available features):
* features proxied from `mysql_common`:

* **mysql_common/bigdecimal03** – the `bigdecimal03` is enabled by default
* **mysql_common/rust_decimal** – the `rust_decimal` is enabled by default
* **mysql_common/time03** – the `time03` is enabled by default
* **mysql_common/uuid** – the `uuid` is enabled by default
* **mysql_common/frunk** – the `frunk` is enabled by default
* **derive** - see [this table][common_features].
* **chrono** - see [this table][common_features].
* **time** - see [this table][common_features].
* **bigdecimal** - see [this table][common_features].
* **rust_decimal** - see [this table][common_features].
* **frunk** - see [this table][common_features].
* **binlog** - see [this table][common_features].

Please note, that you'll need to reenable required features if you are using `default-features = false`:

```toml
[dependencies]
# Lets say that we want to use the `rustls-tls` feature:
mysql = { version = "*", default-features = false, features = ["minimal", "rustls-tls"] }
# Previous line disables default mysql features,
# so now we need to choose desired mysql_common features:
mysql_common = { version = "*", default-features = false, features = ["bigdecimal03", "time03", "uuid"]}
# Lets say that we want to use only the `rustls-tls` feature:
mysql = { version = "*", default-features = false, features = ["minimal-rust", "rustls-tls"] }
```

### API Documentation
Expand Down Expand Up @@ -418,7 +417,7 @@ let mut conn = Conn::new(get_opts())?;
let val: Option<String> = conn.query_first("SELECT 'foo'")?;
assert_eq!(val.unwrap(), "foo");

// Example of a mutli-column row conversion to an inferred type:
// Example of a multi-column row conversion to an inferred type:
let row = conn.query_first("SELECT 255, 256")?;
assert_eq!(row, Some((255u8, 256u16)));

Expand Down Expand Up @@ -501,6 +500,7 @@ or when you need to parse JSON cell as a struct.
```rust
use mysql::*;
use mysql::prelude::*;
use serde::{Deserialize, Serialize};

/// Serializable structure.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -662,7 +662,7 @@ assert!(conn_2.exec_drop(&stmt_1, ("foo",)).is_err());

##### Note

Statemet cache only works for:
Statement cache only works for:
1. for raw [`Conn`]
2. for [`PooledConn`]:
* within its lifetime if [`PoolOpts::reset_connection`] is `true`
Expand All @@ -684,7 +684,7 @@ Statement cache is completely disabled if `stmt_cache_size` is zero.

* you should be aware of the [`max_prepared_stmt_count`][max_prepared_stmt_count]
option of the MySql server. If the number of active connections times the value
of `stmt_cache_size` is greater, than you could receive an error while prepareing
of `stmt_cache_size` is greater, than you could receive an error while preparing
another statement.

#### Named parameters
Expand Down Expand Up @@ -742,7 +742,7 @@ from the set of default crate features (see the [Crate Features](#crate-features

`BinQuery` and `BatchQuery` traits covers the set of `Queryable::exec*` methods from
the perspective of a query, i.e. `BinQuery` is something, that can be performed if suitable
connection is given (see [`TextQuery`](#the-textquery-trat) section for the list
connection is given (see [`TextQuery`](#the-textquery-trait) section for the list
of suitable connections).

As with the [`TextQuery`](#the-textquery-trait) you can give away the connection and acquire
Expand Down Expand Up @@ -813,10 +813,17 @@ execution.

SSL support comes in two flavors:

1. Based on **native-tls** – this is the default option, that usually works without pitfalls
(see the `native-tls` crate feature).
2. Based on **rustls** – TLS backend written in Rust. Please use the `rustls-tls` crate feature
to enable it (see the [Crate Features](#crate-features) section).
1. Based on the `native-tls` crate – native TLS backend.

This uses the native OS SSL/TLS provider. Enabled by the **rustls-tls** feature.

2. Based on the `rustls` – TLS backend written in Rust. You have three options here:

1. **rustls-tls** feature enables `rustls` backend with `aws-lc-rs` crypto provider
2. **rustls-tls-ring** feature enables `rustls` backend with `ring` crypto provider
3. **rustls** feature enables `rustls` backend without crypto provider — you have to
install your own provider to avoid "no process-level CryptoProvider available" error
(see relevant section of the [`rustls` crate docs](https://docs.rs/rustls))

Please also note a few things about **rustls**:

Expand All @@ -827,7 +834,8 @@ SSL support comes in two flavors:
[crate docs]: https://docs.rs/mysql
[mysql_common docs]: https://docs.rs/mysql_common
[max_prepared_stmt_count]: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_prepared_stmt_count

[derive_docs]: https://docs.rs/mysql_common/latest/mysql_common/#derive-macros
[common_features]: https://docs.rs/mysql_common/latest/mysql_common/#crate-features

## Changelog

Expand Down
2 changes: 1 addition & 1 deletion README.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Gitter](https://badges.gitter.im/rust-mysql/community.svg)](https://gitter.im/rust-mysql/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

[![Crates.io](https://img.shields.io/crates/v/mysql.svg)](https://crates.io/crates/mysql)
{{badges}}
[![Build Status](https://dev.azure.com/aikorsky/mysql%20Rust/_apis/build/status/blackbeam%2Erust%2Dmysql%2Dsimple)](https://dev.azure.com/aikorsky/mysql%20Rust/_build/latest?definitionId=1)

# {{crate}}

Expand Down
22 changes: 11 additions & 11 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
displayName: lint
- bash: |
cargo check
cargo check --no-default-features --features default-rustls
cargo check --no-default-features --features default-rust
cargo check --no-default-features --features minimal
displayName: Run check
Expand All @@ -53,7 +53,7 @@ jobs:
displayName: Install rust (MacOs)
- bash: |
cargo check
cargo check --no-default-features --features default-rustls
cargo check --no-default-features --features default-rust
cargo check --no-default-features --features minimal
displayName: Run check
Expand Down Expand Up @@ -94,12 +94,12 @@ jobs:
displayName: Install Rust (Windows)
- bash: |
SSL=false COMPRESS=false cargo test
SSL=true COMPRESS=false cargo test
SSL=true COMPRESS=false cargo test --features native-tls
SSL=false COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test
SSL=true COMPRESS=true cargo test --features native-tls
SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog
SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls-ring,minimal-rust,time,frunk,binlog
SSL=false COMPRESS=true cargo test --no-default-features --features minimal,time,frunk,binlog
SSL=false COMPRESS=false cargo test --no-default-features --features minimal,time,frunk,binlog
Expand Down Expand Up @@ -175,11 +175,11 @@ jobs:
if [[ "5.6" != "$(DB_VERSION)" ]]; then SSL=true; else DATABASE_URL="mysql://root2:password@localhost/mysql?secure_auth=false"; fi
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL cargo test --features native-tls"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=$SSL COMPRESS=true cargo test --features native-tls"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls-ring,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features minimal,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features minimal,time,frunk,binlog"
Expand Down Expand Up @@ -245,11 +245,11 @@ jobs:
- bash: |
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true cargo test --features native-tls"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --features native-tls"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=false cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=true COMPRESS=true cargo test --no-default-features --features rustls-tls-ring,minimal-rust,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=true cargo test --no-default-features --features minimal,time,frunk,binlog"
docker exec container bash -l -c "cd \$HOME && DATABASE_URL=$DATABASE_URL SSL=false COMPRESS=false cargo test --no-default-features --features minimal,time,frunk,binlog"
Expand Down
2 changes: 1 addition & 1 deletion src/buffer_pool/enabled.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "buffer-pool")]

use crossbeam::queue::ArrayQueue;
use crossbeam_queue::ArrayQueue;

use std::{
mem::take,
Expand Down
9 changes: 7 additions & 2 deletions src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ mod test {
from_value::<String>(row1.0.clone()),
from_value::<i32>(row1.1.clone()),
from_value::<u32>(row1.2.clone()),
from_value::<PrimitiveDateTime>(row1.3.clone()),
from_value::<time::PrimitiveDateTime>(row1.3.clone()),
from_value::<f32>(row1.4.clone()),
),
)
Expand Down Expand Up @@ -1850,7 +1850,11 @@ mod test {

let plugins: &[&str] =
if conn.0.mariadb_server_version.is_none() && conn.server_version() >= (5, 8, 0) {
&["mysql_native_password", "caching_sha2_password"]
if conn.server_version() >= (8, 4, 0) {
&["caching_sha2_password"]
} else {
&["mysql_native_password", "caching_sha2_password"]
}
} else {
&["mysql_native_password"]
};
Expand Down Expand Up @@ -2299,6 +2303,7 @@ mod test {
#[test]
fn should_handle_json_columns() {
use crate::{Deserialized, Serialized};
use serde::{Deserialize, Serialize};
use serde_json::Value as Json;
use std::str::FromStr;

Expand Down
Loading

0 comments on commit bf8640d

Please sign in to comment.