| 1 | #!/usr/bin/env bash |
| 2 | # KVT fork: cross-build target/x86_64-pc-windows-msvc/release/teams.exe in a Linux |
| 3 | # CI container. Wraps upstream's scripts/build-windows.sh (cargo-xwin, patched |
| 4 | # gpui-pre-windows, embedded onnxruntime.dll) and swaps its WSL fxc for |
| 5 | # packaging/kvt/fxc-wine.sh. Keeping upstream's script as is keeps merges small. |
| 6 | # Usage: build-windows.sh [x86_64|aarch64] (default x86_64; fxc.exe stays an x64 tool under wine) |
| 7 | set -euo pipefail |
| 8 | arch="${1:-x86_64}" |
| 9 | case "$arch" in x86_64|aarch64) ;; *) echo "usage: $0 [x86_64|aarch64]" >&2; exit 2 ;; esac |
| 10 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 11 | # Microsoft.Windows.SDK.CPP from nuget.org carries fxc.exe and d3dcompiler_47.dll. |
| 12 | SDK_VERSION="${KVT_WINDOWS_SDK_VERSION:-10.0.28000.2957}" |
| 13 | SDK_SHA256="${KVT_WINDOWS_SDK_SHA256:-f0a200dae58858f418b30dc9e2f52b4188f97eb7837bd4f73074652a01937ddd}" |
| 14 | export FXC_DIR="${FXC_DIR:-$ROOT/target/kvt-fxc/$SDK_VERSION}" |
| 15 | if [[ ! -f "$FXC_DIR/fxc.exe" || ! -f "$FXC_DIR/d3dcompiler_47.dll" ]]; then |
| 16 | mkdir -p "$FXC_DIR" |
| 17 | nupkg="$FXC_DIR/sdk.nupkg" |
| 18 | curl -fsSL --retry 3 -o "$nupkg" \ |
| 19 | "https://api.nuget.org/v3-flatcontainer/microsoft.windows.sdk.cpp/$SDK_VERSION/microsoft.windows.sdk.cpp.$SDK_VERSION.nupkg" |
| 20 | echo "$SDK_SHA256 $nupkg" | sha256sum -c - |
| 21 | unzip -o -q -j "$nupkg" "c/bin/${SDK_VERSION%.*}.0/x64/fxc.exe" "c/bin/${SDK_VERSION%.*}.0/x64/d3dcompiler_47.dll" -d "$FXC_DIR" |
| 22 | rm -f "$nupkg" |
| 23 | fi |
| 24 | script="$(mktemp)" |
| 25 | trap 'rm -f "$script"' EXIT |
| 26 | sed 's#^export GPUI_FXC_PATH=.*#export GPUI_FXC_PATH="$repoRoot/packaging/kvt/fxc-wine.sh"#' \ |
| 27 | "$ROOT/scripts/build-windows.sh" > "$script" |
| 28 | grep -q 'packaging/kvt/fxc-wine.sh' "$script" || { |
| 29 | echo "scripts/build-windows.sh no longer sets GPUI_FXC_PATH; update packaging/kvt/build-windows.sh" >&2 |
| 30 | exit 1 |
| 31 | } |
| 32 | # Upstream's script builds x86_64-pc-windows-msvc; swap the target for ARM64 builds. |
| 33 | sed -i "s#^targetName=.*#targetName=${arch}-pc-windows-msvc#" "$script" |
| 34 | grep -q "^targetName=${arch}-pc-windows-msvc$" "$script" || { echo "scripts/build-windows.sh no longer sets targetName" >&2; exit 1; } |
| 35 | # The copy lives in /tmp; point its repoRoot at this checkout. |
| 36 | sed -i "s#^repoRoot=.*#repoRoot=\"$ROOT\"#" "$script" |
| 37 | export CARGO_TARGET_DIR="$ROOT/target" |
| 38 | bash "$script" "$ROOT/crates/app" teams |