Skip to content
Open
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
4 changes: 2 additions & 2 deletions crates/component-macro/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct Config {
include_generated_code_from_file: bool,
}

pub fn expand(input: &Config) -> Result<TokenStream> {
let mut src = match input.opts.generate(&input.resolve, input.world) {
pub fn expand(input: &mut Config) -> Result<TokenStream> {
let mut src = match input.opts.generate(&mut input.resolve, input.world) {
Ok(s) => s,
Err(e) => return Err(Error::new(Span::call_site(), e.to_string())),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/component-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn flags(input: proc_macro::TokenStream) -> proc_macro::TokenStream {

#[proc_macro]
pub fn bindgen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
bindgen::expand(&parse_macro_input!(input as bindgen::Config))
bindgen::expand(&mut parse_macro_input!(input as bindgen::Config))
.unwrap_or_else(Error::into_compile_error)
.into()
}
11 changes: 11 additions & 0 deletions crates/component-macro/tests/codegen/implements.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package foo:foo;

interface store {
get: func(key: string) -> option<string>;
set: func(key: string, value: string);
}

world cache {
import hot-cache: store;
import durable: store;
}
5 changes: 5 additions & 0 deletions crates/component-macro/tests/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ fn process_expanded(path: &str, suffix: &str, src: &str) -> Result<()> {
Path::new("tests/expanded").join(stem).with_extension("rs")
};
if std::env::var("BINDGEN_TEST_BLESS").is_ok_and(|val| !val.is_empty()) {
if let Ok(prev) = std::fs::read(&expanded_path)
&& prev == formatted_src.as_bytes()
{
return Ok(());
}
std::fs::write(expanded_path, formatted_src)?;
} else {
match std::fs::read_to_string(&expanded_path) {
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,15 @@ pub mod foo {
Host::return_char(*self)
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap(
"take-char",
move |
Expand All @@ -241,6 +240,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static,
{
let mut inst = linker.instance("foo:foo/chars")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/char_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,15 @@ pub mod foo {
async move { Host::return_char(*self).await }
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_async(
"take-char",
move |
Expand All @@ -255,6 +254,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/char_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,15 @@ pub mod foo {
}
pub trait Host: Send {}
impl<_T: Host + ?Sized + Send> Host for &mut _T {}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_concurrent(
"take-char",
move |caller: &wasmtime::component::Accessor<T>, (arg0,): (char,)| {
Expand All @@ -234,6 +233,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/char_tracing_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,15 @@ pub mod foo {
async move { Host::return_char(*self).await }
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_async(
"take-char",
move |
Expand Down Expand Up @@ -284,6 +283,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/conventions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,15 @@ pub mod foo {
Host::bool(*self)
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap(
"kebab-case",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
Expand Down Expand Up @@ -403,6 +402,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static,
{
let mut inst = linker.instance("foo:foo/conventions")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/conventions_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,15 @@ pub mod foo {
async move { Host::bool(*self).await }
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap_async(
"kebab-case",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
Expand Down Expand Up @@ -461,6 +460,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
17 changes: 14 additions & 3 deletions crates/component-macro/tests/expanded/conventions_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,15 @@ pub mod foo {
}
pub trait Host: Send {}
impl<_T: Host + ?Sized + Send> Host for &mut _T {}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap_concurrent(
"kebab-case",
move |caller: &wasmtime::component::Accessor<T>, (): ()| {
Expand Down Expand Up @@ -409,6 +408,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,15 @@ pub mod foo {
async move { Host::bool(*self).await }
}
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap_async(
"kebab-case",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
Expand Down Expand Up @@ -621,6 +620,18 @@ pub mod foo {
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/conventions")?;
add_to_linker_instance(&mut inst, host_getter)
}
}
}
}
Expand Down
Loading
Loading