Skip to content

Commit d2d3be0

Browse files
committed
Take advantage of weak features in Rust 1.60 for TLS enablement
Previously it was impossible to have a unified feature named `rustls` or `native-tls` that would turn on the respective TLS backend in the chosen transport (`reqwest` or `ureq`) as a feature of `<crate>/tls` would implicitly turn on `<crate>`. Since Rust 1.60 it is now possible to specify this crate-feature enablement through the use of the question mark in `<crate>?/tls`, which will only enable the `tls` feature if `<crate>` was enabled through other means (another feature). Secondly we can now also let optional crates have the same name as a feature, and use `dep:<crate>` to refer to the crate instead of the dependency, making for a more pleasant experience without renames to underscore suffixes.
1 parent 62f7b8e commit d2d3be0

File tree

7 files changed

+24
-27
lines changed

7 files changed

+24
-27
lines changed

sentry/Cargo.toml

+14-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Sentry (getsentry.com) client for rust ;)
1111
"""
1212
edition = "2018"
1313
autoexamples = true
14+
rust-version = "1.60.0"
1415

1516
# To build locally:
1617
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --open
@@ -38,14 +39,14 @@ test = ["sentry-core/test"]
3839
debug-logs = ["log_", "sentry-core/debug-logs"]
3940
# transports
4041
transport = ["reqwest", "native-tls"]
41-
reqwest = ["reqwest_", "httpdate", "tokio"]
42-
curl = ["curl_", "httpdate"]
43-
surf-h1 = ["surf_/h1-client", "httpdate"]
44-
surf = ["surf_/curl-client", "httpdate", "tokio"]
45-
native-tls = ["reqwest_/default-tls"]
46-
rustls = ["reqwest_/rustls-tls"]
47-
ureq = ["ureq_/tls", "httpdate"]
48-
ureq-native-tls = ["ureq_/native-tls", "httpdate"]
42+
reqwest = ["dep:reqwest", "httpdate", "tokio"]
43+
curl = ["dep:curl", "httpdate"]
44+
surf-h1 = ["surf/h1-client", "httpdate"]
45+
surf = ["surf/curl-client", "httpdate", "tokio"]
46+
ureq = ["dep:ureq", "httpdate"]
47+
# transport settings
48+
native-tls = ["reqwest?/default-tls", "ureq?/native-tls"]
49+
rustls = ["reqwest?/rustls-tls", "ureq?/tls"]
4950

5051
[dependencies]
5152
sentry-core = { version = "0.25.0", path = "../sentry-core", features = ["client"] }
@@ -59,13 +60,13 @@ sentry-slog = { version = "0.25.0", path = "../sentry-slog", optional = true }
5960
sentry-tower = { version = "0.25.0", path = "../sentry-tower", optional = true }
6061
sentry-tracing = { version = "0.25.0", path = "../sentry-tracing", optional = true }
6162
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
62-
reqwest_ = { package = "reqwest", version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
63-
curl_ = { package = "curl", version = "0.4.25", optional = true }
63+
reqwest = { version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
64+
curl = { version = "0.4.25", optional = true }
6465
httpdate = { version = "1.0.0", optional = true }
65-
surf_ = { package = "surf", version = "2.0.0", optional = true, default-features = false }
66+
surf = { version = "2.0.0", optional = true, default-features = false }
6667
serde_json = { version = "1.0.48", optional = true }
6768
tokio = { version = "1.0", features = ["rt"], optional = true }
68-
ureq_ = { package = "ureq", version = "2.3.0", optional = true, default-features = false }
69+
ureq = { version = "2.3.0", optional = true, default-features = false }
6970

7071
[dev-dependencies]
7172
sentry-anyhow = { path = "../sentry-anyhow" }
@@ -79,6 +80,6 @@ log_ = { package = "log", version = "0.4.8", features = ["std"] }
7980
pretty_env_logger = "0.4.0"
8081
slog_ = { package = "slog", version = "2.5.2" }
8182
tokio = { version = "1.0", features = ["macros"] }
82-
tower_ = { package = "tower", version = "0.4", features = ["util"] }
83+
tower = { version = "0.4", features = ["util"] }
8384
tracing_ = { package = "tracing", version = "0.1" }
8485
tracing-subscriber = { version = "0.3", features = ["fmt", "tracing-log"] }

sentry/src/transports/curl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::{Cursor, Read};
22
use std::time::Duration;
33

4-
use curl_::{self as curl, easy::Easy as CurlClient};
4+
use curl::{self as curl, easy::Easy as CurlClient};
55

66
use super::thread::TransportThread;
77

sentry/src/transports/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ mod tokio_thread;
1616
#[cfg(feature = "reqwest")]
1717
mod reqwest;
1818
#[cfg(feature = "reqwest")]
19-
pub use reqwest::ReqwestHttpTransport;
19+
pub use self::reqwest::ReqwestHttpTransport;
2020

2121
#[cfg(feature = "curl")]
2222
mod curl;
2323
#[cfg(feature = "curl")]
24-
pub use curl::CurlHttpTransport;
24+
pub use self::curl::CurlHttpTransport;
2525

2626
#[cfg(feature = "surf")]
2727
mod surf;
2828
#[cfg(feature = "surf")]
29-
pub use surf::SurfHttpTransport;
29+
pub use self::surf::SurfHttpTransport;
3030

3131
#[cfg(feature = "ureq")]
3232
mod ureq;
3333
#[cfg(feature = "ureq")]
34-
pub use ureq::UreqHttpTransport;
34+
pub use self::ureq::UreqHttpTransport;
3535

3636
#[cfg(feature = "reqwest")]
3737
type DefaultTransport = ReqwestHttpTransport;

sentry/src/transports/reqwest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use reqwest_::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};
3+
use reqwest::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};
44

55
use super::tokio_thread::TransportThread;
66

@@ -31,7 +31,7 @@ impl ReqwestHttpTransport {
3131

3232
fn new_internal(options: &ClientOptions, client: Option<ReqwestClient>) -> Self {
3333
let client = client.unwrap_or_else(|| {
34-
let mut builder = reqwest_::Client::builder();
34+
let mut builder = reqwest::Client::builder();
3535
if let Some(url) = options.http_proxy.as_ref() {
3636
builder = builder.proxy(Proxy::http(url.as_ref()).unwrap());
3737
};

sentry/src/transports/surf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use surf_::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
3+
use surf::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
44

55
use super::tokio_thread::TransportThread;
66

sentry/src/transports/ureq.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::time::Duration;
22

3-
#[cfg(fdoc)]
4-
use ureq_ as ureq;
5-
use ureq_::{Agent, AgentBuilder, Proxy};
3+
use ureq::{Agent, AgentBuilder, Proxy};
64

75
use super::thread::TransportThread;
86

@@ -11,8 +9,6 @@ use crate::{sentry_debug, types::Scheme, ClientOptions, Envelope, Transport};
119
/// A [`Transport`] that sends events via the [`ureq`] library.
1210
///
1311
/// This is enabled by the `ureq` feature flag.
14-
///
15-
/// [`ureq`]: https://crates.io/crates/ureq
1612
#[cfg_attr(doc_cfg, doc(cfg(feature = "ureq")))]
1713
pub struct UreqHttpTransport {
1814
thread: TransportThread,

sentry/tests/test_tower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sentry::{
88
ClientOptions, Hub,
99
};
1010
use sentry_tower::SentryLayer;
11-
use tower_::{ServiceBuilder, ServiceExt};
11+
use tower::{ServiceBuilder, ServiceExt};
1212

1313
#[test]
1414
fn test_tower_hub() {

0 commit comments

Comments
 (0)