diff --git a/Cargo.lock b/Cargo.lock index 7a2fd97..4db9920 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3412,7 +3412,7 @@ checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "wit-bindgen-core" version = "0.63.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=4f7496b180e4c0eaf787b0bc5ef4a3ac5c68151a#4f7496b180e4c0eaf787b0bc5ef4a3ac5c68151a" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=4a6406d2523716cf0a8b37da1ac2ce68b14d21ee#4a6406d2523716cf0a8b37da1ac2ce68b14d21ee" dependencies = [ "anyhow", "heck", @@ -3422,7 +3422,7 @@ dependencies = [ [[package]] name = "wit-bindgen-go" version = "0.63.0" -source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=4f7496b180e4c0eaf787b0bc5ef4a3ac5c68151a#4f7496b180e4c0eaf787b0bc5ef4a3ac5c68151a" +source = "git+https://github.com/bytecodealliance/wit-bindgen?rev=4a6406d2523716cf0a8b37da1ac2ce68b14d21ee#4a6406d2523716cf0a8b37da1ac2ce68b14d21ee" dependencies = [ "anyhow", "heck", diff --git a/Cargo.toml b/Cargo.toml index 7667f0c..ef7bd41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ reqwest = { version = "0.13.4", features = ["blocking"] } tar = "0.4.46" [workspace.package] -version = "0.5.2" +version = "0.5.3" edition = "2024" [workspace.lints.clippy] @@ -46,9 +46,10 @@ 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 = "4f7496b180e4c0eaf787b0bc5ef4a3ac5c68151a" } +wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "4a6406d2523716cf0a8b37da1ac2ce68b14d21ee" } wit-component = "0.262.0" wit-parser = "0.262.0" which = "8.0.4" dirs = "6.0.0" semver = "1.0.28" + diff --git a/main.go b/main.go index d6cb160..1cc0fe5 100644 --- a/main.go +++ b/main.go @@ -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.5.2" + release := "v0.5.3" directories := userdirs.ForApp( "componentize-go", diff --git a/tests/fixtures/memory-pressure/export_wit_world/wit_bindings.go b/tests/fixtures/memory-pressure/export_wit_world/wit_bindings.go index 075b168..a71c8f2 100644 --- a/tests/fixtures/memory-pressure/export_wit_world/wit_bindings.go +++ b/tests/fixtures/memory-pressure/export_wit_world/wit_bindings.go @@ -2,15 +2,30 @@ package export_wit_world import ( "fmt" + "runtime" + "runtime/debug" + "time" "wit_component/wit_world" ) func Run() { - // Build heap pressure so GC fires during the next host call - for i := 0; i < 10_000; i++ { - _ = make([]byte, 1024) + timer := time.AfterFunc(time.Hour, func() { panic("timer fired early") }) + defer timer.Stop() + old := debug.SetGCPercent(10) + defer debug.SetGCPercent(old) + var before, after runtime.MemStats + runtime.ReadMemStats(&before) + var retained [8]string + for i := range 4096 { + retained[i%len(retained)] = wit_world.GetStr() + if len(retained[i%len(retained)]) != 65536 { + panic("wrong import result length") + } } - - v := wit_world.GetStr() - fmt.Println(v) + runtime.KeepAlive(retained) + runtime.ReadMemStats(&after) + if after.NumGC == before.NumGC { + panic("test did not trigger garbage collection") + } + fmt.Println("ok") } diff --git a/tests/src/fixtures.rs b/tests/src/fixtures.rs index 082a2ce..a2644b8 100644 --- a/tests/src/fixtures.rs +++ b/tests/src/fixtures.rs @@ -96,7 +96,7 @@ fn fixture_memory_pressure() -> Result<()> { impl MemoryPressureImports for State { fn get_str(&mut self) -> String { - String::from("Hello!") + "x".repeat(65536) } } @@ -110,15 +110,9 @@ fn fixture_memory_pressure() -> Result<()> { let mut store = Store::new(&engine, State::new()); let tests = MemoryPressure::instantiate(&mut store, &component, &linker)?; - // Run component a generous number of times to make sure nothing panics - let num_invocations = 10_000; - for _ in 0..num_invocations { - tests.call_run(&mut store)?; - } - assert_eq!( - store.data().stdout(), - b"Hello!\n".repeat(num_invocations).as_slice() - ); + // The guest performs a finite allocation loop and asserts that GC ran. + tests.call_run(&mut store)?; + assert_eq!(store.data().stdout(), b"ok\n"); Ok(()) }