I'm newbie in Rust, and trying to compile Rust code into WASM:
use libloading::{Library, Symbol};
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn main() {
// Load the DLL
let lib = unsafe { Library::new("file.dll").unwrap() };
let connect: Symbol<unsafe extern "C" fn(*const std::os::raw::c_char, *const std::os::raw::c_char) -> i32;> =
unsafe { lib.get(b"Function\0").unwrap() };
But when i run wasm-pack
i'm getting the error:
error[E0432]: unresolved imports 'libloading::Library', 'libloading::Symbol'
--> src\lib.rs:1:18
|
1 | use libloading::{Library, Symbol};
| ^^^^^^^ ^^^^^^ no 'Symbol' in the root
| |
| no 'Library' in the root
For more information about this error, try 'rustc --explain E0432'`.
error: could not compile 'rust' due to previous error
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute 'cargo build': exited with exit code: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"`
If my undestanding is right - libloading can'not complie to WASM.
Does any one know way to comple such Rust code into WASM? Or may be there is any other approach to access functions from dll file in JS (React).
I'm trying:
- change 'release' in toml file;
- compile in binary file;