summaryrefslogtreecommitdiff
path: root/scripts/build_win.sh
blob: 4b7f576bce113974b86b9e9d9b3cbc53a3dc7167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -e

# 1. Build native tools
echo "Building native tools..."
cmake -S . -B build_native -DDEMO_BUILD_TOOLS=OFF -DDEMO_BUILD_TESTS=OFF
cmake --build build_native --target asset_packer tracker_compiler_host -j8

ASSET_PACKER_PATH=$(pwd)/build_native/asset_packer
TRACKER_COMPILER_PATH=$(pwd)/build_native/tools_host/tracker_compiler_host

echo "Cross-compiling for Windows..."
cmake -S . -B build_win \
    -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-MinGW-w64.cmake \
    -DDEMO_CROSS_COMPILE_WIN32=ON \
    -DDEMO_STRIP_ALL=ON \
    -DASSET_PACKER_PATH=$ASSET_PACKER_PATH \
    -DTRACKER_COMPILER_PATH=$TRACKER_COMPILER_PATH \
    "-DCMAKE_EXE_LINKER_FLAGS=-static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic"

cmake --build build_win -j8

# 3. Copy runtime DLLs to build_win so we can run it
cp third_party/windows/lib/wgpu_native.dll build_win/

# Copy libwinpthread-1.dll (wgpu_native.dll depends on it even when exe statically links it)
WINPTHREAD_DLL=$(x86_64-w64-mingw32-gcc --print-file-name=libwinpthread-1.dll 2>/dev/null)
if [ ! -f "$WINPTHREAD_DLL" ]; then
    WINPTHREAD_DLL=$(find /opt/homebrew /usr /usr/local -path "*x86_64*" -name "libwinpthread-1.dll" 2>/dev/null | head -1)
fi
if [ -f "$WINPTHREAD_DLL" ]; then
    cp "$WINPTHREAD_DLL" build_win/
else
    echo "Warning: libwinpthread-1.dll not found — Wine may fail to run"
fi

# 4. Crunch the binary
./scripts/crunch_win.sh

echo "Build complete. Output: build_win/demo64k.exe"