Skip to content

refactor: use cfg-aliases for feature flags #3865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,6 @@ required-features = ["full"]
name = "server"
path = "tests/server.rs"
required-features = ["full"]

[build-dependencies]
cfg_aliases = "0.2.1"
25 changes: 25 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cfg_aliases::cfg_aliases;

fn main() {
cfg_aliases! {
http1: { feature = "http1" },
http2: { feature = "http2" },

client : { feature = "client" },
server : { feature = "server" },

ffi: { feature = "ffi" },
full: { feature = "full" },
nightly: { feature = "nightly" },
runtime: { feature = "runtime" },
tracing: { feature = "tracing" },

http_client: { all(any(http1, http2), client) },
http1_client: { all(http1, client) },
http2_client: { all(http2, client) },

http_server: { all(any(http1, http2), server) },
http1_server: { all(http1, server) },
http2_server: { all(http2, server) },
}
}
8 changes: 4 additions & 4 deletions examples/hello-http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use http_body_util::Full;
use hyper::body::Bytes;
#[cfg(feature = "server")]
#[cfg(server)]
use hyper::server::conn::http2;
use hyper::service::service_fn;
use hyper::{Request, Response};
Expand All @@ -19,7 +19,7 @@ use support::TokioIo;

// An async function that consumes a request, does nothing with it and returns a
// response.
#[cfg(feature = "server")]
#[cfg(server)]
async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
Ok(Response::new(Full::new(Bytes::from("Hello, World!"))))
}
Expand All @@ -42,7 +42,7 @@ where
}
}

#[cfg(feature = "server")]
#[cfg(server)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
pretty_env_logger::init();
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
}
}

#[cfg(not(feature = "server"))]
#[cfg(not(server))]
fn main() {
panic!("This example requires the 'server' feature to be enabled");
}
Loading
Loading