-
Notifications
You must be signed in to change notification settings - Fork 115
initial port to wasm #118
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
Open
ed2k
wants to merge
14
commits into
dds-bridge:develop
Choose a base branch
from
ed2k:wasm
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
initial port to wasm #118
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7d4a378
initial port to wasm
ed2k 2b7a87c
remove .js and .wasm output files
ed2k b9e748d
fix typo
ed2k bba7c0d
clean up unnecessary change
ed2k 8fdbe38
add dds wasm example
ed2k d45a170
Merge remote-tracking branch 'origin/develop' into wasm
ed2k 0e2382d
initial wasm build migrate to bazel
ed2k 0740b5b
auto find em++, analyze still have hand 2 ERROR
ed2k 167efe2
Merge remote-tracking branch 'origin/develop' into wasm
ed2k 2c0b79b
Remove Makefile_wasm
ed2k c61a146
remove obsolete make file
ed2k ccd81e6
Add emsdk WASM toolchain and wasm rules
ed2k 5e2c5a1
Docs: use Bazel hermetic Emscripten for WASM
ed2k 6a684e2
WASM: rename AnalysePlayBin, update docs & cleanup
ed2k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| # WebAssembly (WASM) Build Guide | ||
|
|
||
| This document explains how to build the DDS library and examples for WebAssembly using Bazel. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### 1. Emscripten SDK | ||
|
|
||
| You must have the Emscripten SDK installed and configured. Follow the official installation guide: | ||
| https://emscripten.org/docs/getting_started/downloads.html | ||
|
|
||
| After installation, ensure `em++` is available on your PATH: | ||
|
|
||
| ```bash | ||
| which em++ | ||
| ``` | ||
|
|
||
| ### 2. Bazel | ||
|
|
||
| Bazel 7.x or later is required. Install using your package manager or download from: | ||
| https://bazel.build/install | ||
|
|
||
| ## Building WASM Examples | ||
|
|
||
| ### Build All Examples | ||
|
|
||
| ```bash | ||
| cd /workspaces/dds | ||
| bazel build --config=wasm //examples:all | ||
| ``` | ||
|
|
||
| ### Build Specific Example | ||
|
|
||
| ```bash | ||
| bazel build --config=wasm //examples:solve_board | ||
| ``` | ||
|
|
||
|
ed2k marked this conversation as resolved.
|
||
| ### Output Files | ||
|
|
||
| When building with `--config=wasm`, the output files will be located in: | ||
| ``` | ||
| bazel-bin/examples/ | ||
| ``` | ||
|
|
||
| Depending on the target, you'll get: | ||
| - `target.js` - JavaScript bindings | ||
| - `target.wasm` - WebAssembly binary | ||
| - `target.html` - HTML shell (for some targets like `solve_board`) | ||
|
|
||
| ## Available WASM Targets | ||
|
|
||
| The following example targets are available for WASM builds: | ||
|
|
||
| ### Core Examples | ||
| - `solve_board` - Solves a single board (produces .html) | ||
| - `solve_board_pbn` - Solves a board from PBN notation (produces .html) | ||
| - `solve_all_boards` - Solves multiple boards (produces .html) | ||
| - `dds` - Main DDS example (produces .html) | ||
|
|
||
| ### Analysis Examples | ||
| - `analyse_play_bin` - Analyze play from binary format | ||
| - `analyse_play_pbn` - Analyze play from PBN format | ||
| - `analyse_all_plays_bin` - Analyze all plays from binary format | ||
| - `analyse_all_plays_pbn` - Analyze all plays from PBN format | ||
|
|
||
| ### Calculation Examples | ||
| - `calc_dd_table` - Calculate double dummy table | ||
| - `calc_dd_table_pbn` - Calculate DD table from PBN | ||
| - `calc_all_tables` - Calculate all tables | ||
| - `calc_all_tables_pbn` - Calculate all tables from PBN | ||
| - `dealer_par` - Calculate dealer par scores | ||
| - `par` - Calculate par scores | ||
| - `calc_par_context_example` - Par context example | ||
|
|
||
| ## WASM Build Configuration | ||
|
|
||
| The WASM build is configured through: | ||
|
|
||
| 1. **BUILD.bazel** - Defines the WASM config_setting: | ||
| ``` | ||
| config_setting( | ||
| name = "build_wasm", | ||
| constraint_values = ["@platforms//os:emscripten"], | ||
| ) | ||
| ``` | ||
|
|
||
| 2. **CPPVARIABLES.bzl** - Specifies WASM-specific compiler flags: | ||
| - Optimization: `-O3 -flto -mtune=generic` | ||
| - Define: `-D__WASM__` | ||
|
|
||
| 3. **.bazelrc** - Contains the `wasm` profile: | ||
| ``` | ||
| build:wasm --compiler=emscripten | ||
| build:wasm --cpu=wasm | ||
| build:wasm --cxxopt=-std=c++20 | ||
| ``` | ||
|
|
||
|
ed2k marked this conversation as resolved.
|
||
| ## Running WASM Examples | ||
|
|
||
| After building, you can run the examples: | ||
|
|
||
| ### Node.js (requires Node.js installed) | ||
|
|
||
| ```bash | ||
| node bazel-bin/examples/solve_board.js | ||
| ``` | ||
|
|
||
| ### Web Browser | ||
|
|
||
| For HTML targets, open the generated HTML file in a web browser: | ||
| ```bash | ||
| # Copy the output files to a web-accessible location | ||
| cp bazel-bin/examples/solve_board.* /path/to/webserver/ | ||
|
|
||
| # Then open in browser at http://localhost:8000/solve_board.html | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Issue: `em++` not found | ||
|
|
||
| **Solution:** Ensure Emscripten SDK is installed and sourced: | ||
| ```bash | ||
| source /path/to/emsdk/emsdk_env.sh | ||
| ``` | ||
|
|
||
| ### Issue: Build fails with undefined reference errors | ||
|
|
||
| **Solution:** This may indicate: | ||
| 1. Missing dependencies in the `deps` field of BUILD.bazel targets | ||
| 2. Emscripten-specific link flags needed | ||
|
|
||
| ### Issue: WASM binary is too large | ||
|
|
||
| **Solution:** Try building with aggressive optimization: | ||
| ```bash | ||
| bazel build --config=wasm -c opt //examples:solve_board | ||
| ``` | ||
|
|
||
| Use `--define=opt_level=3` for maximum optimization if available. | ||
|
|
||
| ## Compilation Flags | ||
|
|
||
| The WASM build uses the following key flags: | ||
|
|
||
| | Flag | Purpose | | ||
| |------|---------| | ||
| | `-O3` | Aggressive optimization | | ||
| | `-flto` | Link-time optimization | | ||
| | `-mtune=generic` | Generic CPU tuning | | ||
| | `-D__WASM__` | Defines `__WASM__` preprocessor constant | | ||
| | `-sWASM=1` | Emscripten WASM output (link flag) | | ||
|
|
||
| ## C++ Standard | ||
|
|
||
| The WASM build uses C++20 as specified in `.bazelrc`: | ||
| ``` | ||
| build:wasm --cxxopt=-std=c++20 | ||
| ``` | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - [Emscripten Documentation](https://emscripten.org/docs/) | ||
| - [Bazel Build System](https://bazel.build/docs) | ||
| - [DDS C++ API](c++_interface.md) | ||
| - [Build System Overview](BUILD_SYSTEM.md) | ||
|
|
||
| ## Next Steps | ||
|
|
||
| To integrate WASM builds into CI/CD: | ||
| 1. See `.github/workflows/ci_linux.yml` and `.github/workflows/ci_macos.yml` | ||
| 2. Add a WASM build job with `--config=wasm` and `em++` available | ||
| 3. Store WASM artifacts for download/release | ||
|
|
||
| ## Development Notes | ||
|
|
||
| - The `__WASM__` preprocessor constant is automatically defined for WASM builds | ||
| - Some threading and platform-specific features are disabled for WASM | ||
| - The build produces both `.js` and `.wasm` files | ||
| - For HTML targets, em++ produces `.html`, `.js`, and `.wasm` files together | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.