summaryrefslogtreecommitdiff
path: root/scripts/project_init.sh
blob: 953e5e57a1c6913683546f6543d41f8ce3ad5f2b (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# Fetch minimal third-party dependencies

set -e

echo "Initializing demo64k dependencies..."

mkdir -p third_party

if [ ! -f third_party/stb_image_write.h ]; then
  echo "Fetching stb_image_write.h..."
  curl -L https://raw.githubusercontent.com/nothings/stb/master/stb_image_write.h \
    -o third_party/stb_image_write.h
else
  echo "stb_image_write.h already present."
fi

if [ ! -f third_party/miniaudio.h ]; then
  echo "Fetching miniaudio.h..."
  curl -L https://raw.githubusercontent.com/mackron/miniaudio/master/miniaudio.h     -o third_party/miniaudio.h
else
  echo "miniaudio.h already present."
fi

# glfw3webgpu (helper for GLFW + WebGPU)
mkdir -p third_party/glfw3webgpu
if [ ! -f third_party/glfw3webgpu/glfw3webgpu.h ]; then
  echo "Fetching glfw3webgpu..."
  curl -L https://raw.githubusercontent.com/eliemichel/glfw3webgpu/main/glfw3webgpu.h -o third_party/glfw3webgpu/glfw3webgpu.h
  curl -L https://raw.githubusercontent.com/eliemichel/glfw3webgpu/main/glfw3webgpu.c -o third_party/glfw3webgpu/glfw3webgpu.c
else
  echo "glfw3webgpu already present."
fi

# Platform-specific system dependencies
if command -v brew >/dev/null 2>&1; then
  # macOS
  for pkg in wgpu-native glfw; do
    if ! brew list "$pkg" >/dev/null 2>&1; then
      echo "Installing $pkg via brew..."
      brew install "$pkg"
    else
      echo "$pkg found (via brew)."
    fi
  done
elif command -v apt-get >/dev/null 2>&1; then
  # Linux / WSL
  echo "Installing Linux build dependencies..."
  sudo apt-get update -qq
  sudo apt-get install -y \
    build-essential cmake git python3 \
    libglfw3-dev libxinerama-dev libxcursor-dev libxi-dev libxrandr-dev

  if [ ! -f /usr/local/lib/libwgpu_native.so ]; then
    echo "wgpu-native not found. Fetching prebuilt release..."
    WGPU_VER="v0.19.4.1"
    curl -L -o /tmp/wgpu_linux.zip \
      "https://github.com/gfx-rs/wgpu-native/releases/download/${WGPU_VER}/wgpu-linux-x86_64-release.zip"
    mkdir -p /tmp/wgpu_tmp
    unzip -q /tmp/wgpu_linux.zip -d /tmp/wgpu_tmp
    sudo cp /tmp/wgpu_tmp/libwgpu_native.so /usr/local/lib/
    sudo cp /tmp/wgpu_tmp/wgpu.h /tmp/wgpu_tmp/webgpu.h /usr/local/include/
    sudo ldconfig
    rm -rf /tmp/wgpu_linux.zip /tmp/wgpu_tmp
    echo "wgpu-native installed."
  else
    echo "wgpu-native found."
  fi

  # Windows cross-compilation toolchain (optional)
  if ! command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
    echo ""
    echo "Note: mingw-w64 not found (needed for Windows cross-compile)."
    echo "  sudo apt-get install -y mingw-w64 && ./scripts/fetch_win_deps.sh"
  else
    echo "mingw-w64 found."
  fi
else
  echo "Warning: Neither Homebrew nor apt-get found."
  echo "See doc/HOWTO.md for manual installation instructions."
fi

echo "Done."