Fix: Persist WSL compilation artifacts in host target_linux to prevent WSL /tmp evaporation

This commit is contained in:
ospab 2026-05-14 22:22:04 +03:00
parent cbb4486514
commit bbe5a88f36
1 changed files with 17 additions and 13 deletions

View File

@ -15,9 +15,9 @@ $LinuxDist = Join-Path $DistDir "linux"
New-Item -ItemType Directory -Force -Path $WinDist | Out-Null New-Item -ItemType Directory -Force -Path $WinDist | Out-Null
New-Item -ItemType Directory -Force -Path $LinuxDist | Out-Null New-Item -ItemType Directory -Force -Path $LinuxDist | Out-Null
# Clear old binaries to prevent false positive checks if copy fails # Strictly purge old distribution binaries to prevent caching false positives
Remove-Item -Path (Join-Path $WinDist "ostp.exe") -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path (Join-Path $WinDist "ostp.exe") -Force -ErrorAction SilentlyContinue | Out-Null
Remove-Item -Path (Join-Path $LinuxDist "ostp") -ErrorAction SilentlyContinue | Out-Null Remove-Item -Path (Join-Path $LinuxDist "ostp") -Force -ErrorAction SilentlyContinue | Out-Null
Write-Output "Building Windows Binary natively" Write-Output "Building Windows Binary natively"
$TempTarget = Join-Path $env:TEMP "ostp_target_build" $TempTarget = Join-Path $env:TEMP "ostp_target_build"
@ -46,8 +46,16 @@ Remove-Item Env:\CARGO_TARGET_DIR -ErrorAction SilentlyContinue | Out-Null
Write-Output "Building Linux binary via WSL" Write-Output "Building Linux binary via WSL"
if (Get-Command wsl -ErrorAction SilentlyContinue) { if (Get-Command wsl -ErrorAction SilentlyContinue) {
# Anchor build target inside host workspace to persist artifacts across WSL session life-cycles
$LinuxBuildDir = Join-Path $ProjectRoot "target_linux"
New-Item -ItemType Directory -Force -Path $LinuxBuildDir | Out-Null
$LinuxBuildUnix = $LinuxBuildDir.Replace("\", "/")
$WslBuildDir = & wsl wslpath -u $LinuxBuildUnix
& wsl rustup target add x86_64-unknown-linux-musl & wsl rustup target add x86_64-unknown-linux-musl
& wsl env CC_x86_64_unknown_linux_musl=gcc CARGO_TARGET_DIR=/tmp/ostp_linux_build cargo build --release --target x86_64-unknown-linux-musl --bin ostp # Build directly into the host-mapped target_linux directory
& wsl env CC_x86_64_unknown_linux_musl=gcc CARGO_TARGET_DIR=$WslBuildDir cargo build --release --target x86_64-unknown-linux-musl --bin ostp
if ($LASTEXITCODE -ne 0) { if ($LASTEXITCODE -ne 0) {
Write-Output "❌ Linux build failed" Write-Output "❌ Linux build failed"
@ -55,18 +63,14 @@ if (Get-Command wsl -ErrorAction SilentlyContinue) {
exit 1 exit 1
} }
# Fix Windows backslashes for WSL path translator passing # Native copy of the artifact entirely on host side (completely avoids wsl cp pitfalls)
$LinuxDistUnix = $LinuxDist.Replace("\", "/") $LinuxTargetBin = Join-Path $LinuxBuildDir "x86_64-unknown-linux-musl\release\ostp"
# Determine WSL translation of the destination folder
$WslLinuxDist = & wsl wslpath -u $LinuxDistUnix
# Copy from WSL temp directory into the actual host mapped linux dist
& wsl cp /tmp/ostp_linux_build/x86_64-unknown-linux-musl/release/ostp $WslLinuxDist/ostp
$LinuxBin = Join-Path $LinuxDist "ostp" if (Test-Path $LinuxTargetBin) {
if (Test-Path $LinuxBin) { Copy-Item -Path $LinuxTargetBin -Destination $LinuxDist -Force
Write-Output "✔ Linux binary successfully copied to dist/linux/ostp" Write-Output "✔ Linux binary successfully copied to dist/linux/ostp"
} else { } else {
Write-Output "Linux binary copy failed" Write-Output "Compiled Linux binary was not found at target: $LinuxTargetBin"
Pop-Location Pop-Location
exit 1 exit 1
} }