Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate preopen of tmpdir in linking example #131

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
34 changes: 19 additions & 15 deletions examples/linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from wasmtime import Engine, Store, Module, Linker, WasiConfig

import tempfile

engine = Engine()

# Load and compile our two modules
Expand All @@ -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)