CertainLach / jrsonnet

Rust implementation of Jsonnet language
MIT License
310 stars 36 forks source link

WASM bindings broken? #181

Open ste26054 opened 1 week ago

ste26054 commented 1 week ago

Hi!

I am trying to figure out how make make test-js work from the bindings folder (running Node 21.6.0). My goal is being able to evaluate vanilla jsonnet files with imports working through WASI.

I managed to get vm.evaluateSnippet to work on tag v0.5.0-pre96-test, but I cannot get vm.evaluateFile to work. It seems there was a refacto done at some point and bindings got broken 🤔. I now need to enable interop feature, but JsonnetImportCallback type got changed.

Here is my progress to make it work, though without much success for now: https://github.com/CertainLach/jrsonnet/compare/v0.5.0-pre96-test...ste26054:wasm-bindings?expand=1

make test-js                                                                                                                         
node --experimental-wasi-unstable-preview1 js/index
(node:70102) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Version = v0.19.1
4
Error: import io error: failed to find a pre-opened file descriptor through which "./test.jsonnet" could be opened
    at JsonnetVM.evaluateFile (/Users/ste26054/jrsonnet/bindings/js/index.js:74:18)
    at /Users/ste26054/jrsonnet/bindings/js/index.js:191:18

Any help would be much appreciated 🙂

CertainLach commented 1 week ago

For imports to work, you need to call jrsonnet_apply_static_import_callback() once. This method sets the import callback, which will use JS to read the files.

Without it, OS file importer will be used, and while it should work in theory with WASI, as I can see, you need some setup to make it work, is there something like _start export of wasm?..

https://github.com/bytecodealliance/wasmtime/issues/2902

I'll check why the bindings won't build with interop feature, thanks!

ste26054 commented 1 week ago

Thanks for the quick reply!

I see, I had commented out this call in my code.

Now I am getting error tried to import ./test.jsonnet, but absolute imports are not supported Which may be due to wrong attempts I made to make the build pass, and logging from js env callbacks doesn't do much.

Regarding WASI, yes I can see a _start exported function from the WASM file

ste26054 commented 1 week ago

Ok, I have found that CallbackImportResolver does not implement resolve function which is the reason for the above error (adding a print statement in ImportResolver shows that it is indeed called). Now I am clueless on how to actually implement it ^^