initial port to wasm#118
Conversation
src> make && make install examples> make && node AnalysePlayBin.js
|
Hi, I am interested in your contribution. But I am using windows and not familiar with these things. Could you share a compiled wasm file? Many thanks. |
|
This pull request is now outdated. There is a request for WASM support and I am keeping this pull request open to use it as a starting point. |
old example, here, you can download wasm from there, |
|
This is looking promising. Can we add the wasm build with at least some smoke tests to the ci_linux.yml workflow? Happy to add a ci_wasm.yml workflow if this is a better solution. |
|
|
||
| #if defined(__linux) || defined(__APPLE__) | ||
| #if defined(__linux) || defined(__APPLE__) || defined(__WASM__) | ||
| SetMaxThreads(0); |
There was a problem hiding this comment.
This should be a no-op by now.
|
@ed2k , do we need both bazel scripts and makefiles for the wasm build and the new examples? If they are required we need to document how to use them. |
There was a problem hiding this comment.
Pull request overview
This PR adds an initial WebAssembly (WASM) build path for DDS using Bazel, primarily by introducing a --config=wasm profile and Emscripten-driven genrules to produce .js/.wasm outputs for selected examples.
Changes:
- Add Bazel “wasm” configuration plumbing (
build_wasmconfig_setting,.bazelrcprofile, wasm-specificDDS_CPPOPTS/defines). - Add
*_wasmgenrules inexamples/BUILD.bazelto invokeem++and emitsolve_board.js/.wasmandAnalysePlayBin.js/.wasm. - Add
__WASM__guards in example programs and add WASM build documentation + legacy Makefile experiments.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/Makefiles/Makefile_wasm |
New legacy Makefile intended for em++ static lib build (currently references missing include files). |
library/src/utility/BUILD.bazel |
Exposes utility source(s) for wasm genrules via filegroup. |
library/src/trans_table/BUILD.bazel |
Exposes transposition-table sources for wasm genrules via filegroup. |
library/src/system/BUILD.bazel |
Exposes system sources for wasm genrules via filegroup. |
library/src/solver_context/BUILD.bazel |
Exposes solver_context source for wasm genrules via filegroup. |
library/src/moves/BUILD.bazel |
Exposes moves sources for wasm genrules via filegroup. |
library/src/lookup_tables/BUILD.bazel |
Exposes lookup table source for wasm genrules via filegroup. |
library/src/heuristic_sorting/BUILD.bazel |
Exposes heuristic sorting source for wasm genrules via filegroup. |
library/src/BUILD.bazel |
Adds visibility + a dds_wasm_sources filegroup to feed wasm genrules. |
examples/solve_board.cpp |
Enables SetMaxThreads(0) call under __WASM__. |
examples/solve_board_pbn.cpp |
Enables SetMaxThreads(0) call under __WASM__. |
examples/Makefiles/Makefile_wasm |
New legacy Makefile for em++ examples (currently mismatched vs repo filenames). |
examples/dds.cpp |
New CLI-like example (currently does not compile against current headers / helpers). |
examples/BUILD.bazel |
Adds wasm genrules + attempts to add wasm link flags to native cc_binaries. |
examples/analyse_play_bin.cpp |
Adds __WASM__ guard around ErrorMessage (currently introduces UB). |
docs/wasm_build.md |
New WASM build guide (currently inconsistent with actual Bazel targets/config). |
CPPVARIABLES.bzl |
Adds wasm-specific compile flags and __WASM__ define selection. |
BUILD.bazel |
Adds build_wasm config_setting. |
.bazelrc |
Adds build:wasm profile enabling --define=wasm=true and opt mode. |
old Make system gone
Enable hermetic Emscripten via the emsdk toolchain and switch project WASM config to use it. .bazelrc now configures the emsdk platform/cpu for --config=wasm; BUILD.bazel's wasm config_setting uses values.cpu=wasm. MODULE.bazel adds the emsdk dependency and registers its toolchains. CPPVARIABLES.bzl updates WASM cppopts (adds -fexceptions, removes -mtune=generic). examples/BUILD.bazel now loads emsdk wasm_rules and replaces custom em++ genrules with wasm_cc_binary targets, and updates WASM link options (exceptions and memory flags).
Revise wasm_build.md to remove manual Emscripten install instructions and note that Bazel will automatically download and configure a hermetic emscripten toolchain. Update BUILD.bazel example to use values={"cpu":"wasm"} and mark the code block as python. Adjust CPPVARIABLES and flags (remove -mtune=generic, add -fexceptions). Update .bazelrc examples to use @emsdk//:platform_wasm, add host_cxxopt and compilation_mode=opt. Remove the em++ not found troubleshooting and the recommendation to make em++ explicitly available in CI. Update the compilation flags table to include -fexceptions, -sALLOW_MEMORY_GROWTH=1 and -sINITIAL_MEMORY=268435456.
the smoke tests need node to run, I put it into future TODO for now |
Rename analyse_play_bin target to AnalysePlayBin and update WASM binary target names and filegroup references; adjust analyse_play_bin.cpp error handling for WASM builds to avoid ErrorMessage and print error code instead; remove deprecated examples/dds.cpp. Also remove -Wno-character-conversion from DDS CPPOPTS. Revise docs/wasm_build.md to use the new WASM target names, simplify available targets list, and trim/clarify WASM-related notes and output instructions.
bazel build, tested under macos
$ bazel build --config=wasm //examples:solve_board_wasm
test
$ node bazel-bin/examples/solve_board.js