Skip to content

Commit

Permalink
minimize use of features based on PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Jan 7, 2025
1 parent 700700b commit 3b57217
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ go = ['dep:wit-bindgen-go']
csharp = ['dep:wit-bindgen-csharp']
csharp-mono = ['csharp']
moonbit = ['dep:wit-bindgen-moonbit']
async = ["wit-bindgen-rust/async"]
async = []

[dev-dependencies]
heck = { workspace = true }
Expand Down
4 changes: 0 additions & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ doctest = false
wit-parser = { workspace = true }
anyhow = { workspace = true }
heck = { workspace = true }

[features]
default = ["async"]
async = []
4 changes: 0 additions & 4 deletions crates/core/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,6 @@ pub fn call(
bindgen: &mut impl Bindgen,
async_: bool,
) {
if async_ && !cfg!(feature = "async") {
panic!("must enable `async` feature to lift or lower using the async ABI");
}

Generator::new(resolve, variant, lift_lower, bindgen, async_).call(func);
}

Expand Down
16 changes: 0 additions & 16 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ pub enum Direction {

pub trait WorldGenerator {
fn generate(&mut self, resolve: &Resolve, id: WorldId, files: &mut Files) -> Result<()> {
// TODO: Should we refine this test to inspect only types reachable from
// the specified world?
if !cfg!(feature = "async")
&& resolve.types.iter().any(|(_, ty)| {
matches!(
ty.kind,
TypeDefKind::Future(_) | TypeDefKind::Stream(_) | TypeDefKind::ErrorContext
)
})
{
anyhow::bail!(
"must enable `async` feature when using WIT files \
containing future, stream, or error types"
);
}

let world = &resolve.worlds[id];
self.preprocess(resolve, id);

Expand Down
2 changes: 1 addition & 1 deletion crates/guest-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ wit-bindgen-rt = { path = "./rt", version = "0.36.0", features = ["bitflags"] }
default = ["macros", "realloc", "async"]
macros = ["dep:wit-bindgen-rust-macro"]
realloc = []
async = ["macros", "wit-bindgen-rt/async", "wit-bindgen-rust-macro/async"]
async = ["macros", "wit-bindgen-rt/async"]
3 changes: 1 addition & 2 deletions crates/guest-rust/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ syn = { workspace = true }
prettyplease = { workspace = true }

[features]
default = ["async"]
async = ["wit-bindgen-rust/async"]
async = []
6 changes: 0 additions & 6 deletions crates/guest-rust/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ impl Parse for Config {
return Err(Error::new(span, "cannot specify second async config"));
}
async_configured = true;
if !matches!(val, AsyncConfig::None) && !cfg!(feature = "async") {
return Err(Error::new(
span,
"must enable `async` feature to enable async imports and/or exports",
));
}
opts.async_ = val;
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/guest-rust/rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ futures = { version = "0.3.30", optional = true }
once_cell = { version = "1.19.0", optional = true }

[features]
default = ["async"]
async = ["dep:futures", "dep:once_cell"]
4 changes: 4 additions & 0 deletions crates/guest-rust/rt/src/async_support.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![deny(missing_docs)]
#![allow(static_mut_refs)]

extern crate std;

use {
futures::{
channel::oneshot,
Expand All @@ -11,6 +13,7 @@ use {
std::{
alloc::{self, Layout},
any::Any,
boxed::Box,
collections::hash_map,
collections::HashMap,
fmt::{self, Debug, Display},
Expand All @@ -19,6 +22,7 @@ use {
ptr,
sync::Arc,
task::{Context, Poll, Wake, Waker},
vec::Vec,
},
};

Expand Down
6 changes: 1 addition & 5 deletions crates/guest-rust/rt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(feature = "async"), no_std)]
#![no_std]

extern crate alloc;

Expand Down Expand Up @@ -113,10 +113,6 @@ pub fn run_ctors_once() {
}
}

/// Support for using the Component Model Async ABI
#[cfg(not(feature = "async"))]
pub mod async_support {}

/// Support for using the Component Model Async ABI
#[cfg(feature = "async")]
pub mod async_support;
4 changes: 0 additions & 4 deletions crates/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ test-helpers = { path = '../test-helpers' }
# For use with the custom attributes test
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"

[features]
default = ["async"]
async = ["wit-bindgen-core/async"]
3 changes: 1 addition & 2 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ pub struct Opts {
/// - some=<value>[,<value>...], where each <value> is of the form:
/// - import:<name> or
/// - export:<name>
#[cfg_attr(all(feature = "clap", feature = "async"), arg(long = "async", value_parser = parse_async))]
#[cfg_attr(all(feature = "clap", not(feature = "async")), skip)]
#[cfg_attr(feature = "clap", arg(long = "async", value_parser = parse_async))]
pub async_: AsyncConfig,
}

Expand Down
1 change: 0 additions & 1 deletion crates/rust/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ mod codegen_tests {
fn works() {}
}

#[cfg(feature = "async")]
mod async_ {
wit_bindgen::generate!({
path: $test,
Expand Down

0 comments on commit 3b57217

Please sign in to comment.