90 lines
2.9 KiB
PowerShell
90 lines
2.9 KiB
PowerShell
#requires -Version 5.1
|
|
# Build C++ Engine to WebAssembly (WASM) and deploy to Frontend public folder.
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$ProjectRoot = (Resolve-Path (Join-Path $ScriptDir "..")).Path
|
|
|
|
# --- Resolve EMSDK ---
|
|
$emsdk = $env:EMSDK
|
|
if (-not $emsdk) {
|
|
$candidates = @(
|
|
"C:\Users\$env:USERNAME\emsdk",
|
|
"C:\emsdk",
|
|
"C:\src\emsdk",
|
|
"C:\Users\furqa\emsdk"
|
|
)
|
|
foreach ($cand in $candidates) {
|
|
if (Test-Path $cand) {
|
|
$emsdk = $cand
|
|
break
|
|
}
|
|
}
|
|
|
|
if (-not $emsdk) {
|
|
Write-Error "EMSDK environment variable was not set and could not be found at standard locations. Please set the EMSDK environment variable."
|
|
exit 1
|
|
}
|
|
$env:EMSDK = $emsdk
|
|
Write-Host "EMSDK defaulted to: $emsdk" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Load EMSDK environment variables in PowerShell context
|
|
$envScript = Join-Path $emsdk "emsdk_env.ps1"
|
|
if (-not (Test-Path $envScript)) {
|
|
Write-Error "Could not find emsdk_env.ps1 at $emsdk"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Loading Emscripten environment variables..." -ForegroundColor Cyan
|
|
. $envScript
|
|
|
|
# Resolve build directory
|
|
$BuildDir = Join-Path $ProjectRoot "out\build\wasm"
|
|
if ($IsWindows -or $env:OS -eq "Windows_NT") {
|
|
$BuildDir = "C:\Users\$env:USERNAME\pdfeng-build\wasm"
|
|
if (-not (Test-Path $BuildDir)) {
|
|
New-Item -ItemType Directory -Path $BuildDir -Force | Out-Null
|
|
}
|
|
}
|
|
$WasmBinDir = Join-Path $BuildDir "bin"
|
|
|
|
# Configure WASM preset
|
|
Write-Host "Configuring CMake WASM preset in $BuildDir..." -ForegroundColor Cyan
|
|
cmake --preset wasm -B $BuildDir
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "CMake configuration failed."
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
# Build WASM preset
|
|
Write-Host "Building WASM targets..." -ForegroundColor Cyan
|
|
cmake --build $BuildDir
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "WASM build failed."
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
# Run WASM smoke tests
|
|
Write-Host "Running WASM smoke tests..." -ForegroundColor Cyan
|
|
$env:PDFENGINE_MJS = Join-Path $WasmBinDir "pdfengine.mjs"
|
|
node wasm/pdfengine.test.mjs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "WASM smoke tests failed."
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
# Copy built targets to frontend public folder
|
|
$FrontendPublic = Join-Path $ProjectRoot "frontend\public"
|
|
|
|
if (-not (Test-Path $FrontendPublic)) {
|
|
Write-Warning "Frontend public folder not found at $FrontendPublic. Skipping copy."
|
|
} else {
|
|
Write-Host "Copying WASM build artifacts to frontend public folder..." -ForegroundColor Cyan
|
|
Copy-Item -Path (Join-Path $WasmBinDir "pdfengine.mjs") -Destination (Join-Path $FrontendPublic "pdfengine.mjs") -Force
|
|
Copy-Item -Path (Join-Path $WasmBinDir "pdfengine.wasm") -Destination (Join-Path $FrontendPublic "pdfengine.wasm") -Force
|
|
Write-Host "Successfully copied WASM files to $FrontendPublic" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host "Success! WASM built and deployed." -ForegroundColor Green |