Skip to content

Commit fc558df

Browse files
committed
reuse existing feature provider-tls-s2n
1 parent 7fe6cc3 commit fc558df

7 files changed

Lines changed: 35 additions & 43 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,16 @@ jobs:
415415
run: |
416416
find . -name 'corpus.tar.gz' -exec dirname {} ';' | xargs -L 1 bash -c 'cd "$0" && rm -rf corpus && tar xf corpus.tar.gz'
417417
418-
# Force s2n-tls as the default TLS provider so the whole suite runs through s2n-tls.
418+
# Exercise s2n-tls on Windows. s2n-quic-tests enables `provider-tls-s2n`, which overrides
419+
# `provider-tls-default` and makes s2n-tls the default TLS provider on the GNU/MinGW target for tests.
419420
- name: Run cargo test
420421
shell: msys2 {0}
421422
run: |
422423
set -eu
423424
cargo test --workspace \
424425
--exclude s2n-quic-dc \
425426
--exclude s2n-quic-dc-benches \
426-
--exclude s2n-quic-dc-metrics \
427-
--features s2n-tls-default
427+
--exclude s2n-quic-dc-metrics
428428
429429
asan:
430430
runs-on: ubuntu-latest

quic/s2n-quic-tests/Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ license = "Apache-2.0"
1010
# this only contains internal tests and should not be published
1111
publish = false
1212

13-
[features]
14-
# Run the integration tests using s2n-tls as the default TLS provider instead of the platform
15-
# default. Intended for exercising s2n-tls on Windows with the GNU/MinGW toolchain.
16-
s2n-tls-default = ["s2n-quic/provider-tls-default-s2n"]
17-
1813
[dependencies]
1914
bach = "0.1.0"
2015
bytes = { version = "1", default-features = false }
@@ -37,7 +32,9 @@ zerocopy = { version = "0.8", features = ["derive"] }
3732
quiche = "0.29"
3833

3934
# s2n-tls is required by ch_callback_server_local_address_test. It builds on unix and on Windows
40-
# with the GNU/MinGW toolchain (target_env = "gnu"), but not with MSVC.
35+
# with the GNU/MinGW toolchain (target_env = "gnu"), but not with MSVC. Enabling `provider-tls-s2n`
36+
# makes s2n-tls the default provider on these targets (it overrides `provider-tls-default`), so the
37+
# whole suite exercises s2n-tls.
4138
[target.'cfg(any(unix, all(target_os = "windows", target_env = "gnu")))'.dependencies]
4239
s2n-tls = "0.3.40"
4340
s2n-quic = { path = "../s2n-quic", features = ["provider-event-tracing", "provider-tls-s2n", "unstable-provider-io-testing", "unstable-provider-dc", "unstable-provider-packet-interceptor", "unstable-provider-random", "unstable-offload-tls", "unstable_client_hello"] }

quic/s2n-quic-tests/src/tests/buffer_limit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ fn buffer_limit_test() {
9999
// Rustls emits INTERNAL_ERROR and S2N-TLS emits UNEXPECTED_MESSAGE error
100100
// when the server close the connection due to large Client Hello.
101101
//
102-
// rustls is the default TLS provider on Windows, unless the `s2n-tls-default` feature forces
103-
// s2n-tls (e.g. when exercising s2n-tls on Windows with the GNU/MinGW toolchain).
104-
let expected_error = if cfg!(target_os = "windows") && !cfg!(feature = "s2n-tls-default") {
102+
// rustls is only the default TLS provider on Windows with the MSVC toolchain. On unix and on
103+
// Windows with the GNU/MinGW toolchain (target_env = "gnu"), s2n-tls is the default.
104+
let expected_error = if cfg!(all(target_os = "windows", target_env = "msvc")) {
105105
TlsError::INTERNAL_ERROR
106106
} else {
107107
TlsError::UNEXPECTED_MESSAGE

quic/s2n-quic-tls-default/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ exclude = ["corpus.tar.gz"]
1616
# preserves the selective compilation of the two tls crates.
1717
fips = ["s2n-quic-tls?/fips"]
1818

19-
# Force s2n-tls to be the default TLS provider even on targets where rustls is the default.
20-
# It is primarily useful for exercising s2n-tls on Windows with GNU/MinGW toolchain.
21-
s2n-tls-default = ["dep:s2n-quic-tls"]
22-
2319
# Declare `s2n-quic-tls` as an optional dependency since the `?` syntax for features requires
2420
# the dependency be optional.
2521
#
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// By default s2n-tls is the default provider on unix and rustls elsewhere (e.g. Windows).
5-
// Enabling the `s2n-tls-default` feature forces s2n-tls as the default on every target where it
6-
// builds, which is primarily used to exercise s2n-tls on Windows.
7-
#[cfg(all(not(unix), not(feature = "s2n-tls-default")))]
4+
#[cfg(not(unix))]
85
pub use s2n_quic_rustls::*;
9-
#[cfg(any(unix, feature = "s2n-tls-default"))]
6+
#[cfg(unix)]
107
pub use s2n_quic_tls::*;

quic/s2n-quic/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ provider-event-tracing = ["s2n-quic-core/event-tracing", "tracing"]
3434
provider-tls-default = ["s2n-quic-tls-default"]
3535
provider-tls-rustls = ["s2n-quic-rustls"]
3636
provider-tls-s2n = ["s2n-quic-tls"]
37-
# Force s2n-tls to be the default TLS provider even on targets where rustls is the default.
38-
# It is primarily useful for exercising s2n-tls on Windows with GNU/MinGW toolchain.
39-
provider-tls-default-s2n = ["provider-tls-default", "s2n-quic-tls-default/s2n-tls-default"]
4037

4138
# List of unstable features. Add new unstable features to the check in s2n-quic/src/lib.rs
4239
#

quic/s2n-quic/src/provider/tls.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ pub trait Provider {
2323
impl_provider_utils!();
2424

2525
cfg_if! {
26-
if #[cfg(feature = "provider-tls-default")] {
26+
// An explicit provider selection overrides the platform default. `provider-tls-s2n` and
27+
// `provider-tls-rustls` lets a consumer force a specific TLS implementation just by enabling its feature,
28+
// without having to disable default features.
29+
if #[cfg(feature = "provider-tls-s2n")] {
30+
pub use s2n_tls as default;
31+
} else if #[cfg(feature = "provider-tls-rustls")] {
32+
pub use rustls as default;
33+
} else if #[cfg(feature = "provider-tls-default")] {
2734
#[cfg_attr(docsrs, doc(cfg(feature = "provider-tls-default")))]
2835
pub mod default {
2936
//! Provides the recommended implementation of TLS using platform detection
3037
pub use super::default_tls::*;
3138
}
32-
} else if #[cfg(feature = "provider-tls-s2n")] {
33-
pub use s2n_tls as default;
34-
} else if #[cfg(feature = "provider-tls-rustls")] {
35-
pub use rustls as default;
3639
} else {
3740
pub mod default {
3841
//! Provides the recommended implementation of TLS using platform detection
@@ -190,7 +193,15 @@ impl Provider for &str {
190193
}
191194
}
192195

193-
#[cfg(feature = "provider-tls-default")]
196+
// `default_tls` only backs the `default` module when `provider-tls-default` is the effective
197+
// choice, i.e. when neither `provider-tls-s2n` nor `provider-tls-rustls` overrides it (see the
198+
// cfg_if above). When an override is active, the re-export below would be unused, so we compile
199+
// the stub instead to avoid dead code.
200+
#[cfg(all(
201+
feature = "provider-tls-default",
202+
not(feature = "provider-tls-s2n"),
203+
not(feature = "provider-tls-rustls")
204+
))]
194205
mod default_tls {
195206
pub use s2n_quic_tls_default::*;
196207

@@ -199,19 +210,9 @@ mod default_tls {
199210
//
200211
// Note: I know this looks like a mess. And it is. Hopefully in the future cargo will support
201212
// platform-specific default features.
202-
//
203-
// The default provider is s2n-tls on unix and whenever `provider-tls-default-s2n` forces it;
204-
// otherwise it is rustls. We only add the impl below when the default type doesn't already
205-
// have one from the explicit `rustls`/`s2n_tls` provider modules, to avoid conflicting impls.
206213
#[cfg(not(any(
207-
all(
208-
not(any(unix, feature = "provider-tls-default-s2n")),
209-
feature = "s2n-quic-rustls"
210-
),
211-
all(
212-
any(unix, feature = "provider-tls-default-s2n"),
213-
feature = "s2n-quic-tls"
214-
)
214+
all(not(unix), feature = "s2n-quic-rustls"),
215+
all(unix, feature = "s2n-quic-tls")
215216
)))]
216217
mod default_provider {
217218
use super::*;
@@ -246,7 +247,11 @@ mod default_tls {
246247
}
247248
}
248249
}
249-
#[cfg(not(feature = "provider-tls-default"))]
250+
#[cfg(not(all(
251+
feature = "provider-tls-default",
252+
not(feature = "provider-tls-s2n"),
253+
not(feature = "provider-tls-rustls")
254+
)))]
250255
mod default_tls {
251256
// TODO stub out default that fails with error when started
252257
}

0 commit comments

Comments
 (0)