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
63 changes: 42 additions & 21 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reqwest = { version = "0.13.4", features = ["blocking"] }
tar = "0.4.46"

[workspace.package]
version = "0.4.0"
version = "0.4.1"
edition = "2024"

[workspace.lints.clippy]
Expand All @@ -46,8 +46,8 @@ clap = { version = "4.6.1", features = ["derive"] }
regex = "1.12.4"
serde = { version = "1.0.228", features = ["derive"] }
toml = "1.1.0"
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "4642b6bcc4283361b5d85eb00b00addf618458a9" }
wit-component = "0.252.0"
wit-parser = "0.252.0"
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "50b799afcb886551565cb29c190371026aa55a30" }
wit-component = "0.253.0"
wit-parser = "0.253.0"
which = "8.0.4"
dirs = "6.0.0"
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// Although `componentize-go` is written in Rust, we can use this wrapper to
// make it available using e.g. `go install` and/or `go tool`.
func main() {
release := "v0.4.0"
release := "v0.4.1"

directories := userdirs.ForApp(
"componentize-go",
Expand Down
17 changes: 17 additions & 0 deletions tests/fixtures/named-implements/export_wit_world/wit_bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package export_wit_world

import (
"fmt"

"wit_component/foo_baz_store"
"wit_component/primary"
"wit_component/secondary"
)

// Run calls the same `store.get` function through the two named imports and
// the bare import, proving each routes to its own host instance.
func Run() {
fmt.Println(primary.Get("color"))
fmt.Println(secondary.Get("color"))
fmt.Println(foo_baz_store.Get("color"))
}
3 changes: 3 additions & 0 deletions tests/fixtures/named-implements/foo_baz_store/empty.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists for testing this package without WebAssembly,
// allowing empty function bodies with a //go:wasmimport directive.
// See https://pkg.go.dev/cmd/compile for more information.
30 changes: 30 additions & 0 deletions tests/fixtures/named-implements/foo_baz_store/wit_bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
//
// This code was generated from the following packages:
// foo:baz@0.1.0

package foo_baz_store

import (
witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
"unsafe"
"runtime"
)


//go:wasmimport foo:baz/store@0.1.0 get
func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr)

func Get(key string) string {
pinner := &runtime.Pinner{}
defer pinner.Unpin()

returnArea := uintptr(witRuntime.Allocate(pinner, (2*4), 4))
utf8 := unsafe.Pointer(unsafe.StringData(key))
pinner.Pin(utf8)
wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea)
value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
result := value;
return result

}
3 changes: 3 additions & 0 deletions tests/fixtures/named-implements/primary/empty.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists for testing this package without WebAssembly,
// allowing empty function bodies with a //go:wasmimport directive.
// See https://pkg.go.dev/cmd/compile for more information.
30 changes: 30 additions & 0 deletions tests/fixtures/named-implements/primary/wit_bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
//
// This code was generated from the following packages:
// foo:baz@0.1.0

package primary

import (
witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
"unsafe"
"runtime"
)


//go:wasmimport primary get
func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr)

func Get(key string) string {
pinner := &runtime.Pinner{}
defer pinner.Unpin()

returnArea := uintptr(witRuntime.Allocate(pinner, (2*4), 4))
utf8 := unsafe.Pointer(unsafe.StringData(key))
pinner.Pin(utf8)
wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea)
value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
result := value;
return result

}
3 changes: 3 additions & 0 deletions tests/fixtures/named-implements/secondary/empty.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists for testing this package without WebAssembly,
// allowing empty function bodies with a //go:wasmimport directive.
// See https://pkg.go.dev/cmd/compile for more information.
30 changes: 30 additions & 0 deletions tests/fixtures/named-implements/secondary/wit_bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Generated by `wit-bindgen` 0.59.0. DO NOT EDIT!
//
// This code was generated from the following packages:
// foo:baz@0.1.0

package secondary

import (
witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
"unsafe"
"runtime"
)


//go:wasmimport secondary get
func wasm_import_get(arg0 uintptr, arg1 uint32, arg2 uintptr)

func Get(key string) string {
pinner := &runtime.Pinner{}
defer pinner.Unpin()

returnArea := uintptr(witRuntime.Allocate(pinner, (2*4), 4))
utf8 := unsafe.Pointer(unsafe.StringData(key))
pinner.Pin(utf8)
wasm_import_get(uintptr(utf8), uint32(len(key)), returnArea)
value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
result := value;
return result

}
15 changes: 15 additions & 0 deletions tests/fixtures/named-implements/wit/world.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package foo:baz@0.1.0;

interface store {
get: func(key: string) -> string;
}

world named-implements {
// Import the same interface under separate names to exercise named
// `implements` imports.
import primary: store;
import secondary: store;
// Ensure a bare import alongside the named ones still works.
import store;
export run: func();
}
47 changes: 47 additions & 0 deletions tests/src/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,53 @@ async fn fixture_multiple_worlds() -> Result<()> {
Ok(())
}

#[test]
fn fixture_named_implements() -> Result<()> {
// Build the app with componentize-go
let app_dir = app_dir("named-implements")?;
let app = App::new(
&app_dir,
&[&app_dir.join("wit")],
&["named-implements"],
None,
true,
);
app.build_component().expect("failed to build app");

// Link the same `store` interface under three import names, each backed
// by a distinct host implementation, to verify that named `implements`
// imports route to their own instances.
let engine = engine()?;
let component = Component::from_file(&engine, app_dir.join("main.wasm"))?;

let mut linker = Linker::<State>::new(&engine);
wasmtime_wasi::p2::add_to_linker_sync(&mut linker)?;

for (import, prefix) in [
("primary", "primary"),
("secondary", "secondary"),
("foo:baz/store@0.1.0", "bare"),
] {
linker
.instance(import)?
.func_wrap("get", move |_store, (key,): (String,)| {
Ok((format!("{prefix}:{key}"),))
})?;
}

let mut store = Store::new(&engine, State::new());
let instance = linker.instantiate(&mut store, &component)?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
run.call(&mut store, ())?;

assert_eq!(
store.data().stdout(),
b"primary:color\nsecondary:color\nbare:color\n"
);

Ok(())
}

#[test]
fn fixture_memory_pressure() -> Result<()> {
// Build the app with componentize-go
Expand Down
1 change: 1 addition & 0 deletions tests/src/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ pub fn engine() -> anyhow::Result<Engine> {
let mut config = Config::new();
config.wasm_component_model(true);
config.wasm_component_model_async(true);
config.wasm_component_model_implements(true);
Engine::new(&config).map_err(|e| anyhow!(e))
}
Loading