Skip to content

Unable to compile to wasm #132

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

Closed
hce opened this issue May 30, 2019 · 11 comments
Closed

Unable to compile to wasm #132

hce opened this issue May 30, 2019 · 11 comments
Labels
Future work An issue which would be nice to do, but not one of the current priorities. help wanted

Comments

@hce
Copy link

hce commented May 30, 2019

Trying to build the project using "cargo web build" (which targets wasm32-unknown-unknown) I get the following error:

error[E0425]: cannot find function free in module libc
--> src/lua.rs:387:19
|
387 | libc::free(ptr as *mut libc::c_void);
| ^^^^ not found in libc
error[E0412]: cannot find type c_void in module libc
--> src/lua.rs:387:42
|
387 | libc::free(ptr as *mut libc::c_void);
| ^^^^^^ not found in libc
help: possible candidates are found in other modules, you can import them into scope
|
1 | use core::ffi::c_void;
|
1 | use std::ffi::c_void;
|
1 | use std::os::raw::c_void;

@kyren
Copy link
Contributor

kyren commented May 30, 2019

rlua uses libc because it uses PUC Rio Lua underneath, which is a C library that also uses libc. I don't think you can compile PUC Lua to wasm directly either, but if you can find a reasonable way I can remove the libc dependency in rlua once enough of the allocators features are stable.

@hce
Copy link
Author

hce commented May 31, 2019

Which features of libc are used that rlua needs? Only memory allocation?

For the purposes I'm currently using rlua, it'd be perfectly ok to allocate a fixed block of memory to Lua until a real fix is found...

@kyren
Copy link
Contributor

kyren commented May 31, 2019

I really don't know the current situation w.r.t. libc and wasm32-unknown-unknown (which I'm assuming you're using). If you remove the libc dependency from rlua, PUC-Lua itself will still use libc's malloc and free (and tons of other stuff from libc too), so I'm not sure what good it will do to remove the libc dependency from rlua without solving the rest of it.

Can you build PUC-Lua for wasm right now at all? I think you might be able to with emscripten, but I'm really not sure. This is getting more in-depth into wasm build infrastructure than I'm really familiar with, but this problem that you're running into is probably the first of many. Certainly getting the "rlua" part working is vastly easier than getting the "actual PUC-Rio Lua library" part working.

I guess the libc crate on wasm32-unknown-unknown targets is empty, which is the immediate cause of this bug, but certainly you'd run into problems after this trying to link the PUC-Lua static library? I think in order to get this to work you'd need to compile rlua in an emscripten environment.. but then I suppose you can set the rust target to "wasm32-unknown-emscripten" and this problem would go away anyway?

@hce
Copy link
Author

hce commented May 31, 2019

Thanks for the quick reply!

I haven't tried wasm32-unknown-emscripten yet, using wasm32-unknown-unknown right now as you said. Considering all the complications you've mentioned, it probably doesn't make sense to fix this right now.

@hce
Copy link
Author

hce commented May 31, 2019 via email

@TannerRogalsky
Copy link

Emscripten's pipeline is long. It gives you a ton of stuff that doesn't exist in wasm32-unknown-unknown land. Most relevant to this discussion is that it provides a libc implementation.

WASI solves some of this. The wasm32-wasi build target gets your further. But ultimately we run into PUC-Lua's dependence on setjmp/longjmp for error handling. "WASI doesn't yet support setjmp/longjmp or C++ exceptions, as it is waiting for unwinding support in WebAssembly."

So, eventually, this will likely Just Work for WASI targets but not yet.

@clouds56
Copy link

I think it takes long for exception support in wasi, is it possible to take prebuilt lua.wasm from wapm?
https://github.com/wapm-packages/lua

I'm not sure if it possible to link .wasm with .wasm, and I cannot found any resource talking about this on google.

@TannerRogalsky
Copy link

@clouds56 It's possible. Rust's link attribute supports wasm modules. https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute

@jugglerchris jugglerchris added the Future work An issue which would be nice to do, but not one of the current priorities. label Jul 4, 2021
@askdaddy
Copy link

Emscripten's pipeline is long. It gives you a ton of stuff that doesn't exist in wasm32-unknown-unknown land. Most relevant to this discussion is that it provides a libc implementation.

WASI solves some of this. The wasm32-wasi build target gets your further. But ultimately we run into PUC-Lua's dependence on setjmp/longjmp for error handling. "WASI doesn't yet support setjmp/longjmp or C++ exceptions, as it is waiting for unwinding support in WebAssembly."

So, eventually, this will likely Just Work for WASI targets but not yet.

what about https://github.com/WebAssembly/wasi-libc

@jugglerchris
Copy link
Collaborator

I'm very interested in having rlua running in wasm but don't currently have time to look into it. I'd be very welcoming of any work towards it if anyone wants to have a crack at it. :-)

@khvzak
Copy link
Member

khvzak commented Feb 6, 2024

rlua is going to be deprecated soon and this feature is already supported by mlua (wasm32 emscripten target)

@khvzak khvzak closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Future work An issue which would be nice to do, but not one of the current priorities. help wanted
Projects
None yet
Development

No branches or pull requests

7 participants