Skip to content

Commit

Permalink
remove unused targets & glue
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Jan 12, 2025
1 parent a947935 commit 246e840
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 367 deletions.
2 changes: 1 addition & 1 deletion build-with-docker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

docker run --rm -u $(id -u):$(id -g) -v "$PWD":/lsfw -w /lsfw emscripten/emsdk:3.1.65 sh -c 'python3 build.py "$@"' -- "$@"
docker run --rm -u $(id -u):$(id -g) -v "$PWD":/lsfw -w /lsfw emscripten/emsdk:3.1.74 sh -c 'python3 build.py "$@"' -- "$@"
24 changes: 7 additions & 17 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@

MAJOR = 3
MINOR = 1
PATCH = 65

# compatiblity modes:
# - sfhce: VERSION_0
# - fsf14, sf16-7, sf16-40: VERSION_1
# - sf16.1: VERSION_2
# - sf17-79: VERSION_3
PATCH = 74

targets = {
"fsf14": {"url": fairy_stockfish_repo, "commit": "a621470", "cxx_flags": "", "version": "version_1"},
"sf16-7": {"url": stockfish_repo, "commit": "68e1e9b", "cxx_flags": "", "version": "version_1"},
"sf16-40": {"url": stockfish_repo, "commit": "68e1e9b", "cxx_flags": "", "version": "version_1"},
"sf161-70": {"url": stockfish_repo, "commit": "e67cc97", "cxx_flags": "", "version": "version_2"}, # 16.1
"sf17-79": {"url": stockfish_repo, "commit": "e0bfc4b", "cxx_flags": "", "version": "version_3"}, # 17
"sfhce": {"url": stockfish_repo, "commit": "9587eee", "version": "version_0"}, # sf classical
"fsf14": {"url": fairy_stockfish_repo, "commit": "a621470", "cxx_flags": ""},
"sf16-7": {"url": stockfish_repo, "commit": "68e1e9b", "cxx_flags": ""},
"sf16-40": {"url": stockfish_repo, "commit": "68e1e9b", "cxx_flags": ""},
"sf17-79": {"url": stockfish_repo, "commit": "e0bfc4b", "cxx_flags": ""}, # 17
}

script_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -43,8 +35,6 @@

def makefile(target, sources, flags, link_flags):
flags = " ".join([flags.strip(), targets[target].get("cxx_flags", "").strip()])
version = targets[target].get("version")
glue_filename = f"glue_{version}"
# DO NOT replace tabs with spaces
# fmt: off
return f"""
Expand All @@ -63,15 +53,15 @@ def makefile(target, sources, flags, link_flags):
-sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sEXIT_RUNTIME -Wno-pthreads-mem-growth
SRCS = {sources}
OBJS = $(addprefix src/, $(SRCS:.cpp=.o)) src/{glue_filename}.o
OBJS = $(addprefix src/, $(SRCS:.cpp=.o)) src/glue.o
$(EXE).js: $(OBJS)
$(CXX) $(CXX_FLAGS) $(LD_FLAGS) $(OBJS) -o $(EXE).js
%.o: %.cpp
$(CXX) $(CXX_FLAGS) -c $< -o $@
src/{glue_filename}.o: ../../src/{glue_filename}.cpp
src/glue.o: ../../src/glue.cpp
$(CXX) $(CXX_FLAGS) -c $< -o $@
"""
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"name": "lila-stockfish-web",
"version": "0.0.7",
"version": "0.0.8",
"author": "T-bone Duplexus",
"license": "AGPL-3.0-or-later",
"type": "module",
"types": "stockfishWeb.d.ts",
"files": [
"sfhce.js",
"sfhce.wasm",
"sf16-7.js",
"sf16-7.wasm",
"sf17-79.js",
Expand Down
90 changes: 0 additions & 90 deletions patches/sf161-70.patch

This file was deleted.

81 changes: 0 additions & 81 deletions patches/sfhce.patch

This file was deleted.

63 changes: 63 additions & 0 deletions src/glue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "glue.hpp"

#include "evaluate.h"
#include "syzygy/tbprobe.h"
#include "uci.h"
#include "nnue/nnue_architecture.h"

EMSCRIPTEN_KEEPALIVE std::string js_getline() {
auto cmd = inQ.pop();
if (cmd.type == cmd.UCI)
return cmd.uci;
else if (cmd.type == cmd.NNUE && cmd.ptr) {
return load_nnue_cmd(cmd);
}
return "";
}

#if __has_include("nnue/evaluate_nnue.h") // single nnue
# include "nnue/evaluate_nnue.h"

const std::string load_nnue_cmd(Command& cmd) {
std::istream in(&cmd);
if (Stockfish::Eval::NNUE::load_eval("", in)) return "setoption name Use NNUE value true";
else std::cerr << "BAD_NNUE" << std::endl;
return "setoption name Use NNUE value false";
}

const char* get_nnue_name(int index) {
return EvalFileDefaultName;
}

#else // big/little nnue
extern Stockfish::UCIEngine* uci_global;

const std::string load_nnue_cmd(Command& cmd) {
std::istream in(&cmd);
if (cmd.index == 0) uci_global->engine.load_big_network(in);
else if (cmd.index == 1) uci_global->engine.load_small_network(in);
else std::cerr << "BAD_NNUE " << cmd.index << std::endl;
return "";
}

const char* get_nnue_name(int index) {
return index == 1 ? EvalFileDefaultNameSmall : EvalFileDefaultNameBig;
}

namespace Stockfish::Tablebases {
Config rank_root_moves(const OptionsMap& o, Position& p, Search::RootMoves& rM, bool rankDTZ) {
return Config();
}
}
#endif

// stubs for tbprobe.cpp (so we don't need -sALLOW_UNIMPLEMENTED_SYSCALLS)
namespace Stockfish::Tablebases {
int MaxCardinality = 0;
void init(const std::string& paths) {}
WDLScore probe_wdl(Position& p, ProbeState* r) { return WDLDraw; }
int probe_dtz(Position& p, ProbeState* r) { return 0; }

bool root_probe(Position& p, Search::RootMoves& rM) { return false; }
bool root_probe_wdl(Position& p, Search::RootMoves& rM) { return false; }
} // namespace Stockfish::Tablebases
17 changes: 9 additions & 8 deletions src/glue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ struct {
}
} inQ;

const char* getRecommendedNnueName(int index);
const char* get_nnue_name(int index);
const std::string load_nnue_cmd(Command& cmd);

EMSCRIPTEN_KEEPALIVE std::string js_getline();

extern "C" {
EMSCRIPTEN_KEEPALIVE void uci(const char* utf8) { inQ.push(Command(utf8)); }
EMSCRIPTEN_KEEPALIVE void uci(const char* utf8) { inQ.push(Command(utf8)); }

EMSCRIPTEN_KEEPALIVE void setNnueBuffer(char* buf, size_t sz, int index) {
inQ.push(Command(buf, sz, index));
}
EMSCRIPTEN_KEEPALIVE void setNnueBuffer(char* buf, size_t sz, int index) {
inQ.push(Command(buf, sz, index));
}

EMSCRIPTEN_KEEPALIVE const char* getRecommendedNnue(int index) {
return getRecommendedNnueName(index);
}
EMSCRIPTEN_KEEPALIVE const char* getRecommendedNnue(int index) {
return get_nnue_name(index);
}
}
33 changes: 0 additions & 33 deletions src/glue_version_0.cpp

This file was deleted.

Loading

0 comments on commit 246e840

Please sign in to comment.