Stranger6667/jsonschema

WASM bindings revisited

Closed this issue · 7 comments

I'd like to use jsonschema in a wasm a environment. I tried this code (below). The app compiles just fine, however it crashes just as soon as it just as soon as it reaches JSONSchema::compile

let schema = json!({"maxLength": 5});
let compiled = JSONSchema::compile(&schema);

I tried different versions / features combinations based in previous issues regarding the same matter (#222, #395) . They each crash for different reasons.

jsonschema = { version = "=0.15.1", default-features = false, features = ["structopt"]}
exception: no mapping for imported function sched_yield

jsonschema = { version = "0.17.0", default-features = false, features = ["resolve-file"]}
exception: no mapping for imported function fd_read

As soon as I add resolve-http to the features I get: could not find blocking in reqwest, which is what we're trying to avoid.

Which features do I need to add in order to use JSONSchema in WASM environment?

Oh, thats problematic right now - I don't think that resolving works just yet, but it will as soon as I'll finish the rewrite. There will be async + blocking API for resolving refs via network. Not sure about the filesystem, but wasm32-wasi probably would work.

Also, I am going to run a full test suite on WASM as the implementation is ready.

Meanwhile - what is your rustc version and target?

rustc version

rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

target: wasi-sdk-20.0

Looking forward to the rewrite!

Thanks! If you have any feedback on the API (current or the next version) & usability, feel free to leave a comment in this discussion

Hi- I am not a power user and am quite new to developing in rust and using jsonschema so apologies in advance if this is a misinformed comment/question. I have written a rust package that checks an instance of a json schema using the jsonschema draft7 validator and it works great. I was following the Mozilla docs for compiling a rust package into wasm (https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_Wasm) and it fails to compile due to what looks like a reqwest dependency in jsonschema.

wasm-pack build --target web

I get the same errors as #222 (comment)

Do you have a sense for why this is the case, how to overcome it, or if this is a fundamental challenge that the new API will address? Thank you!

Closing this in favor of #568. I've implemented some improvements & added a CI job that runs tests on WASM (excluding the JSON Schema test suite though), so it is very much usable right now. Documentation will come in the next release

I'm running jsonschema = { version = "0.23.0", default-features = false } in my WASM.
Works fine!
Thanks for the fix.

Glad to hear it!