diff --git a/examples/linking.py b/examples/linking.py index 4c24dbf8..7bdea057 100644 --- a/examples/linking.py +++ b/examples/linking.py @@ -2,6 +2,8 @@ from wasmtime import Engine, Store, Module, Linker, WasiConfig +import tempfile + engine = Engine() # Load and compile our two modules @@ -13,18 +15,20 @@ linker = Linker(engine) linker.define_wasi() -# Create a `Store` to hold instances, and configure wasi state -store = Store(engine) -wasi = WasiConfig() -wasi.inherit_stdout() -store.set_wasi(wasi) - -# Instantiate our first module which only uses WASI, then register that -# instance with the linker since the next linking will use it. -linking2 = linker.instantiate(store, linking2) -linker.define_instance(store, "linking2", linking2) - -# And with that we can perform the final link and the execute the module. -linking1 = linker.instantiate(store, linking1) -run = linking1.exports(store)["run"] -run(store) +with tempfile.TemporaryDirectory() as tmpdirname: + # Create a `Store` to hold instances, and configure wasi state + store = Store(engine) + wasi = WasiConfig() + wasi.inherit_stdout() + wasi.preopen_dir(tmpdirname, tmpdirname) + store.set_wasi(wasi) + + # Instantiate our first module which only uses WASI, then register that + # instance with the linker since the next linking will use it. + linking2 = linker.instantiate(store, linking2) + linker.define_instance(store, "linking2", linking2) + + # And with that we can perform the final link and the execute the module. + linking1 = linker.instantiate(store, linking1) + run = linking1.exports(store)["run"] + run(store)