Skip to content

Commit ed2b22a

Browse files
authored
feat(lib): disable all optional features by default (#2336)
BREAKING CHANGE: All optional features have been disabled by default.
1 parent abb6471 commit ed2b22a

File tree

5 files changed

+68
-55
lines changed

5 files changed

+68
-55
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ jobs:
5959

6060
include:
6161
- rust: stable
62-
features: ""
62+
features: "--features full"
6363
- rust: beta
64-
features: ""
64+
features: "--features full"
6565
- rust: nightly
66-
features: "--features nightly"
66+
features: "--features full,nightly"
6767
benches: true
6868

6969
runs-on: ${{ matrix.os }}
@@ -132,4 +132,4 @@ jobs:
132132
uses: actions-rs/cargo@v1
133133
with:
134134
command: rustdoc
135-
args: -- -D broken-intra-doc-links
135+
args: --features full -- -D broken-intra-doc-links

.github/workflows/bench.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
# Run benchmark and stores the output to a file
2828
- name: Run benchmark
29-
run: cargo bench --bench ${{ matrix.bench }} | tee output.txt
29+
run: cargo bench --features full --bench ${{ matrix.bench }} | tee output.txt
3030

3131
# Download previous benchmark result from cache (if exists)
3232
- name: Download previous benchmark data

Cargo.toml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ url = "1.0"
7171
pnet = "0.25.0"
7272

7373
[features]
74-
default = [
75-
"runtime",
76-
"stream",
77-
"client",
78-
"server",
79-
"http1",
80-
"http2",
81-
]
74+
# Nothing by default
75+
default = []
76+
77+
# Easily turn it all on
8278
full = [
8379
"client",
8480
"http1",
@@ -87,16 +83,6 @@ full = [
8783
"stream",
8884
"runtime",
8985
]
90-
runtime = [
91-
"tcp",
92-
"tokio/rt",
93-
]
94-
tcp = [
95-
"socket2",
96-
"tokio/net",
97-
"tokio/rt",
98-
"tokio/time",
99-
]
10086

10187
# HTTP versions
10288
http1 = []
@@ -109,6 +95,19 @@ server = []
10995
# `impl Stream` for things
11096
stream = []
11197

98+
# Tokio support
99+
100+
runtime = [
101+
"tcp",
102+
"tokio/rt",
103+
]
104+
tcp = [
105+
"socket2",
106+
"tokio/net",
107+
"tokio/rt",
108+
"tokio/time",
109+
]
110+
112111
# internal features used in CI
113112
nightly = []
114113
__internal_happy_eyeballs_tests = []
@@ -131,122 +130,122 @@ incremental = false
131130
[[example]]
132131
name = "client"
133132
path = "examples/client.rs"
134-
required-features = ["runtime"]
133+
required-features = ["full"]
135134

136135
[[example]]
137136
name = "client_json"
138137
path = "examples/client_json.rs"
139-
required-features = ["runtime"]
138+
required-features = ["full"]
140139

141140
[[example]]
142141
name = "echo"
143142
path = "examples/echo.rs"
144-
required-features = ["runtime", "stream"]
143+
required-features = ["full"]
145144

146145
[[example]]
147146
name = "gateway"
148147
path = "examples/gateway.rs"
149-
required-features = ["runtime"]
148+
required-features = ["full"]
150149

151150
[[example]]
152151
name = "hello"
153152
path = "examples/hello.rs"
154-
required-features = ["runtime"]
153+
required-features = ["full"]
155154

156155
[[example]]
157156
name = "http_proxy"
158157
path = "examples/http_proxy.rs"
159-
required-features = ["runtime"]
158+
required-features = ["full"]
160159

161160
[[example]]
162161
name = "multi_server"
163162
path = "examples/multi_server.rs"
164-
required-features = ["runtime"]
163+
required-features = ["full"]
165164

166165
[[example]]
167166
name = "params"
168167
path = "examples/params.rs"
169-
required-features = ["runtime", "stream"]
168+
required-features = ["full"]
170169

171170
[[example]]
172171
name = "send_file"
173172
path = "examples/send_file.rs"
174-
required-features = ["runtime"]
173+
required-features = ["full"]
175174

176175
[[example]]
177176
name = "service_struct_impl"
178177
path = "examples/service_struct_impl.rs"
179-
required-features = ["runtime"]
178+
required-features = ["full"]
180179

181180
[[example]]
182181
name = "single_threaded"
183182
path = "examples/single_threaded.rs"
184-
required-features = ["runtime"]
183+
required-features = ["full"]
185184

186185
[[example]]
187186
name = "state"
188187
path = "examples/state.rs"
189-
required-features = ["runtime"]
188+
required-features = ["full"]
190189

191190
[[example]]
192191
name = "tower_client"
193192
path = "examples/tower_client.rs"
194-
required-features = ["runtime"]
193+
required-features = ["full"]
195194

196195
[[example]]
197196
name = "tower_server"
198197
path = "examples/tower_server.rs"
199-
required-features = ["runtime"]
198+
required-features = ["full"]
200199

201200
[[example]]
202201
name = "upgrades"
203202
path = "examples/upgrades.rs"
204-
required-features = ["runtime"]
203+
required-features = ["full"]
205204

206205

207206
[[example]]
208207
name = "web_api"
209208
path = "examples/web_api.rs"
210-
required-features = ["runtime", "stream"]
209+
required-features = ["full"]
211210

212211

213212
[[bench]]
214213
name = "body"
215214
path = "benches/body.rs"
216-
required-features = ["runtime", "stream"]
215+
required-features = ["full"]
217216

218217
[[bench]]
219218
name = "connect"
220219
path = "benches/connect.rs"
221-
required-features = ["runtime"]
220+
required-features = ["full"]
222221

223222
[[bench]]
224223
name = "end_to_end"
225224
path = "benches/end_to_end.rs"
226-
required-features = ["runtime"]
225+
required-features = ["full"]
227226

228227
[[bench]]
229228
name = "pipeline"
230229
path = "benches/pipeline.rs"
231-
required-features = ["runtime"]
230+
required-features = ["full"]
232231

233232
[[bench]]
234233
name = "server"
235234
path = "benches/server.rs"
236-
required-features = ["runtime", "stream"]
235+
required-features = ["full"]
237236

238237

239238
[[test]]
240239
name = "client"
241240
path = "tests/client.rs"
242-
required-features = ["runtime", "stream"]
241+
required-features = ["full"]
243242

244243
[[test]]
245244
name = "integration"
246245
path = "tests/integration.rs"
247-
required-features = ["runtime", "stream"]
246+
required-features = ["full"]
248247

249248
[[test]]
250249
name = "server"
251250
path = "tests/server.rs"
252-
required-features = ["runtime"]
251+
required-features = ["full"]

src/common/io/rewind.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub(crate) struct Rewind<T> {
1414
}
1515

1616
impl<T> Rewind<T> {
17-
#[cfg(any(feature = "http2", test))]
18-
#[cfg(feature = "server")]
17+
#[cfg(any(all(feature = "http2", feature = "server"), test))]
1918
pub(crate) fn new(io: T) -> Self {
2019
Rewind {
2120
pre: None,

src/lib.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,29 @@
3131
//!
3232
//! # Optional Features
3333
//!
34+
//! hyper uses a set of [feature flags] to reduce the amount of compiled code.
35+
//! It is possible to just enable certain features over others. By default,
36+
//! hyper does not enable any features but allows one to enable a subset for
37+
//! their use case. Below is a list of the available feature flags. You may
38+
//! also notice above each function, struct and trait there is listed one or
39+
//! more feature flags that are required for that item to be used.
40+
//!
41+
//! If you are new to hyper it is possible to enable the `full` feature flag
42+
//! which will enable all public APIs. Beware though that this will pull in
43+
//! many extra dependencies that you may not need.
44+
//!
3445
//! The following optional features are available:
3546
//!
36-
//! - `runtime` (*enabled by default*): Enables convenient integration with
37-
//! `tokio`, providing connectors and acceptors for TCP, and a default
38-
//! executor.
39-
//! - `tcp` (*enabled by default*): Enables convenient implementations over
40-
//! TCP (using tokio).
41-
//! - `stream` (*enabled by default*): Provides `futures::Stream` capabilities.
47+
//! - `http1`: Enables HTTP/1 support.
48+
//! - `http2`: Enables HTTP/2 support.
49+
//! - `client`: Enables the HTTP `client`.
50+
//! - `server`: Enables the HTTP `server`.
51+
//! - `runtime`: Enables convenient integration with `tokio`, providing
52+
//! connectors and acceptors for TCP, and a default executor.
53+
//! - `tcp`: Enables convenient implementations over TCP (using tokio).
54+
//! - `stream`: Provides `futures::Stream` capabilities.
55+
//!
56+
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
4257
4358
#[doc(hidden)]
4459
pub use http;

0 commit comments

Comments
 (0)