Change build scripts to Odin via brokkr

This commit is contained in:
Riyyi
2026-09-28 20:50:59 +02:00
parent bf668d6177
commit 9ead998a3b
11 changed files with 661 additions and 331 deletions
+3 -14
View File
@@ -1,18 +1,7 @@
#!/bin/sh
set -eu
SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
git stash push --keep-index --quiet
"$SCRIPT_DIR/../fmt.sh"
if ! git diff --quiet; then
echo "Formatting changed staged files; commit aborted."
git checkout -- "$SCRIPT_DIR/.."
git stash pop --quiet
exit 1
fi
# "$SCRIPT_DIR/../test.sh"
git stash pop --quiet
exec "$SCRIPT_DIR/../build.sh" -pre-commit
-100
View File
@@ -1,100 +0,0 @@
$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
}
}
-100
View File
@@ -1,100 +0,0 @@
#!/bin/sh
SCRIPT_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
VENDOR_DIR="$SCRIPT_DIR/../vendor"
# ------------------------------------------
# Platform detection
# OS detection
case "$(uname -s)" in
Darwin)
os="macos"
;;
Linux)
os="linux"
;;
MINGW* | MSYS* | CYGWIN*)
os="windows"
extra="-msvc"
;;
*)
echo "wgpu setup: unsupported OS '$(uname -s)'" >&2
exit 1
;;
esac
# Arch detection
case "$(uname -m)" in
arm64 | aarch64)
arch="aarch64"
;;
x86_64 | amd64)
arch="x86_64"
;;
*)
echo "wgpu setup: unsupported arch '$(uname -m)'" >&2
exit 1
;;
esac
# Download filename
name="wgpu-${os}-${arch}${extra:-}-release"
# Compiler filename: lib/wgpu-macos-aarch64-release/lib/libwgpu_native.a
target="$VENDOR_DIR/wgpu/lib/$name"
# ------------------------------------------
# WGPU version detection
# Detect the wgpu-native version the bundled bindings expect, can be overridden
if [ "$1" != "" ]; then
WGPU_VERSION="$1"
else
WGPU_VERSION="v$(sed -n 's/.*BINDINGS_VERSION_STRING :: "\([^"]*\)".*/\1/p' "$(odin root)/vendor/wgpu/wgpu_native_types.odin")"
fi
if [ "$WGPU_VERSION" = "v" ]; then
echo "wgpu setup: could not detect the wgpu-native version" >&2
exit 1
fi
# Detect the version of the vendored wgpu bindings
current="v$(sed -n 's/.*BINDINGS_VERSION_STRING :: "\([^"]*\)".*/\1/p' "$VENDOR_DIR/wgpu/wgpu_native_types.odin" 2> /dev/null)"
# Check if the vendored wgpu is already up to date
if [ "$current" = "$WGPU_VERSION" ] && [ -d "$target" ]; then
exit 0
fi
# ------------------------------------------
# Copy vendor/wgpu
# Remove any stale copy
rm -rf "$VENDOR_DIR/wgpu"
# Copy wgpu
wgpu_path="$(odin root)/vendor/wgpu"
cp -r "$wgpu_path" "$VENDOR_DIR"
chmod -R +w "$VENDOR_DIR/wgpu"
# Point imports at the copied vendor wgpu package
grep -rl '"vendor:wgpu"' "$VENDOR_DIR/wgpu" --include='*.odin' |
while IFS= read -r file; do
sed 's|"vendor:wgpu"|"wgpu:wgpu"|g' "$file" >"$file.tmp" && mv "$file.tmp" "$file"
done
# ------------------------------------------
# Download
ASSET_BASE="https://github.com/gfx-rs/wgpu-native/releases/download/${WGPU_VERSION}"
# Download
if [ ! -d "$target" ]; then
url="${ASSET_BASE}/${name}.zip"
echo "wgpu setup: downloading $url"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
curl -fL --retry 3 -o "$tmp/wgpu.zip" "$url"
unzip -o -q "$tmp/wgpu.zip" -d "$target"
fi