evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
273 stars 26 forks source link

webassembly build #12

Closed ritz078 closed 5 years ago

ritz078 commented 5 years ago

I tried building on my own but it keeps breaking. will you like to distribute such a build that can be directly consumed using JS?

ritz078 commented 5 years ago

or maybe just commit your generated pkg folder too so that some exploring can have a look?

evestera commented 5 years ago

Sure, if it is of interest I could probably just publish the generated npm package to npm. I want to avoid committing it to the repo as it contains the binary webassembly file.

What kind of problems did you have trying to build the project?

ritz078 commented 5 years ago

It was an issue with the rustup version. I had to update it to nightly build to make it work. A npm package will be great. I want to use it on https://transform.tools/ . I can provide the link to your npm package there in case anyone wants to use it programatically.

evestera commented 5 years ago

Hmm, checked now, and seems I am building on stable myself, but I see the CI on this repo is incorrectly configured so that the wasm module is not built on CI, so I'm not too confident in how reliably that part builds.

What kind of interface would you need to use it the way you want? At the moment the wasm module is very much in an MVP stage, so the exposed function just returns a string no matter what happens (the exposed function).

ritz078 commented 5 years ago

I just need the generated pkg folder. I have been able to build it and just copied the pkg folder. Everything is working great.

I think the function returning a string is good enough. If there is an error, I can catch it via try/catch. So the API doesn't seem to have any issue. btw thanks for this. It has helped me close multiple issues on my repo relating to rust.

It also automatically creates a package.json file, so I guess you need nothing more to publish it. Let me know if you need any help on that.

evestera commented 5 years ago

Cool, if that's all you need I'll just let what is there now be the initial version of the npm package. And if I change the interface I'll leave the current function around for backwards compatibility.

So there is a npm package here now: https://www.npmjs.com/package/json_typegen_wasm

evestera commented 5 years ago

FYI: I ended up re-publishing (which was then 0.3.3) the wasm module, as compiled with

[profile.release]
lto = true
opt-level = "s"

the wasm module is ~200KB smaller, which is quite a bit.

ritz078 commented 5 years ago

That's awesome. Thanks a lot for this. ❤️