-
Notifications
You must be signed in to change notification settings - Fork 824
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
Replacement for trampolines in C API #1631
Comments
Hello @liamappelbe, Thank you for your question. We are deprecating the Wasmer C API in favour of the standard Wasm C API,
should work. It generates a |
My build system is not set up to call make like that. My current approach is to just grab the wasmer-runtime-c-api rust crate and build it as a shared library, and use wasmer.hh as a guide to see what functions the crate exports. Is there a rust crate I can pull in, analogous to wasmer-runtime-c-api, that exports the wasm.h functions? I just checked my current shared library and it doesn't have these functions. |
We can absolutely publish it as a crate, I think that may have fallen through the cracks with the refactor! |
We published the C API under a new name at version 1.0.0-alpha3 today https://crates.io/crates/wasmer-c-api ; @Hywan and I have discussed some changes that may affect the C API if anything changes about where to get the C API, we'll list it in the changelog and mention it here |
Awesome. Thanks! |
Is the wasmer-c-api crate doing something differently to the wasmer-runtime-c-api crate? My old approach isn't working anymore. I basically had a single wamer.rs file like this:
And a Cargo.toml like this:
So this was basically just bundling the wasmer-runtime-c-api into a dylib and exposing all its symbols. Switching to
I looked at the Cargo.toml for wasmer-c-api, and it provides cdylib and staticlib. I'm not sure what wasmer-runtime-c-api provided. cdylib and staticlib seems like sensible things for the wasmer-c-api to provide, but afaict there's no way of just getting the .so file from crates.io using cargo. This is why I wrote my wamer.rs and Cargo.toml files to wrap up the library in the first place. I'm pretty new to rust and cargo, so do you folks know how to either:
The best fix I've found so far is to remove the |
@liamappelbe Thanks for the report! I looked into it and adding "dylib" to the It creates 2 dylibs on OSX where I tested it: I'm surprised this worked with the old wasmer though as I've had issues reexporting symbols with Rust before, I believe it's a known issue (the issue seems to be reexporting through cdylib rust-lang/rfcs#2771 ). I just tried adding "rlib" to the I end up with the
As far as I'm aware, there's no way to build libraries like this directly with cargo. There could probably be a third party cargo sub-command to do this but I wasn't able to find one that does it. That does seem like a useful thing to be able to do... |
1646: Add `rlib` as a crate-type for wasmer-c-api r=MarkMcCaskey a=MarkMcCaskey This is how `wasmer-runtime-c-api` was before and seems to fix a use case that users relied on Fixes an issue mentioned in #1631 # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]>
Using the dep hack I mentioned to get a .so file, I've started experimenting with the new API.
Looking at mod.rs, I'm guessing the crate needs some build flags to get one of the JIT engines linked? |
@liamappelbe when compiling the wasmer-c-api, use the following feature flags: Let us know if that fixes the issue! |
Ok, I added the jit, cranelift, and wasi features. Now wasm_engine_new prints this error:
|
Thanks for posting the error. The last output seems to be a bug in our end. We are investigating at the moment to fix it asap. To accelerate as much as we can the debug process it could be possible to know the system you are running the code in, and perhaps the c code that is calling the Wasm api? |
@liamappelbe good news! Wasmer was not tested in a musl environment before, so that's why we didn't discover the issue until now. We are now investigating to add musl testing to our CI, so the issue doesn't happen again. I'll create a new comment here once we merge the PR! |
PR merged, the issue you reported should be fixed now in |
Thanks. Yeah, a crates.io release would be very helpful. |
I cloned this repo, verified that it contains #1650, and built libwasmer_c_api.so, but I'm still getting this libunwind error. To answer your question about my system, this is the output of
As for the code that's calling wasmer, I'm using dart:ffi to load and run it, which is the same as using dlopen/dlsym etc. But I was able to repro the bug using C++:
Output:
I haven't checked if the same thing happens under static linking. |
I think like I can make progress on the migration by just ignoring this error for now. The next thing I'm doing is listing the module's imports and exports. I the expected results when I build the .so in release mode, but in debug mode it's hitting an assert in wasm_module_exports:
Seems like this is just an over aggressive assertion (there's a similar one in wasm_module_imports). |
1673: Add conversion logic for boxed_vec, simplify vec creation code r=MarkMcCaskey a=MarkMcCaskey Fixes the issue mentioned in #1631 (comment) Co-authored-by: Mark McCaskey <[email protected]>
We just merged a fix for your last issue (the assertion error) :) We are investigating to fix the |
I'm migrating my memory stuff from the old API right now. It looks like there's a difference in how the limits struct works between the APIs. In the old API, whether the optional maximum was specified or not was controlled by a bool, but in the new API you just set it to this default value if you don't want to specify it: But when I tried setting the max to this default, I got this error:
My tests work fine when I do specify the maximum value. Also, when I specify a minimum value that's too big, the old API would fail gracefully, but the new API gives this error:
|
1682: Improve error messages around memory creation r=MarkMcCaskey a=MarkMcCaskey Fixes issue reported in #1631 (comment) Co-authored-by: Mark McCaskey <[email protected]>
I was wondering if you could help me to reproduce this. I have an environment that matches the The warning here is printed from LLVM's libunwind, which is surprising because wasmer doesn't use libunwind and neither does the C++ code you posted. Do you know how I could set up an environment like yours that links against LLVM's libunwind? Are you perhaps using compiler-rt instead of libgcc or libc++abi instead of libstdc++? Do you have any relevant settings in your |
I'm not using So to repro, go here and click on the download link. Unzip the .zip file, and then you can do the build like this (assuming the compiler ended up in ~/Downloads/rust):
I also had to clean out the cached stuff in ~/.cargo, since I had just done a build that didn't have the bug. TBH, I'm not sure if this is a bug in wasmer that is being exposed by this version of rust, or if it's a problem with this rust compiler. The compiler is being built from this fork of rust, so maybe a better git sleuth than me can figure out what's going on here. I'm going to reach out to the team that maintains it to see if they have any insights. Worst case, I can probably upload a vanilla rust compiler to CIPD. |
I just tried an older version of the CIPD rust compiler ( At least now I have a work around. I can stick with the older rust compiler for now. |
Thanks for you help, I was able to reproduce it! I've filed a bug on LLVM pointing out that their implementation of I also checked 2020-08-11-nightly and it doesn't reproduce the issue, I think this is a change fuchsia has made for their platform. |
Thanks for investigating. I think the most sensible fix is for Dart to use vanilla rustc, rather than Fuchsia's. |
Hey Liam, this should be fixed now but there's something I didn't mention: Wasm memory in the Wasm C API operates on pages (defined to be 0x1_0000 bytes each); the So the max value for Wasm memory in the limit is much lower than Anyways, Wasmer shouldn't panic there anymore and has clear error messages for these cases now! edit: Nick brought to my attention the use of this value as a sentinel value... that's a good point, that's something I had considered after shipping the PR but completely forgot about today. My previous PR does not have logic special casing this value, but that seems like a good change. |
Yeah, that was my read of the API too. I think this value is supposed to indicate that the max is unspecified. |
1688: Fix sentinel value in wasm_limits_t for memory in wasm_c_api r=MarkMcCaskey a=MarkMcCaskey FIxes issue mentioned in #1631 (comment) Co-authored-by: Mark McCaskey <[email protected]>
Thanks for doing all these fixes so quickly. What's the ETA on publishing a release to crates.io? I think this is the last thing blocking me from completing my migration to the new API. |
The only thing blocking us from doing a full release is #1694 -- we had a git dependency for some new features in our header file generating library (which would block us from publishing the C API crate to crates.io) and they just released a new version yesterday. We can do a release easily once that lands! |
I've synced to head again. Now I'm getting this build error:
Everything works fine when I just comment out that line. |
@liamappelbe I noticed that too and I believe I fixed it in #1694 ! Which just merged into master, perhaps reupdate and try again? |
@liamappelbe we've published the crates and released a new Wasmer binary |
It looks like the wasmer-c-api crate is still on alpha3: https://crates.io/crates/wasmer-c-api |
@liamappelbe thanks for the heads up, it should be up now! |
I've updated to alpha4, and my old build setup is now working again. Thanks! I'm running through my tests again, and I found another memory panic. Calling
|
Thanks for the bug report, I fixed it in #1718 and tested more edge cases too. |
1718: Prevent panic when min > static bound and max is less than it r=MarkMcCaskey a=MarkMcCaskey This change should be safe because we check that min <= max when actually making the memory, so this assert can never fire and produce a `MemoryStyle` that would let us create a memory. This PR also tests a lot more edge cases of memory creation in the C API. Resolves the issue brought up here #1631 (comment) # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <[email protected]> Co-authored-by: Mark McCaskey <[email protected]>
Can we close this issue now? |
yep |
In an earlier version of the C API the trampoline functions were marked as deprecated. Now it seems they've been deleted, and I can't find their replacement. The deprecation message mentioned exposing
DynamicFunc::new
to the C API. Any word on that?Is it possible/advisable to use
wasmer_import_func_new
directly? The documentation for that function isn't very clear, so I'm not sure how my imported function maps to thevoid (*func)(void *data)
.The text was updated successfully, but these errors were encountered: