w
This commit is contained in:
parent
03ddaa09f2
commit
caa90775f9
89 changed files with 7126 additions and 0 deletions
50
scripts/build-kernels.ps1
Normal file
50
scripts/build-kernels.ps1
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
param(
|
||||
[string]$ManifestPath = (Join-Path $PSScriptRoot '..\dist\wasm\manifest.json'),
|
||||
[string]$OutputPath = (Join-Path $PSScriptRoot '..\kernels.js')
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$workspace = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..')).Path
|
||||
$output = [System.IO.Path]::GetFullPath($OutputPath)
|
||||
if (-not $output.StartsWith($workspace, [System.StringComparison]::OrdinalIgnoreCase)) { throw 'OutputPath must stay inside the workspace.' }
|
||||
$manifest = Get-Content -LiteralPath $ManifestPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||
$values = @{}
|
||||
foreach ($payload in $manifest.payloads) {
|
||||
$path = Join-Path (Split-Path $ManifestPath) $payload.file
|
||||
$values[$payload.symbol] = [Convert]::ToBase64String([System.IO.File]::ReadAllBytes($path))
|
||||
}
|
||||
foreach ($required in @('WASM_SIMD_B64','WASM_SCALAR_B64','DEEP_SIMD_B64','DEEP_SCALAR_B64','BLA_SIMD_B64','BLA_SCALAR_B64','COLOR_SIMD_B64','COLOR_SCALAR_B64')) {
|
||||
if (-not $values.ContainsKey($required)) { throw "Missing payload: $required" }
|
||||
}
|
||||
$colorDeduplicated = $values.COLOR_SIMD_B64 -eq $values.COLOR_SCALAR_B64
|
||||
$lines = @(
|
||||
"'use strict';"
|
||||
'// Generated from dist/wasm/manifest.json. Run scripts/extract-wasm.ps1 before replacing compatibility inputs.'
|
||||
)
|
||||
if ($colorDeduplicated) { $lines += "const COLOR_B64='$($values.COLOR_SIMD_B64)';" }
|
||||
$lines += @(
|
||||
'globalThis.MANDEL_KERNELS=Object.freeze({'
|
||||
" WASM_SIMD_B64:'$($values.WASM_SIMD_B64)',"
|
||||
" WASM_SCALAR_B64:'$($values.WASM_SCALAR_B64)',"
|
||||
" DEEP_SIMD_B64:'$($values.DEEP_SIMD_B64)',"
|
||||
" DEEP_SCALAR_B64:'$($values.DEEP_SCALAR_B64)',"
|
||||
" BLA_SIMD_B64:'$($values.BLA_SIMD_B64)',"
|
||||
" BLA_SCALAR_B64:'$($values.BLA_SCALAR_B64)',"
|
||||
)
|
||||
if ($colorDeduplicated) {
|
||||
$lines += @(' COLOR_SIMD_B64:COLOR_B64,', ' COLOR_SCALAR_B64:COLOR_B64')
|
||||
} else {
|
||||
$lines += @(" COLOR_SIMD_B64:'$($values.COLOR_SIMD_B64)',", " COLOR_SCALAR_B64:'$($values.COLOR_SCALAR_B64)'")
|
||||
}
|
||||
$lines += @(
|
||||
'});'
|
||||
'globalThis.MANDEL_KERNEL_META=Object.freeze({'
|
||||
)
|
||||
for ($index = 0; $index -lt $manifest.payloads.Count; $index++) {
|
||||
$payload = $manifest.payloads[$index]
|
||||
$comma = if ($index -lt $manifest.payloads.Count - 1) { ',' } else { '' }
|
||||
$lines += " '$($payload.symbol)':'$($payload.sha256)'$comma"
|
||||
}
|
||||
$lines += '});'
|
||||
[System.IO.File]::WriteAllText($output, ($lines -join [Environment]::NewLine) + [Environment]::NewLine, [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output $output
|
||||
Loading…
Add table
Add a link
Reference in a new issue