summaryrefslogtreecommitdiff
path: root/scripts/build_win.sh
blob: da7574853dc2ddfbe58119f93dd7bd868910ea5e (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
41
42
43
44
45
46
47
48
49
#!/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

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 MinGW DLLs (pthread, etc.)
echo "Copying MinGW DLLs..."
if [[ "$(uname)" == "Darwin" ]]; then
    MINGW_SEARCH_ROOTS="/opt/homebrew"
else
    # Linux / WSL: mingw-w64 installed via apt
    MINGW_SEARCH_ROOTS="/usr/x86_64-w64-mingw32 /usr/lib/gcc/x86_64-w64-mingw32"
fi
COPIED=0
for dll in libwinpthread-1.dll libgcc_s_seh-1.dll libstdc++-6.dll; do
    src=$(find $MINGW_SEARCH_ROOTS -name "$dll" 2>/dev/null | head -n 1)
    if [ -n "$src" ]; then
        cp "$src" build_win/
        echo "  Copied: $dll"
        COPIED=$((COPIED+1))
    fi
done
if [ "$COPIED" -eq 0 ]; then
    echo "Warning: Could not find MinGW DLLs. You might need them to run the exe."
fi

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

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