Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
exports: Vec<String>,
},
All,
}

/// Configuration for bindings generation.
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
Expand Down