-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add a wasmtime::Linker
type
#1384
Conversation
This commit adds a new type to the `wasmtime` crate, a `Linker`. This linker is intended to vastly simplify calling `Instance::new` by easily performing name resolution and incrementally defining state over time. The goal here is to start down a path of making linking wasm modules in `wasmtime` a first-class and ergonomic operation. This is highly likely to evolve over time and get tweaked through releases as we iterate towards a design well-suited for `wasmtime`, but this is intended to at least be the initial foundation for such functionality. This commit additionally also adds a C API for the linker and switches the existing linking examples to using this linker in both Rust and C. One piece of future work I'd like to tackle next is to integrate WASI into the `wasmtime` crate in a more first-class manner. This [`Linker`] type provides a great location to hook into the instantiation process to easily instantiate modules with WASI imports. That's a relatively large refactoring for now though and I figured it'd be best left for a different time. Closes bytecodealliance#727
Subscribe to Label ActionThis issue or pull request has been labeled: "wasi", "wasmtime:api", "wasmtime:c-api" Users Subscribed to "wasmtime:api"Users Subscribed to "wasmtime:c-api"To subscribe or unsubscribe from this label, edit the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great and I really like how it simplifies things. I like this better than taking a list of instances to Module.Instantiate
in the C# API, so I'll create a first-class Linker
representation instead.
Just some minor feedback, but otherwise 👍 from me.
Updated! |
/// let mut linker = Linker::new(&store); | ||
/// let ty = GlobalType::new(ValType::I32, Mutability::Const); | ||
/// let global = Global::new(&store, ty, Val::I32(0x1234))?; | ||
/// linker.define("host", "offset", global); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a ?
to handle errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good eye, I've added a commit to #1391 which denies warnings in doctests to catch this
This commit adds a new type to the
wasmtime
crate, aLinker
. Thislinker is intended to vastly simplify calling
Instance::new
by easilyperforming name resolution and incrementally defining state over time.
The goal here is to start down a path of making linking wasm modules in
wasmtime
a first-class and ergonomic operation. This is highly likelyto evolve over time and get tweaked through releases as we iterate
towards a design well-suited for
wasmtime
, but this is intended to atleast be the initial foundation for such functionality.
This commit additionally also adds a C API for the linker and switches
the existing linking examples to using this linker in both Rust and C.
One piece of future work I'd like to tackle next is to integrate WASI
into the
wasmtime
crate in a more first-class manner. This [Linker
]type provides a great location to hook into the instantiation process to
easily instantiate modules with WASI imports. That's a relatively large
refactoring for now though and I figured it'd be best left for a
different time.
Closes #727