Skip to content

Commit f0a3713

Browse files
Saphereyeanematode
andcommitted
Add wasm32 and wasm32-relaxed-simd targets
Bench: 3204302 Co-authored-by: anematode <timothy.herchen@gmail.com>
1 parent 252bfd9 commit f0a3713

17 files changed

Lines changed: 713 additions & 64 deletions

File tree

.cargo/config.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ rustflags = ["-C", "target-cpu=native"]
1515

1616
[target.x86_64-pc-windows-msvc]
1717
rustflags = ["-C", "target-cpu=native"]
18+
19+
[target.wasm32-unknown-unknown]
20+
rustflags = [
21+
"-C", "target-feature=+atomics,+bulk-memory,+simd128,+relaxed-simd",
22+
"-C", "link-arg=--shared-memory",
23+
"-C", "link-arg=--max-memory=1073741824",
24+
"-C", "link-arg=--import-memory",
25+
"-C", "link-arg=--export=__wasm_init_tls",
26+
"-C", "link-arg=--export=__tls_size",
27+
"-C", "link-arg=--export=__tls_align",
28+
"-C", "link-arg=--export=__tls_base",
29+
]

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition = "2024"
55
build = "build/build.rs"
66
publish = false
77

8+
[lib]
9+
crate-type = ["cdylib", "rlib"]
10+
811
[features]
912
default = ["syzygy"]
1013
syzygy = []
@@ -26,3 +29,8 @@ bindgen = "0.71.1"
2629

2730
[dependencies]
2831
libc = "0.2.175"
32+
web-time = "1"
33+
34+
[target.'cfg(target_arch = "wasm32")'.dependencies]
35+
wasm-bindgen = "0.2"
36+
js-sys = "0.3"

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ endif
2323
rule:
2424
cargo rustc --release -- -C target-cpu=native --emit link=$(NAME)
2525

26+
wasm:
27+
unset RUSTFLAGS && rustup run nightly \
28+
cargo build -Z build-std=panic_abort,std \
29+
--lib --target wasm32-unknown-unknown --release --no-default-features
30+
wasm-bindgen target/wasm32-unknown-unknown/release/reckless.wasm --target web --out-dir pkg
31+
wasm-opt -O3 --enable-simd --enable-threads --enable-relaxed-simd \
32+
pkg/reckless_bg.wasm -o pkg/reckless_bg.wasm
33+
34+
2635
x64-check:
2736
RUSTFLAGS="-C target-cpu=x86-64" cargo check --target x86_64-unknown-linux-gnu --no-default-features
2837
RUSTFLAGS="-C target-cpu=x86-64-v3" cargo check --target x86_64-unknown-linux-gnu --no-default-features

build/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ fn main() {
2020
generate_engine_version();
2121

2222
#[cfg(feature = "syzygy")]
23-
generate_syzygy_binding();
23+
if std::env::var("CARGO_CFG_TARGET_ARCH").as_deref() != Ok("wasm32") {
24+
generate_syzygy_binding();
25+
}
2426

2527
if !Path::new("networks").join(NETWORK_NAME).exists() && env::var("EVALFILE").is_err() {
2628
download_network();

src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![allow(unsafe_op_in_unsafe_fn)]
2+
#![warn(clippy::large_types_passed_by_value)]
3+
#![warn(clippy::trivially_copy_pass_by_ref)]
4+
#![warn(clippy::redundant_clone)]
5+
#![cfg_attr(target_arch = "wasm32", allow(dead_code, unused_imports))]
6+
7+
mod board;
8+
mod evaluation;
9+
mod history;
10+
mod lookup;
11+
mod misc;
12+
mod movepick;
13+
mod nnue;
14+
mod numa;
15+
mod parameters;
16+
mod search;
17+
mod setwise;
18+
mod stack;
19+
mod thread;
20+
mod threadpool;
21+
mod time;
22+
mod transposition;
23+
mod types;
24+
25+
mod tools;
26+
27+
#[cfg(not(target_arch = "wasm32"))]
28+
mod uci;
29+
30+
#[cfg(feature = "syzygy")]
31+
mod tb;
32+
33+
#[cfg(feature = "syzygy")]
34+
#[allow(warnings)]
35+
mod bindings;
36+
37+
#[cfg(target_arch = "wasm32")]
38+
pub mod wasm;
39+
40+
#[cfg(not(target_arch = "wasm32"))]
41+
pub fn run(buffer: std::collections::VecDeque<String>) {
42+
lookup::initialize();
43+
nnue::initialize();
44+
uci::message_loop(buffer);
45+
}

src/main.rs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,5 @@
1-
#![allow(unsafe_op_in_unsafe_fn)]
2-
#![warn(clippy::large_types_passed_by_value)]
3-
#![warn(clippy::trivially_copy_pass_by_ref)]
4-
#![warn(clippy::redundant_clone)]
5-
6-
mod board;
7-
mod evaluation;
8-
mod history;
9-
mod lookup;
10-
mod misc;
11-
mod movepick;
12-
mod nnue;
13-
mod numa;
14-
mod parameters;
15-
mod search;
16-
mod setwise;
17-
mod stack;
18-
mod thread;
19-
mod threadpool;
20-
mod time;
21-
mod tools;
22-
mod transposition;
23-
mod types;
24-
mod uci;
25-
26-
#[cfg(feature = "syzygy")]
27-
mod tb;
28-
29-
#[cfg(feature = "syzygy")]
30-
#[allow(warnings)]
31-
mod bindings;
32-
1+
#[cfg(not(target_arch = "wasm32"))]
332
fn main() {
34-
lookup::initialize();
35-
nnue::initialize();
36-
37-
let buffer: std::collections::VecDeque<String> = std::env::args().skip(1).collect();
38-
39-
uci::message_loop(buffer);
3+
let buffer = std::env::args().skip(1).collect();
4+
reckless::run(buffer);
405
}

0 commit comments

Comments
 (0)