Add workflow for ffishjs
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 7 Jan 2021 16:20:34 +0000 (17:20 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 7 Jan 2021 18:33:16 +0000 (19:33 +0100)
- Add Makefile for easier compilation
- Run js unit tests as part of CI
- Increase test timeout to work with unoptimized builds

.github/workflows/ffishjs.yml [new file with mode: 0644]
src/Makefile_js [new file with mode: 0644]
tests/js/README.md
tests/js/package.json

diff --git a/.github/workflows/ffishjs.yml b/.github/workflows/ffishjs.yml
new file mode 100644 (file)
index 0000000..7177f0e
--- /dev/null
@@ -0,0 +1,45 @@
+name: ffishjs
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+env:
+  EM_VERSION: 1.39.16
+  EM_CACHE_FOLDER: 'emsdk-cache'
+
+jobs:
+  test:
+    runs-on: ubuntu-20.04
+
+    strategy:
+      matrix:
+        node-version: [12.x]
+
+    steps:
+      - uses: actions/checkout@v2
+      - name: Setup cache
+        id: cache-system-libraries
+        uses: actions/cache@v2
+        with:
+          path: ${{env.EM_CACHE_FOLDER}}
+          key: emsdk-${{env.EM_VERSION}}-${{ runner.os }}
+      - uses: mymindstorm/setup-emsdk@v7
+        with:
+          version: ${{env.EM_VERSION}}
+          actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
+      - name: Use Node.js ${{ matrix.node-version }}
+        uses: actions/setup-node@v1
+        with:
+          node-version: ${{ matrix.node-version }}
+      - name: Build ffishjs
+        working-directory: src
+        run: make -f Makefile_js build debug=yes optimize=no
+      - name: Install dependencies
+        working-directory: tests/js
+        run: npm install
+      - name: Run unit tests
+        working-directory: tests/js
+        run: npm test
diff --git a/src/Makefile_js b/src/Makefile_js
new file mode 100644 (file)
index 0000000..7e5ff9c
--- /dev/null
@@ -0,0 +1,61 @@
+# ffish.js, a JavaScript chess variant library derived from Fairy-Stockfish
+# Copyright (C) 2020 Fabian Fichter, Johannes Czech
+#
+# ffish.js is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ffish.js is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+EXE = ../tests/js/ffish.js
+
+SRCS = ffishjs.cpp benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp \
+       material.cpp misc.cpp movegen.cpp movepick.cpp pawns.cpp position.cpp psqt.cpp \
+       search.cpp thread.cpp timeman.cpp tt.cpp uci.cpp ucioption.cpp tune.cpp syzygy/tbprobe.cpp \
+       nnue/evaluate_nnue.cpp nnue/features/half_kp.cpp \
+       partner.cpp parser.cpp piece.cpp variant.cpp xboard.cpp
+
+CXX=emcc
+CXXFLAGS += --bind -DNNUE_EMBEDDING_OFF -DNO_THREADS -std=c++17 -Wall
+
+largeboards = yes
+optimize = yes
+debug = no
+
+### Debugging
+ifeq ($(debug),no)
+       CXXFLAGS += -DNDEBUG -s ASSERTIONS=0 -s SAFE_HEAP=0
+else
+       CXXFLAGS += -g -s ASSERTIONS=1 -s SAFE_HEAP=1
+endif
+
+### Optimization
+ifeq ($(optimize),yes)
+       CXXFLAGS += -O3
+endif
+
+# Compile version with support for large board variants
+# Use precomputed magics by default
+ifneq ($(largeboards),no)
+       CXXFLAGS += -DLARGEBOARDS -DPRECOMPUTED_MAGICS -s TOTAL_MEMORY=32MB -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=1GB
+endif
+
+### Compile as ES6/ES2015 module
+ifeq ($(es6),yes)
+       CXXFLAGS += -s ENVIRONMENT='web,worker' -s EXPORT_ES6=1 -s MODULARIZE=1 -s USE_ES6_IMPORT_META=0
+endif
+
+objclean:
+       @rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o
+
+clean: objclean
+
+build:
+       $(CXX) $(CXXFLAGS) $(SRCS) -o $(EXE)
index f938a79..f902362 100644 (file)
@@ -232,53 +232,18 @@ It is built using emscripten/Embind from C++ source code.
 
 
 If you want to disable variants with a board greater than 8x8,
- you can remove the flags `-s TOTAL_MEMORY=67108864 -s
-  ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=2147483648
-   -DLARGEBOARDS -DPRECOMPUTED_MAGICS`.
+ you can add the flag `largeboards=no`.
 
-The pre-compiled wasm binary is built with `-DLARGEBOARDS`.
+The pre-compiled wasm binary is built with `largeboards=yes`.
 
-It is recommended to set `-s ASSERTIONS=1 -s SAFE_HEAP=1` before running tests.
+It is recommended to set `debug=yes` before running tests.
 
 
 ### Compile as standard module
 
 ```bash
-cd Fairy-Stockfish/src
-```
-```bash
-emcc -O3 --bind -DLARGEBOARDS -DPRECOMPUTED_MAGICS -DNNUE_EMBEDDING_OFF -DNO_THREADS \
- -s TOTAL_MEMORY=32MB -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=1GB \
- -s ASSERTIONS=0 -s SAFE_HEAP=0 -std=c++17 -Wall \
- -DNO_THREADS -DLARGEBOARDS -DPRECOMPUTED_MAGICS \
-ffishjs.cpp \
-benchmark.cpp \
-bitbase.cpp \
-bitboard.cpp \
-endgame.cpp \
-evaluate.cpp \
-material.cpp \
-misc.cpp \
-movegen.cpp \
-movepick.cpp \
-parser.cpp \
-partner.cpp \
-pawns.cpp \
-piece.cpp \
-position.cpp \
-psqt.cpp \
-search.cpp \
-thread.cpp \
-timeman.cpp \
-tt.cpp \
-uci.cpp \
-ucioption.cpp \
-variant.cpp \
-xboard.cpp \
-nnue/*.cpp \
-nnue/features/*.cpp \
-syzygy/*.cpp \
--o ../tests/js/ffish.js
+cd src
+make -f Makefile_js build
 ```
 
 ### Compile as ES6/ES2015 module
@@ -287,41 +252,8 @@ Some environments such as [vue-js](https://vuejs.org/) may require the library t
   as a ES6/ES2015 module.
 
 ```bash
-cd Fairy-Stockfish/src
-```
-```bash
-emcc -O3 --bind -DLARGEBOARDS -DPRECOMPUTED_MAGICS -DNNUE_EMBEDDING_OFF -DNO_THREADS \
- -s TOTAL_MEMORY=32MB -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=1GB \
- -s ASSERTIONS=0 -s SAFE_HEAP=0 -std=c++17 -Wall \
- -s ENVIRONMENT='web,worker' -s EXPORT_ES6=1 -s MODULARIZE=1 -s USE_ES6_IMPORT_META=0 \
-ffishjs.cpp \
-benchmark.cpp \
-bitbase.cpp \
-bitboard.cpp \
-endgame.cpp \
-evaluate.cpp \
-material.cpp \
-misc.cpp \
-movegen.cpp \
-movepick.cpp \
-parser.cpp \
-partner.cpp \
-pawns.cpp \
-piece.cpp \
-position.cpp \
-psqt.cpp \
-search.cpp \
-thread.cpp \
-timeman.cpp \
-tt.cpp \
-uci.cpp \
-ucioption.cpp \
-variant.cpp \
-xboard.cpp \
-nnue/*.cpp \
-nnue/features/*.cpp \
-syzygy/*.cpp \
--o ../tests/js/ffish.js
+cd src
+make -f Makefile_js build es6=yes
 ```
 
 Make sure that the wasm file is in the `public` directory.
index 9e44aa0..eb555a8 100644 (file)
@@ -4,7 +4,7 @@
   "description": "A high performance WebAssembly chess variant library based on Fairy-Stockfish",
   "main": "ffish.js",
   "scripts": {
-    "test": "mocha",
+    "test": "mocha --timeout 20000",
     "dev": "node index"
   },
   "author": [