Stream: git-wasmtime

Topic: wasmtime / Issue #2330 Call Native libraries from rust code


view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 14:52):

litch0 opened Issue #2330:

<!-- Please try to describe precisely what you would like to do in
Cranelift/Wasmtime and/or expect from it. You can answer the questions below if
they're relevant and delete this text before submitting. Thanks for opening an
issue! -->

Feature

Call Native c++ librarys based on operational system/
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->

Benefit

Enable option for making native gui apps using for example gtk or qt, and other stuff too
<!-- What is the value of adding this in Cranelift/Wasmtime? -->

Implementation

Maybe using extern crates for this? I have no idea
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 15:15):

bjorn3 commented on Issue #2330:

C++ doesn't have a stable ABI, so it is not possible to call any C++ functions from any language that is not C++. You will have to use a C wrapper if you want to call it from an other language.

Is this a feature request for Cranelift or Wasmtime? Are you a user of the Cranelift code generator and do you want to use native libraries from code you compiled using it? This is already possible. Or do you want to use native libraries from code compiled to wasm? This will never be possible. Wasm runs in a VM. This VM is only capable of addressing 4GB of memory, which is only a small chunk of the full address space on 64bit architectures. This means that if a native library returns a pointer outside this small chunk of memory, which it should as Wasmtime reserves the full 4GB of address space, then it isn't possible for the wasm code to access it. In addition the memory layout and call conv of the wasm code is very likely different that of the architecture you are running Wasmtime on. And that doesn't even account for the security issues with this. If you don't care about the security issues, then why are you using wasm instead of compiling to native code?

What is possible is to write a program that embeds wasmtime and exports safe interfaces for the functions you want to use to the wasm code.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 16:10):

litch0 commented on Issue #2330:

Cool, so, I am planning to use the wastime to distribute my software instead of compiling it into multiple wrappers, and I like the idea of the VM running under it. Ok, so where can I find documentation about exposing interfaces and interop between them?
Finally I tried making a simple Gtk app using wastime but it failed to build gtk-sys, now I understand why, thanks

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 16:34):

litch0 commented on Issue #2330:

more specific how can i expose functions from my webassembly rust code

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 16:35):

alexcrichton commented on Issue #2330:

For wasmtime I'd recommend browsing the documentation which should cover how to embed wasmtime in your application. For binding native APIs in C++ you'll probably, as @bjorn3 mentioned, want to make a C wrapper that you can call from the native Rust code. Then you can create a Func for each piece of functionality you'd like to expose to wasm. It'd be up to you what the APIs look like and how data is transferred across the boundary. The various examples in this repository should help you get started!

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 16:40):

litch0 commented on Issue #2330:

I am browsing this doc for a long time and i havent found anything about exposing or calling functions on my webassembly code like, I have a runtime and a example app in the example app i have a function called main and on the runtime I have a function called runApp, how do i call runApp on the main function of the rust webassembly

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 16:45):

litch0 commented on Issue #2330:

I found it
https://docs.wasmtime.dev/wasm-rust.html

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 18:03):

tschneidereit commented on Issue #2330:

There's also a nice series of blog posts by @radu-matei on using witx to expose interfaces. This one is a good start, but be sure to check the other posts on Radu's blog, too.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 18:32):

litch0 commented on Issue #2330:

Thanks

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 19:26):

litch0 commented on Issue #2330:

It work, Thanks

view this post on Zulip Wasmtime GitHub notifications bot (Oct 28 2020 at 19:26):

litch0 closed Issue #2330:

<!-- Please try to describe precisely what you would like to do in
Cranelift/Wasmtime and/or expect from it. You can answer the questions below if
they're relevant and delete this text before submitting. Thanks for opening an
issue! -->

Feature

Call Native c++ librarys based on operational system/
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->

Benefit

Enable option for making native gui apps using for example gtk or qt, and other stuff too
<!-- What is the value of adding this in Cranelift/Wasmtime? -->

Implementation

Maybe using extern crates for this? I have no idea
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->


Last updated: Nov 22 2024 at 16:03 UTC