#!/usr/bin/env pwsh # https://docs.sheetjs.com/docs/demos/engines/duktape#rust-demo $oldDir = Get-Location $tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-duk-rs" if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force } New-Item -ItemType Directory -Path $tempDir | Out-Null Set-Location -Path $tempDir cargo new sheetjs-duk-rs Set-Location -Path "sheetjs-duk-rs" $version = "0.20.3" Invoke-WebRequest -Uri "https://cdn.sheetjs.com/xlsx-$version/package/dist/shim.min.js" -OutFile "src\shim.min.js" Invoke-WebRequest -Uri "https://cdn.sheetjs.com/xlsx-$version/package/dist/xlsx.full.min.js" -OutFile "src\xlsx.full.min.js" Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.numbers" -OutFile "pres.numbers" Invoke-WebRequest -Uri "https://docs.sheetjs.com/duk/main.rs" -OutFile "src\main.rs" cargo add ducc base64 # On Windows ARM, ducc-sys fails to compile Duktape from source (intptr type detection issue). # Use x64 Rust toolchain through Windows ARM x64 emulation (similar to Bun's approach). $isWindowsArm = $env:PROCESSOR_ARCHITECTURE -eq "ARM64" if ($isWindowsArm) { # Install x64 toolchain with --force-non-host to allow cross-compilation rustup toolchain install stable-x86_64-pc-windows-msvc --force-non-host rustup default stable-x86_64-pc-windows-msvc --force-non-host cargo run -- pres.numbers rustup default stable } else { cargo run -- pres.numbers } npx -y xlsx-cli sheetjsw.xlsb Set-Location $oldDir Remove-Item -Path $tempDir -Recurse -Force