Skip to content

initial port to wasm#118

Open
ed2k wants to merge 14 commits into
dds-bridge:developfrom
ed2k:wasm
Open

initial port to wasm#118
ed2k wants to merge 14 commits into
dds-bridge:developfrom
ed2k:wasm

Conversation

@ed2k
Copy link
Copy Markdown

@ed2k ed2k commented Mar 10, 2022

bazel build, tested under macos
$ bazel build --config=wasm //examples:solve_board_wasm

test
$ node bazel-bin/examples/solve_board.js

SolveBoard, hand 1: solutions 3 OK, solutions 2 OK
--------------------------------------------------
            QJ6
            K652
            J85
            T98
AT942                   873
AQ4                     J97
32                      AT764
KJ3                     Q4
            K5
            T83
            KQ9
            A7652


solutions == 3

  card suit   rank   equals score 
     0 D      5             5     
     1 D      8             5     
     2 D      J             5     
     3 C      T      98     5     
     4 S      6             5     
     5 S      Q      J      5     
     6 H      2             4     
     7 H      6      5      4     
     8 H      K             4     

solutions == 2

  card suit   rank   equals score 
     0 D      5             5     
     1 D      8             5     
     2 D      J             5     
     3 C      T      98     5     
     4 S      6             5     
     5 S      Q      J      5     

SolveBoard, hand 2: solutions 3 OK, solutions 2 OK
--------------------------------------------------
            AK96
            KQ8
            A98
            K63
87                      QJT5432
A62                     T
QJT4                    6
AT75                    QJ82
            -
            J97543
            K7532
            94


solutions == 3

  card suit   rank   equals score 
     0 C      2             4     
     1 C      8             4     
     2 C      Q      J      4     
     3 H      T             3     
     4 D      6             3     
     5 S      Q      JT     3     
     6 S      5      432    2     

solutions == 2

  card suit   rank   equals score 
     0 C      2             4     
     1 C      8             4     
     2 C      Q      J      4     

SolveBoard, hand 3: solutions 3 OK, solutions 2 OK
--------------------------------------------------
            73
            QJT
            AQ54
            T752
AKJ9842                 QT6
K                       876
T8                      KJ9
J93                     AQ84
            5
            A95432
            7632
            K6


solutions == 3

  card suit   rank   equals score 
     0 H      A             3     
     1 D      3      2      3     
     2 D      7      6      3     
     3 S      5             3     
     4 H      5      432    2     
     5 H      9             2     
     6 C      6             1     
     7 C      K             1     

solutions == 2

  card suit   rank   equals score 
     0 H      A             3     
     1 D      3      2      3     
     2 D      7      6      3     
     3 S      5             3     

@S-N-O-R-L-A-X
Copy link
Copy Markdown

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.

@zzcgumn
Copy link
Copy Markdown
Collaborator

zzcgumn commented May 20, 2026

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.

@ed2k ed2k marked this pull request as draft May 20, 2026 21:52
@ed2k ed2k marked this pull request as ready for review May 20, 2026 22:56
@ed2k
Copy link
Copy Markdown
Author

ed2k commented May 20, 2026

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.

old example, here, you can download wasm from there,
https://ed2k.github.io/dds/test_dds.html

Comment thread src/Makefiles/Makefile_wasm Outdated
Comment thread src/Makefiles/Makefile_wasm Outdated
@zzcgumn
Copy link
Copy Markdown
Collaborator

zzcgumn commented May 26, 2026

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.

Comment thread examples/solve_board.cpp

#if defined(__linux) || defined(__APPLE__)
#if defined(__linux) || defined(__APPLE__) || defined(__WASM__)
SetMaxThreads(0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a no-op by now.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will try later

@zzcgumn
Copy link
Copy Markdown
Collaborator

zzcgumn commented May 26, 2026

@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_wasm config_setting, .bazelrc profile, wasm-specific DDS_CPPOPTS/defines).
  • Add *_wasm genrules in examples/BUILD.bazel to invoke em++ and emit solve_board.js/.wasm and AnalysePlayBin.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.

Comment thread examples/analyse_play_bin.cpp
Comment thread examples/dds.cpp Outdated
Comment thread examples/dds.cpp Outdated
Comment thread examples/dds.cpp Outdated
Comment thread docs/wasm_build.md
Comment thread docs/wasm_build.md
Comment thread BUILD.bazel
Comment thread examples/BUILD.bazel
Comment thread examples/Makefiles/Makefile_wasm Outdated
Comment thread src/Makefiles/Makefile_wasm Outdated
ed2k added 5 commits May 26, 2026 11:37
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.
@ed2k
Copy link
Copy Markdown
Author

ed2k commented May 27, 2026

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.

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.
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

Successfully merging this pull request may close these issues.

4 participants