Add Windows build script
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$PROJECT = "sindri"
|
||||
$COMMIT = git rev-parse --short HEAD
|
||||
$VERSION = "dev-$(Get-Date -Format 'yyyy-MM-dd')-$COMMIT"
|
||||
|
||||
$OPTION = $args[0]
|
||||
if ($args) { $args = $args[1..($args.Length - 1)] } else { $args = @() }
|
||||
|
||||
# ------------------------------------------
|
||||
|
||||
# Setup compiled wgpu binary
|
||||
& (Join-Path $PSScriptRoot "scripts\wgpu-init.ps1")
|
||||
|
||||
# ------------------------------------------
|
||||
# Game compile
|
||||
|
||||
New-Item -ItemType Directory -Force -Path build | Out-Null
|
||||
|
||||
# Game.dll
|
||||
odin build game/ -show-timings `
|
||||
-collection:sindri=src `
|
||||
-build-mode:dynamic `
|
||||
-out:build/game_tmp.dll -microarch:native "-define:VERSION=$VERSION-debug" -debug @args
|
||||
|
||||
# Need to use a temp file on Windows because it first writes an empty file,
|
||||
# which the engine will load before it is actually fully written.
|
||||
if (-not (Test-Path "build/game_tmp.dll")) {
|
||||
Write-Error "error: build produced no game lib.dll"
|
||||
exit 1
|
||||
}
|
||||
Move-Item -Force "build/game_tmp.dll" "build/game.dll"
|
||||
|
||||
# ------------------------------------------
|
||||
# Engine compile
|
||||
|
||||
# If the executable is already running, then don't try to build and start it.
|
||||
$proc = Get-Process -Name $PROJECT -ErrorAction SilentlyContinue
|
||||
if ($proc) {
|
||||
Write-Output "Hot reloading..."
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($OPTION -eq "debug") {
|
||||
odin build src/ -show-timings `
|
||||
-collection:sindri=src `
|
||||
-collection:gram=vendor/gram/src `
|
||||
-collection:wgpu=vendor `
|
||||
-out:build/$PROJECT.exe -microarch:native -use-separate-modules "-define:VERSION=$VERSION-debug" -debug @args
|
||||
exit 0
|
||||
}
|
||||
|
||||
odin build src/ -show-timings `
|
||||
-collection:sindri=src `
|
||||
-collection:gram=vendor/gram/src `
|
||||
-collection:wgpu=vendor `
|
||||
-out:build/$PROJECT.exe -microarch:native -o:speed "-define:VERSION=$VERSION" @args
|
||||
@@ -0,0 +1,100 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$VENDOR_DIR = Join-Path $PSScriptRoot "..\vendor" | Resolve-Path
|
||||
|
||||
# ------------------------------------------
|
||||
# Platform detection (target dir name, only used for the up-to-date check)
|
||||
|
||||
# Windows PowerShell 5.1 doesn't define $IsWindows/$IsMacOS/$IsLinux
|
||||
if (-not (Test-Path variable:IsWindows)) { $IsWindows = $env:OS -eq "Windows_NT" }
|
||||
if (-not (Test-Path variable:IsMacOS)) { $IsMacOS = $false }
|
||||
if (-not (Test-Path variable:IsLinux)) { $IsLinux = $false }
|
||||
|
||||
if ($IsWindows) {
|
||||
$os = "windows"
|
||||
$extra = "-msvc"
|
||||
} elseif ($IsMacOS) {
|
||||
$os = "macos"
|
||||
$extra = ""
|
||||
} elseif ($IsLinux) {
|
||||
$os = "linux"
|
||||
$extra = ""
|
||||
} else {
|
||||
Write-Error "wgpu setup: unsupported OS"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$procArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
|
||||
$arch = if ($procArch -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "aarch64" } else { "x86_64" }
|
||||
|
||||
$odinRoot = (odin root).Trim()
|
||||
$name = "wgpu-$os-$arch$extra-release"
|
||||
$target = Join-Path $VENDOR_DIR "wgpu\lib\$name"
|
||||
|
||||
# ------------------------------------------
|
||||
# WGPU version detection
|
||||
|
||||
if ($args.Count -gt 0 -and $args[0]) {
|
||||
$WGPU_VERSION = $args[0]
|
||||
} else {
|
||||
$odinTypes = Join-Path $odinRoot "vendor\wgpu\wgpu_native_types.odin"
|
||||
$typesContent = Get-Content $odinTypes -Raw
|
||||
if ($typesContent -match 'BINDINGS_VERSION_STRING :: "([^"]*)"') {
|
||||
$WGPU_VERSION = "v" + $Matches[1]
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $WGPU_VERSION -or $WGPU_VERSION -eq "v") {
|
||||
Write-Error "wgpu setup: could not detect the wgpu-native version"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Detect the version of the vendored wgpu bindings
|
||||
$currentTypes = Join-Path $VENDOR_DIR "wgpu\wgpu_native_types.odin"
|
||||
$current = $null
|
||||
if (Test-Path $currentTypes) {
|
||||
$cur = Get-Content $currentTypes -Raw
|
||||
if ($cur -match 'BINDINGS_VERSION_STRING :: "([^"]*)"') {
|
||||
$current = "v" + $Matches[1]
|
||||
}
|
||||
}
|
||||
|
||||
# Check if the vendored wgpu is already up to date
|
||||
if ($current -eq $WGPU_VERSION -and (Test-Path $target)) {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# ------------------------------------------
|
||||
# Copy vendor/wgpu
|
||||
|
||||
# Remove any stale copy
|
||||
if (Test-Path (Join-Path $VENDOR_DIR "wgpu")) {
|
||||
Remove-Item -Recurse -Force (Join-Path $VENDOR_DIR "wgpu")
|
||||
}
|
||||
|
||||
# Copy wgpu
|
||||
$wgpuPath = Join-Path $odinRoot "vendor\wgpu"
|
||||
Copy-Item -Recurse $wgpuPath $VENDOR_DIR
|
||||
|
||||
# Point imports at the copied vendor wgpu package
|
||||
Get-ChildItem -Path (Join-Path $VENDOR_DIR "wgpu") -Recurse -Filter *.odin | ForEach-Object {
|
||||
(Get-Content $_.FullName -Raw) -replace '"vendor:wgpu"', '"wgpu:wgpu"' | Set-Content $_.FullName -NoNewline
|
||||
}
|
||||
|
||||
# ------------------------------------------
|
||||
# Download
|
||||
|
||||
$assetBase = "https://github.com/gfx-rs/wgpu-native/releases/download/$WGPU_VERSION"
|
||||
|
||||
if (-not (Test-Path $target)) {
|
||||
$url = "$assetBase/$name.zip"
|
||||
Write-Output "wgpu setup: downloading $url"
|
||||
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
|
||||
New-Item -ItemType Directory -Path $tmp | Out-Null
|
||||
try {
|
||||
Invoke-WebRequest -MaximumRedirection 5 -Uri $url -OutFile (Join-Path $tmp "wgpu.zip")
|
||||
Expand-Archive -Force -Path (Join-Path $tmp "wgpu.zip") -DestinationPath $target
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force $tmp
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user