From 3b57217a45ddb09ebe023f5174eea7122c6dfa30 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 7 Jan 2025 09:14:39 -0700 Subject: [PATCH] minimize use of features based on PR feedback Signed-off-by: Joel Dice --- Cargo.toml | 2 +- crates/core/Cargo.toml | 4 ---- crates/core/src/abi.rs | 4 ---- crates/core/src/lib.rs | 16 ---------------- crates/guest-rust/Cargo.toml | 2 +- crates/guest-rust/macro/Cargo.toml | 3 +-- crates/guest-rust/macro/src/lib.rs | 6 ------ crates/guest-rust/rt/Cargo.toml | 1 - crates/guest-rust/rt/src/async_support.rs | 4 ++++ crates/guest-rust/rt/src/lib.rs | 6 +----- crates/rust/Cargo.toml | 4 ---- crates/rust/src/lib.rs | 3 +-- crates/rust/tests/codegen.rs | 1 - 13 files changed, 9 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 148e0c1f1..435c11242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index bc476ea80..60935ef8d 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -18,7 +18,3 @@ doctest = false wit-parser = { workspace = true } anyhow = { workspace = true } heck = { workspace = true } - -[features] -default = ["async"] -async = [] diff --git a/crates/core/src/abi.rs b/crates/core/src/abi.rs index 027e4a0d0..e331188fd 100644 --- a/crates/core/src/abi.rs +++ b/crates/core/src/abi.rs @@ -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); } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index ccebe94d1..b193df61a 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -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); diff --git a/crates/guest-rust/Cargo.toml b/crates/guest-rust/Cargo.toml index 3fb139adf..4eb6ee28b 100644 --- a/crates/guest-rust/Cargo.toml +++ b/crates/guest-rust/Cargo.toml @@ -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"] diff --git a/crates/guest-rust/macro/Cargo.toml b/crates/guest-rust/macro/Cargo.toml index f30dd8780..5fb9c1ea6 100644 --- a/crates/guest-rust/macro/Cargo.toml +++ b/crates/guest-rust/macro/Cargo.toml @@ -25,5 +25,4 @@ syn = { workspace = true } prettyplease = { workspace = true } [features] -default = ["async"] -async = ["wit-bindgen-rust/async"] +async = [] diff --git a/crates/guest-rust/macro/src/lib.rs b/crates/guest-rust/macro/src/lib.rs index 24a04f291..69f71fd06 100644 --- a/crates/guest-rust/macro/src/lib.rs +++ b/crates/guest-rust/macro/src/lib.rs @@ -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; } } diff --git a/crates/guest-rust/rt/Cargo.toml b/crates/guest-rust/rt/Cargo.toml index e84f04d18..d0a43412e 100644 --- a/crates/guest-rust/rt/Cargo.toml +++ b/crates/guest-rust/rt/Cargo.toml @@ -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"] diff --git a/crates/guest-rust/rt/src/async_support.rs b/crates/guest-rust/rt/src/async_support.rs index a2a1a285e..338c77e43 100644 --- a/crates/guest-rust/rt/src/async_support.rs +++ b/crates/guest-rust/rt/src/async_support.rs @@ -1,6 +1,8 @@ #![deny(missing_docs)] #![allow(static_mut_refs)] +extern crate std; + use { futures::{ channel::oneshot, @@ -11,6 +13,7 @@ use { std::{ alloc::{self, Layout}, any::Any, + boxed::Box, collections::hash_map, collections::HashMap, fmt::{self, Debug, Display}, @@ -19,6 +22,7 @@ use { ptr, sync::Arc, task::{Context, Poll, Wake, Waker}, + vec::Vec, }, }; diff --git a/crates/guest-rust/rt/src/lib.rs b/crates/guest-rust/rt/src/lib.rs index c9a63cf71..0f2858362 100644 --- a/crates/guest-rust/rt/src/lib.rs +++ b/crates/guest-rust/rt/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(feature = "async"), no_std)] +#![no_std] extern crate alloc; @@ -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; diff --git a/crates/rust/Cargo.toml b/crates/rust/Cargo.toml index ddaa117e2..d2e0b69be 100644 --- a/crates/rust/Cargo.toml +++ b/crates/rust/Cargo.toml @@ -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"] diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 22efce8f8..754955c47 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -295,8 +295,7 @@ pub struct Opts { /// - some=[,...], where each is of the form: /// - import: or /// - export: - #[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, } diff --git a/crates/rust/tests/codegen.rs b/crates/rust/tests/codegen.rs index edfe44809..4d79b48c8 100644 --- a/crates/rust/tests/codegen.rs +++ b/crates/rust/tests/codegen.rs @@ -52,7 +52,6 @@ mod codegen_tests { fn works() {} } - #[cfg(feature = "async")] mod async_ { wit_bindgen::generate!({ path: $test,