BlueGit

ict rusty-teams

Files

rusty-teams / scripts / fxc-wsl.sh

fxc-wsl.sh

fxc-wsl.sh 1.5 KiB Download Raw
1#!/usr/bin/env bash
2# fxc.exe stand-in for WSL: translates paths, runs fxc-shim.ps1 on Windows. Point GPUI_FXC_PATH here.
3set -euo pipefail
4shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
6# WSL interop calls time out under load ("UtilAcceptVsock: accept4 failed 110"): retry each one.
7interop() {
8 local output attempt
9 for attempt in 1 2 3; do
10 if output="$("$@" 2>&1 | tr -d '\0')"; then
11 printf '%s' "$output"
12 return 0
13 fi
14 sleep "$attempt"
15 done
16 printf 'fxc-wsl: %s failed 3 times:\n%s\n' "$1" "$output" >&2
17 return 1
18}
19# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
20windowsProfile="$(cd /mnt/c && interop /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" | tr -d '\r')"
21stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
22trap 'rm -rf "$stageDir"' EXIT
23translatedArgs=(); headerOut=""
24while (($#)); do
25 case "$1" in
26 /T|/E|/Vn) translatedArgs+=("$1" "$2"); shift 2 ;;
27 /Fh) headerOut="$2"; translatedArgs+=("$1" "$(wslpath -w "$stageDir/out.h")"); shift 2 ;;
28 /O3) translatedArgs+=("$1"); shift ;;
29 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
30 esac
31done
32interop "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" >/dev/null
33cp "$stageDir/out.h" "$headerOut"