Skip to content

Commit ea32edf

Browse files
committed
use cfg alias
1 parent 4a6e65c commit ea32edf

6 files changed

Lines changed: 44 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ json = ["dep:serde", "dep:serde_json"]
2020
p2 = ["dep:wasip2"]
2121
p3 = ["dep:wasip3"]
2222

23+
[build-dependencies]
24+
cfg_aliases.workspace = true
25+
2326
[dependencies]
2427
anyhow.workspace = true
2528
async-task.workspace = true
@@ -134,6 +137,7 @@ async-task = "4.7"
134137
axum = { version = "0.8.6", default-features = false }
135138
bytes = "1.10.1"
136139
cargo_metadata = "0.22"
140+
cfg_aliases = "0.2"
137141
clap = { version = "4.5.26", features = ["derive"] }
138142
futures-core = "0.3.19"
139143
futures-lite = "1.12.0"

axum/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ default = ["p2"]
2121
p2 = ["wstd/p2"]
2222
p3 = ["wstd/p3"]
2323

24+
[build-dependencies]
25+
cfg_aliases.workspace = true
26+
2427
[dev-dependencies]
2528
anyhow.workspace = true
2629
futures-concurrency.workspace = true

axum/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use cfg_aliases::cfg_aliases;
2+
3+
fn main() {
4+
cfg_aliases! {
5+
// TODO https://github.com/bytecodealliance/wstd/issues/147: Swap these
6+
// to use `target_env` instead.
7+
p2: { feature = "p2" },
8+
p3: { feature = "p3" },
9+
}
10+
}

axum/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "p2")]
1+
#![cfg(p2)]
22
//! Support for the [`axum`] web server framework in wasi-http components, via
33
//! [`wstd`].
44
//!

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use cfg_aliases::cfg_aliases;
2+
3+
fn main() {
4+
cfg_aliases! {
5+
// TODO https://github.com/bytecodealliance/wstd/issues/147: Swap these
6+
// to use `target_env` instead.
7+
p2: { feature = "p2" },
8+
p3: { feature = "p3" },
9+
}
10+
}

src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! **TCP echo server**
1919
//!
2020
//! ```rust,no_run
21-
#![cfg_attr(feature = "p2", doc = include_str!("../examples/tcp_echo_server.rs"))]
21+
#![cfg_attr(p2, doc = include_str!("../examples/tcp_echo_server.rs"))]
2222
//! ```
2323
//!
2424
//! **HTTP Client**
@@ -30,7 +30,7 @@
3030
//! **HTTP Server**
3131
//!
3232
//! ```rust,no_run
33-
#![cfg_attr(feature = "p2", doc = include_str!("../examples/http_server.rs"))]
33+
#![cfg_attr(p2, doc = include_str!("../examples/http_server.rs"))]
3434
//! ```
3535
//!
3636
//! # Design Decisions
@@ -56,33 +56,33 @@
5656
//! is specific to that are exposed from here.
5757
5858
// Exactly one WASI backend must be selected. See the `p2`/`p3` features.
59-
#[cfg(all(feature = "p2", feature = "p3"))]
59+
#[cfg(all(p2, p3))]
6060
compile_error!(
6161
"the `p2` and `p3` features are mutually exclusive — enable exactly one WASI backend"
6262
);
63-
#[cfg(not(any(feature = "p2", feature = "p3")))]
63+
#[cfg(not(any(p2, p3)))]
6464
compile_error!("exactly one of the `p2` or `p3` features must be enabled");
6565

66-
#[cfg(feature = "p2")]
66+
#[cfg(p2)]
6767
pub mod future;
68-
#[cfg(feature = "p2")]
68+
#[cfg(p2)]
6969
#[macro_use]
7070
pub mod http;
71-
#[cfg(feature = "p2")]
71+
#[cfg(p2)]
7272
pub mod io;
7373
pub mod iter;
74-
#[cfg(feature = "p2")]
74+
#[cfg(p2)]
7575
pub mod net;
76-
#[cfg(feature = "p2")]
76+
#[cfg(p2)]
7777
pub mod rand;
78-
#[cfg(feature = "p2")]
78+
#[cfg(p2)]
7979
pub mod runtime;
80-
#[cfg(feature = "p2")]
80+
#[cfg(p2)]
8181
pub mod task;
82-
#[cfg(feature = "p2")]
82+
#[cfg(p2)]
8383
pub mod time;
8484

85-
#[cfg(feature = "p2")]
85+
#[cfg(p2)]
8686
pub use wstd_macro::{
8787
attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test,
8888
};
@@ -94,13 +94,13 @@ pub use wstd_macro::{
9494
// private.
9595
#[doc(hidden)]
9696
pub mod __internal {
97-
#[cfg(feature = "p2")]
97+
#[cfg(p2)]
9898
pub use wasip2;
99-
#[cfg(feature = "p3")]
99+
#[cfg(p3)]
100100
pub use wasip3;
101101
}
102102

103-
#[cfg(feature = "p2")]
103+
#[cfg(p2)]
104104
pub mod prelude {
105105
pub use crate::future::FutureExt as _;
106106
pub use crate::io::AsyncRead as _;

0 commit comments

Comments
 (0)