feat(lib): disable all optional features by default (#2336)

BREAKING CHANGE: All optional features have been disabled by default.
This commit is contained in:
Sean McArthur
2020-11-19 10:05:39 -08:00
committed by GitHub
parent abb6471690
commit ed2b22a7f6
5 changed files with 68 additions and 55 deletions

View File

@@ -59,11 +59,11 @@ jobs:
include: include:
- rust: stable - rust: stable
features: "" features: "--features full"
- rust: beta - rust: beta
features: "" features: "--features full"
- rust: nightly - rust: nightly
features: "--features nightly" features: "--features full,nightly"
benches: true benches: true
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@@ -132,4 +132,4 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: rustdoc command: rustdoc
args: -- -D broken-intra-doc-links args: --features full -- -D broken-intra-doc-links

View File

@@ -26,7 +26,7 @@ jobs:
# Run benchmark and stores the output to a file # Run benchmark and stores the output to a file
- name: Run benchmark - name: Run benchmark
run: cargo bench --bench ${{ matrix.bench }} | tee output.txt run: cargo bench --features full --bench ${{ matrix.bench }} | tee output.txt
# Download previous benchmark result from cache (if exists) # Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data - name: Download previous benchmark data

View File

@@ -71,14 +71,10 @@ url = "1.0"
pnet = "0.25.0" pnet = "0.25.0"
[features] [features]
default = [ # Nothing by default
"runtime", default = []
"stream",
"client", # Easily turn it all on
"server",
"http1",
"http2",
]
full = [ full = [
"client", "client",
"http1", "http1",
@@ -87,16 +83,6 @@ full = [
"stream", "stream",
"runtime", "runtime",
] ]
runtime = [
"tcp",
"tokio/rt",
]
tcp = [
"socket2",
"tokio/net",
"tokio/rt",
"tokio/time",
]
# HTTP versions # HTTP versions
http1 = [] http1 = []
@@ -109,6 +95,19 @@ server = []
# `impl Stream` for things # `impl Stream` for things
stream = [] stream = []
# Tokio support
runtime = [
"tcp",
"tokio/rt",
]
tcp = [
"socket2",
"tokio/net",
"tokio/rt",
"tokio/time",
]
# internal features used in CI # internal features used in CI
nightly = [] nightly = []
__internal_happy_eyeballs_tests = [] __internal_happy_eyeballs_tests = []
@@ -131,122 +130,122 @@ incremental = false
[[example]] [[example]]
name = "client" name = "client"
path = "examples/client.rs" path = "examples/client.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "client_json" name = "client_json"
path = "examples/client_json.rs" path = "examples/client_json.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "echo" name = "echo"
path = "examples/echo.rs" path = "examples/echo.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[example]] [[example]]
name = "gateway" name = "gateway"
path = "examples/gateway.rs" path = "examples/gateway.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "hello" name = "hello"
path = "examples/hello.rs" path = "examples/hello.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "http_proxy" name = "http_proxy"
path = "examples/http_proxy.rs" path = "examples/http_proxy.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "multi_server" name = "multi_server"
path = "examples/multi_server.rs" path = "examples/multi_server.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "params" name = "params"
path = "examples/params.rs" path = "examples/params.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[example]] [[example]]
name = "send_file" name = "send_file"
path = "examples/send_file.rs" path = "examples/send_file.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "service_struct_impl" name = "service_struct_impl"
path = "examples/service_struct_impl.rs" path = "examples/service_struct_impl.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "single_threaded" name = "single_threaded"
path = "examples/single_threaded.rs" path = "examples/single_threaded.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "state" name = "state"
path = "examples/state.rs" path = "examples/state.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "tower_client" name = "tower_client"
path = "examples/tower_client.rs" path = "examples/tower_client.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "tower_server" name = "tower_server"
path = "examples/tower_server.rs" path = "examples/tower_server.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "upgrades" name = "upgrades"
path = "examples/upgrades.rs" path = "examples/upgrades.rs"
required-features = ["runtime"] required-features = ["full"]
[[example]] [[example]]
name = "web_api" name = "web_api"
path = "examples/web_api.rs" path = "examples/web_api.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[bench]] [[bench]]
name = "body" name = "body"
path = "benches/body.rs" path = "benches/body.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[bench]] [[bench]]
name = "connect" name = "connect"
path = "benches/connect.rs" path = "benches/connect.rs"
required-features = ["runtime"] required-features = ["full"]
[[bench]] [[bench]]
name = "end_to_end" name = "end_to_end"
path = "benches/end_to_end.rs" path = "benches/end_to_end.rs"
required-features = ["runtime"] required-features = ["full"]
[[bench]] [[bench]]
name = "pipeline" name = "pipeline"
path = "benches/pipeline.rs" path = "benches/pipeline.rs"
required-features = ["runtime"] required-features = ["full"]
[[bench]] [[bench]]
name = "server" name = "server"
path = "benches/server.rs" path = "benches/server.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[test]] [[test]]
name = "client" name = "client"
path = "tests/client.rs" path = "tests/client.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[test]] [[test]]
name = "integration" name = "integration"
path = "tests/integration.rs" path = "tests/integration.rs"
required-features = ["runtime", "stream"] required-features = ["full"]
[[test]] [[test]]
name = "server" name = "server"
path = "tests/server.rs" path = "tests/server.rs"
required-features = ["runtime"] required-features = ["full"]

View File

@@ -14,8 +14,7 @@ pub(crate) struct Rewind<T> {
} }
impl<T> Rewind<T> { impl<T> Rewind<T> {
#[cfg(any(feature = "http2", test))] #[cfg(any(all(feature = "http2", feature = "server"), test))]
#[cfg(feature = "server")]
pub(crate) fn new(io: T) -> Self { pub(crate) fn new(io: T) -> Self {
Rewind { Rewind {
pre: None, pre: None,

View File

@@ -31,14 +31,29 @@
//! //!
//! # Optional Features //! # Optional Features
//! //!
//! hyper uses a set of [feature flags] to reduce the amount of compiled code.
//! It is possible to just enable certain features over others. By default,
//! hyper does not enable any features but allows one to enable a subset for
//! their use case. Below is a list of the available feature flags. You may
//! also notice above each function, struct and trait there is listed one or
//! more feature flags that are required for that item to be used.
//!
//! If you are new to hyper it is possible to enable the `full` feature flag
//! which will enable all public APIs. Beware though that this will pull in
//! many extra dependencies that you may not need.
//!
//! The following optional features are available: //! The following optional features are available:
//! //!
//! - `runtime` (*enabled by default*): Enables convenient integration with //! - `http1`: Enables HTTP/1 support.
//! `tokio`, providing connectors and acceptors for TCP, and a default //! - `http2`: Enables HTTP/2 support.
//! executor. //! - `client`: Enables the HTTP `client`.
//! - `tcp` (*enabled by default*): Enables convenient implementations over //! - `server`: Enables the HTTP `server`.
//! TCP (using tokio). //! - `runtime`: Enables convenient integration with `tokio`, providing
//! - `stream` (*enabled by default*): Provides `futures::Stream` capabilities. //! connectors and acceptors for TCP, and a default executor.
//! - `tcp`: Enables convenient implementations over TCP (using tokio).
//! - `stream`: Provides `futures::Stream` capabilities.
//!
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
#[doc(hidden)] #[doc(hidden)]
pub use http; pub use http;