Skip to content

Commit 1afce96

Browse files
committed
feat: add WebAssembly support and fugue-evo-wasm bindings crate
- Add cargo feature flags: std, parallel, checkpoint (default all enabled) - Feature-gate parallel/rayon functionality for WASM compatibility - Make CheckpointError WASM-compatible with cfg-gated variants - Add non-parallel impl blocks to SimpleGA for WASM target - Feature-gate island model (requires parallel feature) - Feature-gate checkpoint file I/O (requires checkpoint feature) - Add to_json/from_json methods to InteractiveSession for WASM - Create fugue-evo-wasm crate with JavaScript-friendly wrappers - Add RealVectorOptimizer for browser-based optimization - Support built-in fitness functions (Sphere, Rastrigin, Rosenbrock) - Generate TypeScript definitions via wasm-pack build
1 parent 17ee2e0 commit 1afce96

16 files changed

Lines changed: 1107 additions & 54 deletions

File tree

Cargo.lock

Lines changed: 105 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[workspace]
2+
members = [".", "crates/fugue-evo-wasm"]
3+
14
[package]
25
name = "fugue-evo"
36
version = "0.1.0"
@@ -9,6 +12,12 @@ repository = "https://github.com/alexnodeland/fugue-evo"
912
keywords = ["genetic-algorithm", "evolution", "optimization", "probabilistic-programming"]
1013
categories = ["algorithms", "science"]
1114

15+
[features]
16+
default = ["std", "parallel", "checkpoint"]
17+
std = []
18+
parallel = ["rayon"]
19+
checkpoint = [] # File-based checkpointing (requires std)
20+
1221
[dependencies]
1322
# Linear algebra for CMA-ES
1423
nalgebra = "0.33"
@@ -17,27 +26,33 @@ nalgebra = "0.33"
1726
rand = "0.8"
1827
rand_distr = "0.4"
1928

20-
# Parallelism
21-
rayon = "1.10"
29+
# Parallelism (optional)
30+
rayon = { version = "1.10", optional = true }
2231

2332
# Serialization
2433
serde = { version = "1.0", features = ["derive"] }
2534
serde_json = "1.0"
2635
bincode = "1.3"
2736

28-
# Compression for checkpoints
29-
zstd = "0.13"
30-
3137
# Error handling
3238
thiserror = "2.0"
3339

3440
# Observability
3541
tracing = "0.1"
3642
fugue-ppl = "0.1.0"
3743

44+
# WASM support (enabled via getrandom js feature when targeting wasm32)
45+
[target.'cfg(target_arch = "wasm32")'.dependencies]
46+
getrandom = { version = "0.2", features = ["js"] }
47+
3848
[dev-dependencies]
3949
# Testing utilities
4050
proptest = "1.5"
4151
criterion = "0.5"
4252
approx = "0.5"
4353
tempfile = "3.10"
54+
55+
# Examples requiring parallel feature
56+
[[example]]
57+
name = "island_model"
58+
required-features = ["parallel"]

crates/fugue-evo-wasm/Cargo.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "fugue-evo-wasm"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Alex Nodeland"]
6+
description = "WebAssembly bindings for fugue-evo genetic algorithm library"
7+
license = "MIT OR Apache-2.0"
8+
repository = "https://github.com/alexnodeland/fugue-evo"
9+
keywords = ["genetic-algorithm", "wasm", "webassembly", "optimization"]
10+
categories = ["algorithms", "wasm"]
11+
12+
[lib]
13+
crate-type = ["cdylib", "rlib"]
14+
15+
[dependencies]
16+
# Core library without parallel/checkpoint features
17+
fugue-evo = { path = "../..", default-features = false, features = ["std"] }
18+
19+
# WASM bindings
20+
wasm-bindgen = "0.2"
21+
wasm-bindgen-futures = "0.4"
22+
js-sys = "0.3"
23+
serde-wasm-bindgen = "0.6"
24+
25+
# Serialization for JS interop
26+
serde = { version = "1.0", features = ["derive"] }
27+
serde_json = "1.0"
28+
29+
# Random number generation with JS entropy
30+
getrandom = { version = "0.2", features = ["js"] }
31+
rand = "0.8"
32+
33+
[dev-dependencies]
34+
wasm-bindgen-test = "0.3"
35+
36+
[profile.release]
37+
opt-level = "s"
38+
lto = true
39+
40+
[package.metadata.wasm-pack.profile.release]
41+
wasm-opt = false

0 commit comments

Comments
 (0)