-
Notifications
You must be signed in to change notification settings - Fork 117
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
Closed
Closed
initial port to wasm #118
Changes from all 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,136 @@ | ||
| # WebAssembly (WASM) Build Guide | ||
|
|
||
| This document explains how to build the DDS library and examples for WebAssembly using Bazel. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### Bazel | ||
|
|
||
| Bazel 7.x or later is required. Install using your package manager or download from: | ||
| https://bazel.build/install | ||
|
|
||
| The Emscripten SDK (emsdk) does NOT need to be manually installed. Bazel will automatically download, configure, and cache the appropriate hermetic Emscripten toolchain for your host platform as part of the build process. | ||
|
|
||
| ## Building WASM Examples | ||
|
|
||
| ### Build All Examples | ||
|
|
||
| ```bash | ||
| cd /workspaces/dds | ||
| bazel build //examples:all_examples_wasm | ||
| ``` | ||
|
|
||
| ### Build Specific Example | ||
|
|
||
| ```bash | ||
| bazel build //examples:solve_board_wasm | ||
| ``` | ||
|
|
||
|
ed2k marked this conversation as resolved.
|
||
| ### Output Files | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| ## Available WASM Targets | ||
|
|
||
| The following example targets are available for WASM builds: | ||
|
|
||
| ### Implemented Examples | ||
| - `solve_board` - Solves a single board (produces .js and .wasm) | ||
|
|
||
| - `analyse_play_bin` - Analyze play from binary format | ||
|
|
||
|
|
||
| ## WASM Build Configuration | ||
|
|
||
| The WASM build is configured through: | ||
|
|
||
| 1. **BUILD.bazel** - Defines the WASM config_setting: | ||
| ```python | ||
| config_setting( | ||
| name = "build_wasm", | ||
| values = {"cpu": "wasm"}, | ||
| ) | ||
| ``` | ||
|
|
||
| 2. **CPPVARIABLES.bzl** - Specifies WASM-specific compiler flags: | ||
| - Optimization: `-O3 -flto` | ||
| - Exceptions: `-fexceptions` | ||
| - Define: `-D__WASM__` | ||
|
|
||
| 3. **.bazelrc** - Contains the `wasm` profile: | ||
| ``` | ||
| build:wasm --platforms=@emsdk//:platform_wasm | ||
| build:wasm --cpu=wasm | ||
| build:wasm --cxxopt=-std=c++20 | ||
| build:wasm --host_cxxopt=-std=c++20 | ||
| build:wasm --compilation_mode=opt | ||
| ``` | ||
|
|
||
|
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 (TODO) | ||
|
|
||
| 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 | ||
| ``` | ||
|
|
||
| ## Compilation Flags | ||
|
|
||
| The WASM build uses the following key flags: | ||
|
|
||
| | Flag | Purpose | | ||
| |------|---------| | ||
| | `-O3` | Aggressive optimization | | ||
| | `-flto` | Link-time optimization | | ||
| | `-fexceptions` | Enable C++ exceptions | | ||
| | `-D__WASM__` | Defines `__WASM__` preprocessor constant | | ||
| | `-sWASM=1` | Emscripten WASM output (link flag) | | ||
| | `-sALLOW_MEMORY_GROWTH=1` | Allow heap growth at runtime | | ||
| | `-sINITIAL_MEMORY=268435456` | Configure 256MB initial memory | | ||
|
|
||
| ## 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. Store WASM artifacts for download/release | ||
|
|
||
| ## Development Notes | ||
|
|
||
| - The `__WASM__` preprocessor constant is added initially to bypass error, need to check again whether we can remove | ||
| - Some threading and platform-specific features are disabled for WASM | ||
| - The build flow for a reusable library wasm | ||
| - A good HTML example | ||
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.