nmrugg / stockfish.js

The Stockfish chess engine in Javascript
GNU General Public License v3.0
906 stars 129 forks source link

MacOS build error #82

Open samuraitruong opened 1 year ago

samuraitruong commented 1 year ago

The build script seem does not work on MACOS. same script works fine on ubuntu


/Library/Developer/CommandLineTools/usr/bin/make ARCH=wasm COMP=em++ all
em++ -D__EMSCRIPTEN_PTHREADS__ -DCHESSCOM -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_POPCNT  -DUSE_WASM_SIMD -DUSE_WASM_SIMD_POST_MVP -msimd128 -DNNUE_EMBEDDING_OFF -mmacosx-version-min=10.14 -arch wasm -DUSE_PTHREADS -DNDEBUG -O3 -mdynamic-no-pic -fexperimental-new-pass-manager -DIS_64BIT -DNO_PREFETCH -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DGIT_SHA=5bb15a12 -DGIT_DATE=20230908 -flto=full   -c -o benchmark.o benchmark.cpp
em++ -D__EMSCRIPTEN_PTHREADS__ -DCHESSCOM -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_POPCNT  -DUSE_WASM_SIMD -DUSE_WASM_SIMD_POST_MVP -msimd128 -DNNUE_EMBEDDING_OFF -mmacosx-version-min=10.14 -arch wasm -DUSE_PTHREADS -DNDEBUG -O3 -mdynamic-no-pic -fexperimental-new-pass-manager -DIS_64BIT -DNO_PREFETCH -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DGIT_SHA=5bb15a12 -DGIT_DATE=20230908 -flto=full   -c -o bitbase.o bitbase.cpp
em++ -D__EMSCRIPTEN_PTHREADS__ -DCHESSCOM -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_POPCNT  -DUSE_WASM_SIMD -DUSE_WASM_SIMD_POST_MVP -msimd128 -DNNUE_EMBEDDING_OFF -mmacosx-version-min=10.14 -arch wasm -DUSE_PTHREADS -DNDEBUG -O3 -mdynamic-no-pic -fexperimental-new-pass-manager -DIS_64BIT -DNO_PREFETCH -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DGIT_SHA=5bb15a12 -DGIT_DATE=20230908 -flto=full   -c -o bitboard.o bitboard.cpp
em++ -D__EMSCRIPTEN_PTHREADS__ -DCHESSCOM -Wall -Wcast-qual -fno-exceptions -std=c++17 -DUSE_POPCNT  -DUSE_WASM_SIMD -DUSE_WASM_SIMD_POST_MVP -msimd128 -DNNUE_EMBEDDING_OFF -mmacosx-version-min=10.14 -arch wasm -DUSE_PTHREADS -DNDEBUG -O3 -mdynamic-no-pic -fexperimental-new-pass-manager -DIS_64BIT -DNO_PREFETCH -DUSE_SSE41 -msse4.1 -DUSE_SSSE3 -mssse3 -DUSE_SSE2 -msse2 -DGIT_SHA=5bb15a12 -DGIT_DATE=20230908 -flto=full   -c -o endgame.o endgame.cpp
em++: error: wasm: No such file or directory ("wasm" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [benchmark.o] Error 1
make[1]: *** Waiting for unfinished jobs....
em++: error: wasm: No such file or directory ("wasm" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [bitbase.o] Error 1
em++: error: wasm: No such file or directory ("wasm" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [bitboard.o] Error 1
em++: error: wasm: No such file or directory ("wasm" was expected to be an input file, based on the commandline arguments provided)
make[1]: *** [endgame.o] Error 1
make: *** [build] Error 2
samuraitruong commented 1 year ago

You can go on my forked, I added docker file to run the build inside docker as the solution for now

  docker run \
  --rm \
  -v $(pwd):/src \
  -u $(id -u):$(id -g) \
  emscripten/emsdk:2.0.26 \
  ./build.js
zserge commented 11 months ago

I think the fix would be to change the Makefile to use proper options syntax:

--- a/src/Makefile
+++ b/src/Makefile
@@ -475,8 +475,8 @@ ifeq ($(KERNEL),Darwin)
        CXXFLAGS += -mmacosx-version-min=10.14
        LDFLAGS += -mmacosx-version-min=10.14
        ifneq ($(arch),any)
-               CXXFLAGS += -arch $(arch)
-               LDFLAGS += -arch $(arch)
+               CXXFLAGS += -arch=$(arch)
+               LDFLAGS += -arch=$(arch)
        endif
        XCRUN = xcrun
 endif
zserge commented 11 months ago

However the fix above would bring you to the next error, which is CXXFLAGS += -mdynamic-no-pic being an unknown option for WASM architecture. Removing that solves the issue. Not sure how to make a patch to fix the latter properly.

ps2-controller commented 4 months ago

Running into the same issue on mac