Skip to content

Commit

Permalink
Take advantage of weak features in Rust 1.60 for TLS enablement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarijnS95 committed Apr 8, 2022
1 parent 62f7b8e commit a3f872c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
27 changes: 14 additions & 13 deletions sentry/Cargo.toml
Expand Up @@ -11,6 +11,7 @@ Sentry (getsentry.com) client for rust ;)
"""
edition = "2018"
autoexamples = true
rust-version = "1.54.0"

# To build locally:
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --open
Expand Down Expand Up @@ -38,14 +39,14 @@ test = ["sentry-core/test"]
debug-logs = ["log_", "sentry-core/debug-logs"]
# transports
transport = ["reqwest", "native-tls"]
reqwest = ["reqwest_", "httpdate", "tokio"]
curl = ["curl_", "httpdate"]
surf-h1 = ["surf_/h1-client", "httpdate"]
surf = ["surf_/curl-client", "httpdate", "tokio"]
native-tls = ["reqwest_/default-tls"]
rustls = ["reqwest_/rustls-tls"]
ureq = ["ureq_/tls", "httpdate"]
ureq-native-tls = ["ureq_/native-tls", "httpdate"]
reqwest = ["dep:reqwest", "httpdate", "tokio"]
curl = ["dep:curl", "httpdate"]
surf-h1 = ["surf/h1-client", "httpdate"]
surf = ["surf/curl-client", "httpdate", "tokio"]
ureq = ["dep:ureq", "httpdate"]
# transport settings
native-tls = ["reqwest?/default-tls", "ureq?/native-tls"]
rustls = ["reqwest?/rustls-tls", "ureq?/tls"]

[dependencies]
sentry-core = { version = "0.25.0", path = "../sentry-core", features = ["client"] }
Expand All @@ -59,13 +60,13 @@ sentry-slog = { version = "0.25.0", path = "../sentry-slog", optional = true }
sentry-tower = { version = "0.25.0", path = "../sentry-tower", optional = true }
sentry-tracing = { version = "0.25.0", path = "../sentry-tracing", optional = true }
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
reqwest_ = { package = "reqwest", version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
curl_ = { package = "curl", version = "0.4.25", optional = true }
reqwest = { version = "0.11", optional = true, features = ["blocking", "json"], default-features = false }
curl = { version = "0.4.25", optional = true }
httpdate = { version = "1.0.0", optional = true }
surf_ = { package = "surf", version = "2.0.0", optional = true, default-features = false }
surf = { version = "2.0.0", optional = true, default-features = false }
serde_json = { version = "1.0.48", optional = true }
tokio = { version = "1.0", features = ["rt"], optional = true }
ureq_ = { package = "ureq", version = "2.3.0", optional = true, default-features = false }
ureq = { version = "2.3.0", optional = true, default-features = false }

[dev-dependencies]
sentry-anyhow = { path = "../sentry-anyhow" }
Expand All @@ -79,6 +80,6 @@ log_ = { package = "log", version = "0.4.8", features = ["std"] }
pretty_env_logger = "0.4.0"
slog_ = { package = "slog", version = "2.5.2" }
tokio = { version = "1.0", features = ["macros"] }
tower_ = { package = "tower", version = "0.4", features = ["util"] }
tower = { version = "0.4", features = ["util"] }
tracing_ = { package = "tracing", version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["fmt", "tracing-log"] }
2 changes: 1 addition & 1 deletion sentry/src/transports/curl.rs
@@ -1,7 +1,7 @@
use std::io::{Cursor, Read};
use std::time::Duration;

use curl_::{self as curl, easy::Easy as CurlClient};
use curl::{self as curl, easy::Easy as CurlClient};

use super::thread::TransportThread;

Expand Down
8 changes: 4 additions & 4 deletions sentry/src/transports/mod.rs
Expand Up @@ -16,22 +16,22 @@ mod tokio_thread;
#[cfg(feature = "reqwest")]
mod reqwest;
#[cfg(feature = "reqwest")]
pub use reqwest::ReqwestHttpTransport;
pub use self::reqwest::ReqwestHttpTransport;

#[cfg(feature = "curl")]
mod curl;
#[cfg(feature = "curl")]
pub use curl::CurlHttpTransport;
pub use self::curl::CurlHttpTransport;

#[cfg(feature = "surf")]
mod surf;
#[cfg(feature = "surf")]
pub use surf::SurfHttpTransport;
pub use self::surf::SurfHttpTransport;

#[cfg(feature = "ureq")]
mod ureq;
#[cfg(feature = "ureq")]
pub use ureq::UreqHttpTransport;
pub use self::ureq::UreqHttpTransport;

#[cfg(feature = "reqwest")]
type DefaultTransport = ReqwestHttpTransport;
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/transports/reqwest.rs
@@ -1,6 +1,6 @@
use std::time::Duration;

use reqwest_::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};
use reqwest::{header as ReqwestHeaders, Client as ReqwestClient, Proxy, StatusCode};

use super::tokio_thread::TransportThread;

Expand Down Expand Up @@ -31,7 +31,7 @@ impl ReqwestHttpTransport {

fn new_internal(options: &ClientOptions, client: Option<ReqwestClient>) -> Self {
let client = client.unwrap_or_else(|| {
let mut builder = reqwest_::Client::builder();
let mut builder = reqwest::Client::builder();
if let Some(url) = options.http_proxy.as_ref() {
builder = builder.proxy(Proxy::http(url.as_ref()).unwrap());
};
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/transports/surf.rs
@@ -1,6 +1,6 @@
use std::time::Duration;

use surf_::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};
use surf::{http::headers as SurfHeaders, Client as SurfClient, StatusCode};

use super::tokio_thread::TransportThread;

Expand Down
6 changes: 1 addition & 5 deletions sentry/src/transports/ureq.rs
@@ -1,8 +1,6 @@
use std::time::Duration;

#[cfg(fdoc)]
use ureq_ as ureq;
use ureq_::{Agent, AgentBuilder, Proxy};
use ureq::{Agent, AgentBuilder, Proxy};

use super::thread::TransportThread;

Expand All @@ -11,8 +9,6 @@ use crate::{sentry_debug, types::Scheme, ClientOptions, Envelope, Transport};
/// A [`Transport`] that sends events via the [`ureq`] library.
///
/// This is enabled by the `ureq` feature flag.
///
/// [`ureq`]: https://crates.io/crates/ureq
#[cfg_attr(doc_cfg, doc(cfg(feature = "ureq")))]
pub struct UreqHttpTransport {
thread: TransportThread,
Expand Down
2 changes: 1 addition & 1 deletion sentry/tests/test_tower.rs
Expand Up @@ -8,7 +8,7 @@ use sentry::{
ClientOptions, Hub,
};
use sentry_tower::SentryLayer;
use tower_::{ServiceBuilder, ServiceExt};
use tower::{ServiceBuilder, ServiceExt};

#[test]
fn test_tower_hub() {
Expand Down

0 comments on commit a3f872c

Please sign in to comment.