Skip to content

Commit

Permalink
Add support for WIT features (#957)
Browse files Browse the repository at this point in the history
This commit updates the wasm-tools crates to their 209 versions which
include support for WIT features from bytecodealliance/wasm-tools#1508.
This adds a `--features` CLI flag in addition to a `features`
configuration of the Rust bindings macro.
  • Loading branch information
alexcrichton authored May 29, 2024
1 parent e8cd824 commit f6409d0
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 105 deletions.
66 changes: 34 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pulldown-cmark = { version = "0.9", default-features = false }
clap = { version = "4.3.19", features = ["derive"] }
indexmap = "2.0.0"

wasmparser = "0.208.0"
wasm-encoder = "0.208.0"
wasm-metadata = "0.208.0"
wit-parser = "0.208.0"
wit-component = "0.208.0"
wasmparser = "0.209.0"
wasm-encoder = "0.209.0"
wasm-metadata = "0.209.0"
wit-parser = "0.209.0"
wit-component = "0.209.0"

wit-bindgen-core = { path = 'crates/core', version = '0.25.0' }
wit-bindgen-c = { path = 'crates/c', version = '0.25.0' }
Expand Down
32 changes: 11 additions & 21 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,9 @@ pub fn imported_types_used_by_exported_interfaces(
for (_, export) in resolve.worlds[world].exports.iter() {
match export {
WorldItem::Function(_) => {}
WorldItem::Interface(i) => {
exported_interfaces.insert(*i);
live_export_types.add_interface(resolve, *i)
WorldItem::Interface { id, .. } => {
exported_interfaces.insert(*id);
live_export_types.add_interface(resolve, *id)
}
WorldItem::Type(_) => unreachable!(),
}
Expand Down Expand Up @@ -1346,7 +1346,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.resolve
}

fn anonymous_type_handle(&mut self, id: TypeId, handle: &Handle, docs: &Docs) {
fn anonymous_type_handle(&mut self, id: TypeId, handle: &Handle, _docs: &Docs) {
self.src.h_defs("\ntypedef ");
let resource = match handle {
Handle::Borrow(id) | Handle::Own(id) => id,
Expand All @@ -1360,7 +1360,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.print_typedef_target(id);
}

fn anonymous_type_tuple(&mut self, id: TypeId, ty: &Tuple, docs: &Docs) {
fn anonymous_type_tuple(&mut self, id: TypeId, ty: &Tuple, _docs: &Docs) {
self.src.h_defs("\ntypedef ");
self.src.h_defs("struct {\n");
for (i, t) in ty.types.iter().enumerate() {
Expand All @@ -1372,7 +1372,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.print_typedef_target(id);
}

fn anonymous_type_option(&mut self, id: TypeId, ty: &Type, docs: &Docs) {
fn anonymous_type_option(&mut self, id: TypeId, ty: &Type, _docs: &Docs) {
self.src.h_defs("\ntypedef ");
self.src.h_defs("struct {\n");
self.src.h_defs("bool is_some;\n");
Expand All @@ -1383,7 +1383,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.print_typedef_target(id);
}

fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, docs: &Docs) {
fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, _docs: &Docs) {
self.src.h_defs("\ntypedef ");
self.src.h_defs(
"struct {
Expand All @@ -1409,7 +1409,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.print_typedef_target(id);
}

fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, docs: &Docs) {
fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, _docs: &Docs) {
self.src.h_defs("\ntypedef ");
self.src.h_defs("struct {\n");
let ty = self.gen.type_name(ty);
Expand All @@ -1420,15 +1420,15 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
self.print_typedef_target(id);
}

fn anonymous_type_future(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs) {
fn anonymous_type_future(&mut self, _id: TypeId, _ty: &Option<Type>, _docs: &Docs) {
todo!("print_anonymous_type for future");
}

fn anonymous_type_stream(&mut self, id: TypeId, ty: &Stream, docs: &Docs) {
fn anonymous_type_stream(&mut self, _id: TypeId, _ty: &Stream, _docs: &Docs) {
todo!("print_anonymous_type for stream");
}

fn anonymous_typ_type(&mut self, id: TypeId, ty: &Type, docs: &Docs) {
fn anonymous_typ_type(&mut self, _id: TypeId, _ty: &Type, _docs: &Docs) {
todo!("print_anonymous_type for typ");
}
}
Expand Down Expand Up @@ -3098,16 +3098,6 @@ impl Source {
}
}

trait SourceExt {
fn as_source(&mut self) -> &mut wit_bindgen_core::Source;
}

impl SourceExt for wit_bindgen_core::Source {
fn as_source(&mut self) -> &mut wit_bindgen_core::Source {
self
}
}

fn wasm_type(ty: WasmType) -> &'static str {
match ty {
WasmType::I32 => "int32_t",
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait WorldGenerator {
for (name, import) in world.imports.iter() {
match import {
WorldItem::Function(f) => funcs.push((unwrap_name(name), f)),
WorldItem::Interface(id) => self.import_interface(resolve, name, *id, files),
WorldItem::Interface { id, .. } => self.import_interface(resolve, name, *id, files),
WorldItem::Type(id) => types.push((unwrap_name(name), *id)),
}
}
Expand All @@ -61,7 +61,7 @@ pub trait WorldGenerator {
for (name, export) in world.exports.iter() {
match export {
WorldItem::Function(f) => funcs.push((unwrap_name(name), f)),
WorldItem::Interface(id) => interfaces.push((name, id)),
WorldItem::Interface { id, .. } => interfaces.push((name, id)),
WorldItem::Type(_) => unreachable!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Types {
WorldItem::Function(f) => {
self.type_info_func(resolve, f, import);
}
WorldItem::Interface(id) => {
WorldItem::Interface { id, stability: _ } => {
for (_, f) in resolve.interfaces[*id].functions.iter() {
self.type_info_func(resolve, f, import);
}
Expand Down
1 change: 0 additions & 1 deletion crates/go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use wit_bindgen_core::{Direction, Files, Source, WorldGenerator};
mod bindgen;
mod imports;
mod interface;
mod path;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "clap", derive(clap::Args))]
Expand Down
31 changes: 0 additions & 31 deletions crates/go/src/path.rs

This file was deleted.

Loading

0 comments on commit f6409d0

Please sign in to comment.