wasmerio / rusty_jsc

Rust bindings for the JavaScriptCore engine.
MIT License
99 stars 7 forks source link

Building with cargo-wasi #2

Open Ethan-Arrowood opened 1 year ago

Ethan-Arrowood commented 1 year ago

Hello, I'm trying to use cargo-wasi to build a rust app that uses rusty_jsc, but I'm seeing this error when I run cargo wasi build:

❯ cargo wasi run 
   Compiling rusty_jsc_sys v0.0.2
   Compiling anyhow v1.0.66
   Compiling rusty_jsc_sys v0.0.3
error: library kind `framework` is only supported on Apple targets

error: could not compile `rusty_jsc_sys` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `rusty_jsc_sys` due to previous error

My Cargo.toml is simple:

[package]
name = "project"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusty_jsc = "0.0.2"
rusty_jsc_macros = "0.0.3"
rusty_jsc_sys = "0.0.3"

And the main.rs is just one of your examples:

use rusty_jsc::JSContext;

fn main() {
    let mut context = JSContext::default();
    let value = context.evaluate_script("'hello, world'", 1);
    if let Some(value) = value {
        println!("{}", value.to_string(&context));
    }
}

Any ideas? I'm new to the world of WASI so hopefully its something I just don't understand

penberg commented 1 year ago

The problem you have is that the JavaScriptCore framework that rusty_jsc provides bindings for is a native library. So you can't build rusty_jsc for a WebAssembly target with cargo wasi build.

Not sure what you are building, but if you really need to run JavaScriptCore on top of a WebAssembly runtime, there's https://github.com/mbbill/JSC.js that might work for you.

Ethan-Arrowood commented 1 year ago

Oh so the native library would also need some kind of way to build down to WASI?

And yeah the target isn't just WASM, but WASI. I'm poking around seeing if its possible to build a rust based JS Runtime that can compile down to WASI. Thank you for the recommendation, ill look into that library too!