Skip to content

Commit

Permalink
feat(lib): disable all optional features by default (#2336)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: All optional features have been disabled by default.
  • Loading branch information
seanmonstar authored Nov 19, 2020
1 parent abb6471 commit ed2b22a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:

include:
- rust: stable
features: ""
features: "--features full"
- rust: beta
features: ""
features: "--features full"
- rust: nightly
features: "--features nightly"
features: "--features full,nightly"
benches: true

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -132,4 +132,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: rustdoc
args: -- -D broken-intra-doc-links
args: --features full -- -D broken-intra-doc-links
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

# Run benchmark and stores the output to a file
- 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)
- name: Download previous benchmark data
Expand Down
83 changes: 41 additions & 42 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ url = "1.0"
pnet = "0.25.0"

[features]
default = [
"runtime",
"stream",
"client",
"server",
"http1",
"http2",
]
# Nothing by default
default = []

# Easily turn it all on
full = [
"client",
"http1",
Expand All @@ -87,16 +83,6 @@ full = [
"stream",
"runtime",
]
runtime = [
"tcp",
"tokio/rt",
]
tcp = [
"socket2",
"tokio/net",
"tokio/rt",
"tokio/time",
]

# HTTP versions
http1 = []
Expand All @@ -109,6 +95,19 @@ server = []
# `impl Stream` for things
stream = []

# Tokio support

runtime = [
"tcp",
"tokio/rt",
]
tcp = [
"socket2",
"tokio/net",
"tokio/rt",
"tokio/time",
]

# internal features used in CI
nightly = []
__internal_happy_eyeballs_tests = []
Expand All @@ -131,122 +130,122 @@ incremental = false
[[example]]
name = "client"
path = "examples/client.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "client_json"
path = "examples/client_json.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "echo"
path = "examples/echo.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]

[[example]]
name = "gateway"
path = "examples/gateway.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "hello"
path = "examples/hello.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "http_proxy"
path = "examples/http_proxy.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "multi_server"
path = "examples/multi_server.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "params"
path = "examples/params.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]

[[example]]
name = "send_file"
path = "examples/send_file.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "service_struct_impl"
path = "examples/service_struct_impl.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "single_threaded"
path = "examples/single_threaded.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "state"
path = "examples/state.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "tower_client"
path = "examples/tower_client.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "tower_server"
path = "examples/tower_server.rs"
required-features = ["runtime"]
required-features = ["full"]

[[example]]
name = "upgrades"
path = "examples/upgrades.rs"
required-features = ["runtime"]
required-features = ["full"]


[[example]]
name = "web_api"
path = "examples/web_api.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]


[[bench]]
name = "body"
path = "benches/body.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]

[[bench]]
name = "connect"
path = "benches/connect.rs"
required-features = ["runtime"]
required-features = ["full"]

[[bench]]
name = "end_to_end"
path = "benches/end_to_end.rs"
required-features = ["runtime"]
required-features = ["full"]

[[bench]]
name = "pipeline"
path = "benches/pipeline.rs"
required-features = ["runtime"]
required-features = ["full"]

[[bench]]
name = "server"
path = "benches/server.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]


[[test]]
name = "client"
path = "tests/client.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]

[[test]]
name = "integration"
path = "tests/integration.rs"
required-features = ["runtime", "stream"]
required-features = ["full"]

[[test]]
name = "server"
path = "tests/server.rs"
required-features = ["runtime"]
required-features = ["full"]
3 changes: 1 addition & 2 deletions src/common/io/rewind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub(crate) struct Rewind<T> {
}

impl<T> Rewind<T> {
#[cfg(any(feature = "http2", test))]
#[cfg(feature = "server")]
#[cfg(any(all(feature = "http2", feature = "server"), test))]
pub(crate) fn new(io: T) -> Self {
Rewind {
pre: None,
Expand Down
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,29 @@
//!
//! # 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:
//!
//! - `runtime` (*enabled by default*): Enables convenient integration with
//! `tokio`, providing connectors and acceptors for TCP, and a default
//! executor.
//! - `tcp` (*enabled by default*): Enables convenient implementations over
//! TCP (using tokio).
//! - `stream` (*enabled by default*): Provides `futures::Stream` capabilities.
//! - `http1`: Enables HTTP/1 support.
//! - `http2`: Enables HTTP/2 support.
//! - `client`: Enables the HTTP `client`.
//! - `server`: Enables the HTTP `server`.
//! - `runtime`: Enables convenient integration with `tokio`, providing
//! 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)]
pub use http;
Expand Down

0 comments on commit ed2b22a

Please sign in to comment.