BlueGit

ict rusty-teams

fix(build): fxc wrapper retries PowerShell calls that fail during busy builds

- Windows release builds failed at random shaders ("Shader compilation failed for X:" with
  empty stderr) while the same fxc call succeeded alone. Retry up to 3 times, print the
  shim output when all attempts fail.
- USERPROFILE CR strip written as tr -d '\r' instead of a raw CR byte that editors lose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-13 · 7 weeks ago

Hash
303afa5586963d283efbe0b219afbd4407be6ba4
Parent
93ff73ee
1 file changed +11 −3
scripts/fxc-wsl.sh +11 −3
@@ -4,7 +4,7 @@ set -euo pipefail
4 4 shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5 5 powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
6 6 # UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
7 windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d ' ')"
7 windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d '\r')"
8 8 stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
9 9 trap 'rm -rf "$stageDir"' EXIT
10 10 translatedArgs=(); headerOut=""
@@ -16,5 +16,13 @@ while (($#)); do
16 16 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
17 17 esac
18 18 done
19 "$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}"
20 cp "$stageDir/out.h" "$headerOut"
19 # PowerShell via WSL interop fails intermittently (empty stderr) during busy builds: retry.
20 for attempt in 1 2 3; do
21 if shimOutput="$("$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" 2>&1)" && [[ -s "$stageDir/out.h" ]]; then
22 cp "$stageDir/out.h" "$headerOut"
23 exit 0
24 fi
25 sleep "$attempt"
26 done
27 printf 'fxc failed after 3 attempts:\n%s\n' "$shimOutput" >&2
28 exit 1
@@ -4,7 +4,7 @@ set -euo pipefail
4shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4shimDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
5powershellExe=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
6# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
6# UNC paths break D3DCompileFromFile includes: stage on the Windows drive.
7windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d ' ')"
7windowsProfile="$(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe /c "echo %USERPROFILE%" 2>/dev/null | tr -d '\r')"
8stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
8stageDir="$(mktemp -d "$(wslpath "$windowsProfile")/AppData/Local/Temp/fxc-stage.XXXXXX")"
9trap 'rm -rf "$stageDir"' EXIT
9trap 'rm -rf "$stageDir"' EXIT
10translatedArgs=(); headerOut=""
10translatedArgs=(); headerOut=""
@@ -16,5 +16,13 @@ while (($#)); do
16 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
16 *) cp "$(dirname "$1")"/*.hlsl "$stageDir/"; translatedArgs+=("$(wslpath -w "$stageDir/$(basename "$1")")"); shift ;;
17 esac
17 esac
18done
18done
19"$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}"
19# PowerShell via WSL interop fails intermittently (empty stderr) during busy builds: retry.
20cp "$stageDir/out.h" "$headerOut"
20for attempt in 1 2 3; do
21 if shimOutput="$("$powershellExe" -NoProfile -ExecutionPolicy Bypass -File "$(wslpath -w "$shimDir/fxc-shim.ps1")" "${translatedArgs[@]}" 2>&1)" && [[ -s "$stageDir/out.h" ]]; then
22 cp "$stageDir/out.h" "$headerOut"
23 exit 0
24 fi
25 sleep "$attempt"
26done
27printf 'fxc failed after 3 attempts:\n%s\n' "$shimOutput" >&2
28exit 1