diff --git a/src/bindings.rs b/src/bindings.rs index dab7c287..1b8e730e 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -12,14 +12,17 @@ use indexmap::{IndexMap, IndexSet}; use semver::Version; use wasm_pkg_client::PackageRef; use wit_bindgen_core::Files; -use wit_bindgen_rust::{AsyncConfig, Opts, WithOption}; +use wit_bindgen_rust::{Opts, WithOption}; use wit_component::DecodedWasm; use wit_parser::{ Interface, Package, PackageName, Resolve, Type, TypeDefKind, TypeOwner, UnresolvedPackageGroup, World, WorldId, WorldItem, WorldKey, }; -use crate::{metadata::Ownership, registry::PackageDependencyResolution}; +use crate::{ + metadata::{AsyncConfig, Ownership}, + registry::PackageDependencyResolution, +}; // Used to format `unlocked-dep` import names for dependencies on // other components. @@ -135,9 +138,14 @@ impl<'a> BindingsGenerator<'a> { pub_export_macro: settings.pub_export_macro, generate_unused_types: settings.generate_unused_types, disable_custom_section_link_helpers: settings.disable_custom_section_link_helpers, - - // TODO: pipe this through to the CLI options, requires valid serde impls - async_: AsyncConfig::None, + async_: match &settings.async_ { + AsyncConfig::None => wit_bindgen_rust::AsyncConfig::None, + AsyncConfig::Some { imports, exports } => wit_bindgen_rust::AsyncConfig::Some { + imports: imports.clone(), + exports: exports.clone(), + }, + AsyncConfig::All => wit_bindgen_rust::AsyncConfig::All, + }, }; let mut files = Files::default(); diff --git a/src/metadata.rs b/src/metadata.rs index a9abdb76..672207e7 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -56,6 +56,18 @@ impl FromStr for Ownership { } } +#[derive(Default, Debug, Clone, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum AsyncConfig { + #[default] + None, + Some { + imports: Vec, + exports: Vec, + }, + All, +} + /// Configuration for bindings generation. #[derive(Debug, Clone, Deserialize)] #[serde(default)] @@ -110,6 +122,9 @@ pub struct Bindings { /// Disabling this can shave a few bytes off a binary but makes /// library-based usage of `generate!` prone to breakage. pub disable_custom_section_link_helpers: bool, + /// Determines which functions to lift or lower `async`, if any. + #[serde(rename = "async")] + pub async_: AsyncConfig, } impl Default for Bindings { @@ -132,6 +147,7 @@ impl Default for Bindings { pub_export_macro: Default::default(), generate_unused_types: Default::default(), disable_custom_section_link_helpers: Default::default(), + async_: Default::default(), } } }