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

This crate can run on wasm32 with a little modification. #16

Closed
warycat opened this issue Feb 4, 2020 · 5 comments
Closed

This crate can run on wasm32 with a little modification. #16

warycat opened this issue Feb 4, 2020 · 5 comments

Comments

@warycat
Copy link

warycat commented Feb 4, 2020

I wrote a traveling salesman problem in rust and build it with wasm bindgen.

  1. rayon::join doesn't work on wasm32, so I limit the population under 50.
  2. time::get_time is unimplemented!. so I stub the time crate return value with 0.

demo https://warycat.github.io/ga_wasm/
src https://github.com/warycat/ga_wasm

Thank you for making this awesome crate.

@Bauxitedev
Copy link

Bauxitedev commented Jun 8, 2021

I'm trying to run genevo in WASM, I've lowered my population to under 50 to avoid crashing, but there's still a crash related to the time crate:

panicked at 'time not implemented on this platform', library/std/src/sys/wasm/../unsupported/time.rs:39:9

How would I go about "stubbing the time crate return value with 0"?


Update: I forked genevo and changed the chrono dependency to:

[dependencies.chrono]
version = "0.4"
features = ["wasmbind"]

(as seen in chronotope/chrono#382 (comment))

Now it works!

@ravicious
Copy link

ravicious commented Aug 6, 2021

Thanks for the examples @warycat and @Bauxitedev. I was able to run the queens and the monkeys examples from v0.5.0 with the following modifications:

  1. In Cargo.toml I added this to dependencies:
rand = { version = "0.7.3", features = ["wasm-bindgen"] }
chrono = { version = "0.4", features = ["wasmbind"] }
  1. I reduced the population size to 40 for the queens example and 48 for the monkeys example (48 will probably work in both cases).

I used wasm-bindgen 0.2.63 and Rust 1.54 with the default wasm-pack 0.10.0 template.

Later I might check if the examples work with a bigger population after adding wasm-bindgen-rayon. The caveats page sounds rather scary and I don't need my algorithm to perform well, yet.

@haraldmaida
Copy link
Member

Thank you all for the feedback and input. I think I finally managed to add support for wasm32 targets to genevo. Starting with version 0.7.0 there is the crate feature wasm-bindgen that enables the support wasm32. Note that I disabled rayon (and multithreading) for wasm32 targets.

I modified the great example from @warycat to test if it really works. You can check out the modified example using genevo 0.7.0 here: https://github.com/haraldmaida/ga_wasm

@ravicious
Copy link

That’s fantastic news! Thank you very much!

I think I might try to see anyway if the previous version of genevo works with rayon if you use wasm-bindgen-rayon.

@ravicious
Copy link

Ok, I tried to make 0.5.0 run with wasm-bindgen-rayon, but I ran into problems straight away:

At this point I'll just upgrade to 0.7.0 instead. ;)

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

4 participants