Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:

# 3️⃣ Unit tests and WASM builds (hermetic emsdk toolchain downloaded by Bazel)
- name: Test web helpers, system tests, e2e, and CalcDDtablePBN
run: bazel test --verbose_failures //web:web_tests //web:web_system_tests //examples/wasm:all
run: bazel test --verbose_failures //web:web_tests //web:web_system_tests //wasm:all

- name: Build WASM targets
run: bazel build --verbose_failures //examples/wasm:all_examples_wasm
run: bazel build --verbose_failures //wasm:all_examples_wasm

# 4️⃣ Smoke test: run solve_board under Node.js — pass if it does not crash
- name: Smoke test solve_board_wasm
run: node bazel-bin/examples/wasm/solve_board.js
run: node bazel-bin/wasm/solve_board.js

# 5️⃣ Upload test logs
- name: Upload test logs - WASM
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "pybind11_bazel", version = "3.0.1")
bazel_dep(name = "rules_python", version = "2.0.1")
bazel_dep(name = "toolchains_llvm", version = "1.7.0")
# WASM builds (//examples/wasm:*, //web:dds_mvp_wasm). If you bump this version,
# WASM builds (//wasm:*, //web:dds_mvp_wasm). If you bump this version,
# rebuild and run web/update_wasm.sh; see docs/wasm_build.md and patch_mvp_wasm.py.
bazel_dep(name = "emsdk", version = "5.0.7")

Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions docs/wasm_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ WASM targets use `wasm_cc_binary`, which applies an Emscripten **platform transi
### Build all WASM examples

```bash
bazel build //examples/wasm:all_examples_wasm
bazel build //wasm:all_examples_wasm
```

The alias `//examples:all_examples_wasm` points at the same filegroup.

### Build a specific example

```bash
bazel build //examples/wasm:solve_board_wasm
bazel build //wasm:solve_board_wasm
```

### Output files

Outputs are under `bazel-bin/examples/wasm/`:
Outputs are under `bazel-bin/wasm/`:

- `solve_board.js` / `solve_board.wasm`
- `AnalysePlayBin.js` / `AnalysePlayBin.wasm`
- `calc_dd_table_pbn.js` / `calc_dd_table_pbn.wasm`

## Available WASM targets

Rules in `examples/wasm/BUILD.bazel` wrap native examples in `examples/`:
Rules in `wasm/BUILD.bazel` wrap native examples in `examples/`:

- `solve_board_wasm` — solves a single board
- `analyse_play_bin_wasm` — analyze play from binary format
Expand All @@ -66,7 +66,7 @@ Native builds (`bazel build //...`, `bazel test //library/tests/...`, Python bin
### Node.js

```bash
node bazel-bin/examples/wasm/solve_board.js
node bazel-bin/wasm/solve_board.js
```

### Web browser (DDS MVP)
Expand All @@ -89,7 +89,7 @@ The MVP loads wasm from `dds_mvp_wasm_bin.js` (base64, no network fetch), so `fi
./web/clean_wasm.sh # web artifacts only
```

For other experiments, copy built `.js` / `.wasm` files from `bazel-bin/examples/wasm/` to any static file server.
For other experiments, copy built `.js` / `.wasm` files from `bazel-bin/wasm/` to any static file server.

## Compilation flags

Expand All @@ -114,22 +114,22 @@ build:macos --cxxopt=-std=c++20
build:linux --cxxopt=-std=c++20
```

There is no separate `build:wasm` profile in `.bazelrc`; WASM builds are selected by targeting `//examples/wasm:*`.
There is no separate `build:wasm` profile in `.bazelrc`; WASM builds are selected by targeting `//wasm:*`.

## Tests

Unit and system tests (Node.js required for system tests; skipped if `node` is not on `PATH`):

```bash
bazel test //web:web_tests //web:web_system_tests //web:web_e2e_tests
bazel test //examples/wasm:all
bazel test //wasm:all
```

`bazel test //...` skips targets tagged `e2e` by default (see `.bazelrc`). Run Playwright tests explicitly, e.g. `bazel test //web:web_e2e_tests` or `bazel test --test_tag_filters=e2e //web:dds_mvp_e2e_test`. To run all tests, including the Playwright tests: `bazel test --test_tag_filters= /...`

- **`//web:dds_mvp_wasm_system_test`** — builds `//web:dds_mvp_wasm`, runs `patch_mvp_wasm` / `gen_wasm_bin_js` / `verify_wasm_js`, then calls `dds_mvp_calc_table` via Node (`web/tests/dds_mvp_wasm_node.mjs`).
- **`//web:dds_mvp_e2e_test`** — Playwright tests for `dds_mvp.html` over `file://` and HTTP (part-score deal table, validation error). Requires Node, network (Chromium download on first run), and `tags = ["no-sandbox"]`.
- **`//examples/wasm:wasm_examples_system_test`** — runs `calc_dd_table_pbn.js` under Node and checks for `OK` on all three example hands.
- **`//wasm:wasm_examples_system_test`** — runs `calc_dd_table_pbn.js` under Node and checks for `OK` on all three example hands.

The MVP link flags include `-sENVIRONMENT=web,node` so the same `.js` / `.wasm` artifacts work in the browser and in Node system tests.

Expand Down
17 changes: 10 additions & 7 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EXAMPLES_LOCAL_DEFINES = DDS_LOCAL_DEFINES + select({
"//conditions:default": [],
})

# Emscripten link flags for examples built as WASM (see //examples/wasm).
# Emscripten link flags for examples built as WASM (see //wasm).
EXAMPLES_LINKOPTS_WASM = select({
"//:build_wasm": WASM_LINKOPTS,
"//conditions:default": [],
Expand All @@ -33,7 +33,10 @@ cc_library(
includes = ["."],
copts = EXAMPLES_CPPOPTS,
local_defines = EXAMPLES_LOCAL_DEFINES,
visibility = ["//examples:__subpackages__"],
visibility = [
"//examples:__subpackages__",
"//wasm:__pkg__",
],
deps = [
"//library/src:dds",
"//library/src/api:api_definitions",
Expand Down Expand Up @@ -73,7 +76,7 @@ cc_binary(
copts = EXAMPLES_CPPOPTS,
linkopts = DDS_LINKOPTS + EXAMPLES_LINKOPTS_WASM,
local_defines = EXAMPLES_LOCAL_DEFINES,
visibility = ["//examples/wasm:__pkg__"],
visibility = ["//wasm:__pkg__"],
deps = [
":hands",
"//library/src:dds",
Expand Down Expand Up @@ -139,7 +142,7 @@ cc_binary(
copts = EXAMPLES_CPPOPTS,
linkopts = DDS_LINKOPTS + EXAMPLES_LINKOPTS_WASM,
local_defines = EXAMPLES_LOCAL_DEFINES,
visibility = ["//examples/wasm:__pkg__"],
visibility = ["//wasm:__pkg__"],
deps = [
":hands",
"//library/src:dds",
Expand Down Expand Up @@ -205,7 +208,7 @@ cc_binary(
copts = EXAMPLES_CPPOPTS,
linkopts = DDS_LINKOPTS + EXAMPLES_LINKOPTS_WASM,
local_defines = EXAMPLES_LOCAL_DEFINES,
visibility = ["//examples/wasm:__pkg__"],
visibility = ["//wasm:__pkg__"],
deps = [
":hands",
"//library/src:dds",
Expand Down Expand Up @@ -275,8 +278,8 @@ filegroup(
],
)

# Backward-compatible alias; prefer //examples/wasm:all_examples_wasm.
# Backward-compatible alias; prefer //wasm:all_examples_wasm.
alias(
name = "all_examples_wasm",
actual = "//examples/wasm:all_examples_wasm",
actual = "//wasm:all_examples_wasm",
)
77 changes: 0 additions & 77 deletions examples/wasm/BUILD.bazel

This file was deleted.

78 changes: 77 additions & 1 deletion wasm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# WASM helpers live in //:wasm_compat.bzl (no build targets in this package).
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
load("@rules_python//python:defs.bzl", "py_test")
load("//:CPPVARIABLES.bzl", "DDS_CPPOPTS", "DDS_LOCAL_DEFINES")

wasm_cc_binary(
name = "solve_board_wasm",
cc_target = "//examples:solve_board",
outputs = [
"solve_board.js",
"solve_board.wasm",
],
)

wasm_cc_binary(
name = "analyse_play_bin_wasm",
cc_target = "//examples:AnalysePlayBin",
outputs = [
"AnalysePlayBin.js",
"AnalysePlayBin.wasm",
],
)

wasm_cc_binary(
name = "calc_dd_table_pbn_wasm",
cc_target = "//examples:calc_dd_table_pbn",
outputs = [
"calc_dd_table_pbn.js",
"calc_dd_table_pbn.wasm",
],
)

filegroup(
name = "all_examples_wasm",
srcs = [
":analyse_play_bin_wasm",
":calc_dd_table_pbn_wasm",
":solve_board_wasm",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "calc_dd_table_pbn_test",
size = "small",
srcs = ["calc_dd_table_pbn_test.cpp"],
copts = DDS_CPPOPTS,
local_defines = DDS_LOCAL_DEFINES,
deps = [
"//examples:hands",
"//library/src:dds",
"//library/src/api:api_definitions",
"@googletest//:gtest_main",
],
)

py_test(
name = "wasm_examples_system_test",
size = "small",
timeout = "short",
main = "tests/test_wasm_examples_system.py",
srcs = ["tests/test_wasm_examples_system.py"],
data = [":calc_dd_table_pbn_wasm"],
)

test_suite(
name = "all",
tests = [
":calc_dd_table_pbn_test",
":wasm_examples_system_test",
],
)

test_suite(
name = "wasm_system_tests",
tests = [":wasm_examples_system_test"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def rlocation(relpath: str) -> Path:
@unittest.skipUnless(shutil.which("node"), "node not found")
class WasmExamplesSystemTest(unittest.TestCase):
def test_calc_dd_table_pbn_wasm(self) -> None:
js = rlocation("examples/wasm/calc_dd_table_pbn.js")
js = rlocation("wasm/calc_dd_table_pbn.js")
proc = subprocess.run(
["node", str(js)],
capture_output=True,
Expand Down
Loading