Good Evening,
Hoping this thread can act as a resource for others trying to build wasm builds using emscripten for C/C++ engines. If anyone has any pointers I would appreciate any tips. While trying to create a wasm build of Integral it seems there are two major hurdles to overcome.
First is the simd issue. The build will essentially be the equivalent of popcnt version. Emscripten does have it's own simd128 extension to partially overcome this.
Second is the lack of .inc support. Now adays most engines embed their neural networks in this fashion. One workaround I'm trying is to use "xxd -i nnue.bin > nnue-wasm.h" though I've not been succesful.
Any help is greatly appreciated. I'm learning by reviewing the stockfish-wasm project on github.
-Josh
Creating WASM Builds of Engines
Moderator: Ras
-
jshriver
- Posts: 1368
- Joined: Wed Mar 08, 2006 9:41 pm
- Location: Morgantown, WV, USA
-
AndrewGrant
- Posts: 1963
- Joined: Tue Apr 19, 2016 6:08 am
- Location: U.S.A
- Full name: Andrew Grant
Re: Creating WASM Builds of Engines
Here is an example to embed, from a python-based make system.jshriver wrote: ↑Sun Dec 21, 2025 7:54 am Good Evening,
Hoping this thread can act as a resource for others trying to build wasm builds using emscripten for C/C++ engines. If anyone has any pointers I would appreciate any tips. While trying to create a wasm build of Integral it seems there are two major hurdles to overcome.
First is the simd issue. The build will essentially be the equivalent of popcnt version. Emscripten does have it's own simd128 extension to partially overcome this.
Second is the lack of .inc support. Now adays most engines embed their neural networks in this fashion. One workaround I'm trying is to use "xxd -i nnue.bin > nnue-wasm.h" though I've not been succesful.
Any help is greatly appreciated. I'm learning by reviewing the stockfish-wasm project on github.
-Josh
Code: Select all
def embed_for_wasm(self):
print ('Embedding %s into embedded_network.h' % self.name)
with open(self.name, 'rb') as fin:
data = fin.read()
output = ''
for i, byte in enumerate(data):
output += '\\x' + format(byte, '02x')
if (i + 1) % 24 == 0: output += "\\\n"
with open('embedded_network.h', 'w') as fout:
fout.write('extern const unsigned char gIncWeightsData[] = "\\\n%s";\\\n' % output)