81 lines
2.6 KiB
PowerShell
81 lines
2.6 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
|
||
|
|
|
||
|
|
# Configure WASM preset
|
||
|
|
Write-Host "Configuring CMake WASM preset..." -ForegroundColor Cyan
|
||
|
|
cmake --preset wasm
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
Write-Error "CMake configuration failed."
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
|
||
|
|
# Build WASM preset
|
||
|
|
Write-Host "Building WASM targets..." -ForegroundColor Cyan
|
||
|
|
cmake --build --preset wasm
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
Write-Error "WASM build failed."
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
|
||
|
|
# Run WASM smoke tests
|
||
|
|
Write-Host "Running WASM smoke tests..." -ForegroundColor Cyan
|
||
|
|
node wasm/pdfengine.test.mjs
|
||
|
|
if ($LASTEXITCODE -ne 0) {
|
||
|
|
Write-Error "WASM smoke tests failed."
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
|
||
|
|
# Copy built targets to frontend public folder
|
||
|
|
$WasmBinDir = Join-Path $ProjectRoot "out\build\wasm\bin"
|
||
|
|
$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
|