-
Notifications
You must be signed in to change notification settings - Fork 721
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
wasm2c example for Bytecode Alliance's Javy #2521
Comments
wasm2c is basically agnostic to a Wasm module's imports and whether those imports come from the host or from another Wasm module. If you want to run a Wasm module that imports from the There was a PR started to contribute an implementation of WASI p1 for a POSIX host (#2002) but it looks like it hasn't been touched in a while. |
I've been sitting on the I'm just trying to figure out how to create the There's no roadmap. |
This is what I'm doing in JavaScript
Using wasmtime
The code produced by |
Trying to create
|
hmm maybe we should add a wasm2c example for imports and exports... |
Yeah, I read that during my research. No clue why you folks have not merged that, yet. I will say that
That's why I wrote https://gitlab.com/-/snippets/4782260/raw/main/wasi-minimal.js - without intending to access the filesystem using
I'm trying to figure out how to create the There's zero guidance on how to do that for WASM compiled with WASI-SDK that uses |
As @keithw already mentioned above, wasm2c (and wabt in general) are generic tools that work on all wasm files without prejudice as to which SDK to toolchain produces them. If a wasm file has host imports (e.g. |
I can find a What I'm asking for here is a roadmap on how to create that The only examples you have do not happen to use WASI at all. https://github.com/WebAssembly/wabt/blob/main/wasm2c/README.md. I managed to get the |
The rot13 example (and the bottom of the wasm2c README) shows how to instantiate a module that takes imports. Please see https://github.com/WebAssembly/wabt/tree/main/wasm2c/examples/rot13 -- does this help? |
I read that, and all of your examples before I filed this issue. Kind of helps. But doesn't really provide a complete roadmap for WASM to C using WASI Preview 1. And you folks are already messing around with components and Preview 2. So, let's say you compiled that |
But hey, if you folks ain't in to it, and don't see the lack of such an example as being an omission, there's nowhere else for me to go. Already tried w2c2. No luck. Already emailed folks who said ask here. I mean, y'll are the experts and gurus in this domain. Don't want to make it seem like I'm putting you out asking for an example of |
What Alan Watts said kind of always plays out, no matter the domain:
|
Perhaps you could elaborate on the specific difficulties you have in implementing the I agree that providing an example of using using |
You have a complete example with the Anyway, I already used What I'm basically doing is a full loop from JavaScript to C to WASM/native executable, back to JavaScript. Here's original Javy source code back to JavaScript from WASM using
Now, I can compile JavaScript to C with QuickJS So, what's my motivation? Well, in research compiling JavaScript to C I found that there's no FOSS code that can do that. I found a random Web site that says it uses "artificial intelligence" to convert JavaScript to C, and actually does a rather good job. That's difficult for me to accept. There has to be a way to convert JavaScript to C - and back, and branch to WASM and/or native executable in the middle if desired - without slapping a "artificial intelligence" label on the gear, and gating the gear behind IPR labels and such - an unobservable box. So, I'm looking into the WebAssembly world because I know there's wabt's Emscripten doesn't really compile to WASM standalone, that I can see. It's expecting JavaScript to be the caller. WASI-SDK works. WASI is a thing. So that's how I wound up here. Assume I don't know C at all. No clue about how to construct that What's the roadmap? |
Assume you have a generic Assume you compile that What I'm basically asking here is how you arrange the necessary code in a generic Just write out which function calls what in C. A generic example in C code that will result in an executable when compiled with Again, write the README.md like the individual doesn't know C. |
we don't believe such a thing is possible - wasm2c has a specialized API due to being a specialized wasm runtime, it's not gonna be easily compatible with an arbitrary WASI implementation. |
I'm afraid that if you don't know C at all then its going to be hard for your successfully create the required embedding code that is needed (e.g. main.c). What you are looking for (IIUC) is some kind of off-the-shelf solution for wiring up wasm2c output with an existing host API (in this case the WASI API), but AFAIK that doesn't exist. Wiring up wasm2c-generated code to an existing host APIs is fairly tricky because the wasm2c-generated code uses pointers from its own internal address space whereas the host APIs using expects/uses real host pointers. Any time you have pointers at the boundary (very common in We can leave this issue open as a feature request if you like, but its not something that exists today. |
Um, every
I already did that and you already have that with the I didn't know C, C++, Rust, Python, Bash, WebAssembly, and multiple JavaScript engines and runtimes either. I still managed to write a Native Messaging host for each https://github.com/guest271314/NativeMessagingHosts. I'm saying the lack of a WASI example is an omission. You're the experts. Make it so No. 1. I don't think you need to do much here. Just take the
|
I know what I'm asking for doesn't exist now. Yeah, leavin' it open as a feature request works, too. I'm most highly motivated to answer my own questions. If you folks on here or somebody else in the wild doesn't get here first, for other people to test and improve if necessary. Thanks for your time. Carry on. But keep this one in mind. |
Doesn't WASI support shipped in LLVM? https://github.com/tmikov/hermes/tree/shermes-wasm/external/llvh/lib/Support/Wasi. |
The repo has an example of using wasi (uvwasi) under the benchmarks
LLVM supports the WASI interface, so you can compile Wasm modules that rely on WASI. What is being discussed above is a WASI implementation, which is different. At some point, I may add an easy-to-use optional adapter for uvwasi, but I am unlikely to get to this for a while. Closing this bug, because an example already exists. |
@shravanrn Thanks.
That would be helpful. I started exploring WebAssembly because I remembered something somebody wrote a while ago about the goal being a "universal executable". I asked the Javy folks about a In the interim I started exploring other options. Facebook's Static Hermes has an I was thinking this would be something the WebAssembly folks would want to explore and make so in furtherance of the original WebAssembly concept, coming from Native Client, et al. Instead I have met resistance to some degree to putting all the pieces together from the WebAssembly folks. I'm not a WebAssembly expert. I'm in JavaScript world, mostly. However, I too, have the goal of JavaScript as a universal executable, at least the source code that universal executables can be made from. Compiling JavaScript to WASM with WASI support using Static Hermes. I would think that Bytecode Alliance and WebAssembly projects would be the ones making these easy-to-use examples, with documentation of what is going on an why. Instead, I'm in the field trying to put pieces together myself. I look forward to reading and testing what you might eventually publish. Thanks, again. |
What I have so far running and taking apart the dhrystone example
With
|
Kindly include a
wasm2c
example where the input is a WASM produced by Bytecode Alliance's Javy. There's no roadmap for compiling C output bywasm2c
to an executable where we need to includewasi_snapshot_preview1
in the process.cc @shravanrn @sbc100 @keithw
The text was updated successfully, but these errors were encountered: