Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm support #64

Open
Easyoakland opened this issue Aug 17, 2023 · 5 comments
Open

Wasm support #64

Easyoakland opened this issue Aug 17, 2023 · 5 comments

Comments

@Easyoakland
Copy link

Easyoakland commented Aug 17, 2023

I've got Wasm support mostly working at this repo.
I also updated to clapv4.

Since you can't spawn multiple processes in Wasm it's set up to use an async main and poll the resulting future concurrently with the gui as explained here.

The file functionality has to come from within the main function the user of the library provides since you have to read a full file to memory instead of being able to use paths directly. For example using rfd's AsyncFileDialog

Also since stdout, stderr, stdin, etc... can't be redirected without nightly I used a custom logger that writes any logs to the gui instead of stdout.

A demo which uses these changes is visible here

I don't know if there's interest in merging some of these features here or not, but I thought it was worth bringing to attention.

@mkatychev
Copy link

This is really nice, what would it take to some of the wasm support put upstream?

@Easyoakland
Copy link
Author

  • @mkatychev An upstream maintainer (I think this is @MichalGniadek) would have to be present and interested in merging it. I would be mostly willing to fix things as needed to make this happen, but I won't file a pull request until I see something indicating it might be merged.
  • You should be able to use the fork as a git dependency (https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html). I'm not opposed to fixing issues filed on the fork, though keep in mind it's a hobby.
  • I'm not interested in publishing the fork on crates.io, so if the issue is that you would like to publish a crate with the fork as a dependency, then yes that will rely on upstream merging since I believe crates.io has a policy of only depending on other crates on crates.io.

@mkatychev
Copy link

Thanks for the reply, I think up-streaming this addition would fare better than maintaining a fork. My question was more along the lines of what mutually exclusive compilation flags to do you foresee this would add (to for example handle wasm32 compilation targets)

@Easyoakland
Copy link
Author

Easyoakland commented Dec 17, 2023

My question was more along the lines of what mutually exclusive compilation flags to do you foresee this would add (to for example handle wasm32 compilation targets)

I don't know what you mean. You compile with cargo build --target wasm32-unknown-unknown. You then serve the resulting wasm in your webpage. (Or use trunk or similar to mostly automate this).

@mkatychev
Copy link

I've gone through your changes, I think I answered my own question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants