← Files ISA-L ZipARCHIVED FILE

build-support/build-native.ps1

4.8 KB · Nov 30, 2026 · 00:22 UTC

↓ Download file

param(
    [string]$ZigPath,
    [string]$NasmPath,
    [string]$CMakePath,
    [string]$NinjaPath
)
# Copyright (c) 2026 Tarek Wasfy. Licensed under the MIT License.
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$native = Join-Path $root 'native'
$archive = Join-Path $root 'third_party\isa-l-master-source.zip'
if (-not (Test-Path -LiteralPath $archive)) { throw "Missing ISA-L source archive: $archive" }
foreach ($pair in @(@('zig',$ZigPath),@('nasm',$NasmPath),@('cmake',$CMakePath),@('ninja',$NinjaPath))) {
    if (-not $pair[1]) {
        $cmd = Get-Command $pair[0] -ErrorAction SilentlyContinue
        if ($cmd) { Set-Variable -Name ($pair[0] + 'Exe') -Value $cmd.Source }
    } else { Set-Variable -Name ($pair[0] + 'Exe') -Value $pair[1] }
}
if ($ZigPath) { $zigExe=$ZigPath }; if ($NasmPath) { $nasmExe=$NasmPath }; if ($CMakePath) { $cmakeExe=$CMakePath }; if ($NinjaPath) { $ninjaExe=$NinjaPath }
if (-not $zigExe -or -not $nasmExe -or -not $cmakeExe -or -not $ninjaExe) { throw 'zig, nasm, cmake and ninja are required. Supply their paths as script parameters.' }
$buildRoot = Join-Path $native '.build'
$sourceRoot = Join-Path $buildRoot 'source'
$isaSource = Join-Path $sourceRoot 'isa-l-master'
$env:ISA_ZIG = [IO.Path]::GetFullPath($zigExe)
$env:ZIG_LOCAL_CACHE_DIR = Join-Path $buildRoot 'zig-local-cache'
$env:ZIG_GLOBAL_CACHE_DIR = Join-Path $buildRoot 'zig-global-cache'
New-Item -ItemType Directory -Force -Path $sourceRoot,$buildRoot | Out-Null
if (-not (Test-Path -LiteralPath (Join-Path $isaSource 'CMakeLists.txt'))) {
    Expand-Archive -LiteralPath $archive -DestinationPath $sourceRoot -Force
}
$wrapperSource = Join-Path $native 'build\cc-wrapper'
$wrapperDir = Join-Path $buildRoot 'wrappers'
New-Item -ItemType Directory -Force -Path $wrapperDir | Out-Null
$env:GOCACHE = Join-Path $buildRoot 'go-cache'
Push-Location $wrapperSource
try { go build -trimpath -o (Join-Path $wrapperDir 'cc-win.exe') .\main.go; if ($LASTEXITCODE -ne 0) { throw 'Building Zig C compiler wrapper failed.' } }
finally { Pop-Location }
Copy-Item (Join-Path $wrapperDir 'cc-win.exe') (Join-Path $wrapperDir 'cc-linux.exe') -Force
Copy-Item (Join-Path $wrapperDir 'cc-win.exe') (Join-Path $wrapperDir 'ar.exe') -Force
Copy-Item (Join-Path $wrapperDir 'cc-win.exe') (Join-Path $wrapperDir 'ranlib.exe') -Force
$configs = @(
    @{ Name='windows-amd64'; System='Windows'; Processor='AMD64'; CC=(Join-Path $wrapperDir 'cc-win.exe'); AsmFlags=''; ArchiveName='isa-l.a'; GoOS='windows'; GoFlags='-trimpath -ldflags=-s\ -w' },
    @{ Name='linux-amd64'; System='Linux'; Processor='x86_64'; CC=(Join-Path $wrapperDir 'cc-linux.exe'); AsmFlags='-f elf64 -D LINUX'; ArchiveName='libisal.a'; GoOS='linux'; GoFlags='-trimpath -ldflags=-s\ -w\ -linkmode\ external\ -extldflags\ -static' }
)
$isalLibRoot = Join-Path $native 'lib'
foreach ($cfg in $configs) {
    $build = Join-Path $buildRoot $cfg.Name
    $libDir = Join-Path $isalLibRoot $cfg.Name
    New-Item -ItemType Directory -Force -Path $libDir | Out-Null
    $common = @('-S',$isaSource,'-B',$build,'-G','Ninja',"-DCMAKE_MAKE_PROGRAM:FILEPATH=$ninjaExe", "-DCMAKE_SYSTEM_NAME=$($cfg.System)", "-DCMAKE_SYSTEM_PROCESSOR=$($cfg.Processor)", "-DCMAKE_C_COMPILER=$($cfg.CC)", "-DCMAKE_AR=$($wrapperDir)\ar.exe", "-DCMAKE_RANLIB=$($wrapperDir)\ranlib.exe", "-DCMAKE_ASM_NASM_COMPILER=$nasmExe", '-DCMAKE_BUILD_TYPE=Release','-DBUILD_SHARED_LIBS=OFF','-DISAL_BUILD_TESTS=OFF','-DISAL_BUILD_PERF_TESTS=OFF','-DISAL_BUILD_ISAL_SHIM=OFF','-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY')
    if ($cfg.AsmFlags) { $common += "-DCMAKE_ASM_NASM_FLAGS=$($cfg.AsmFlags)" }
    & $cmakeExe @common
    if ($LASTEXITCODE -ne 0) { throw "ISA-L C configure failed for $($cfg.Name)" }
    & $cmakeExe --build $build --target isal -j 8
    if ($LASTEXITCODE -ne 0) { throw "ISA-L C build failed for $($cfg.Name)" }
    Copy-Item (Join-Path $build $cfg.ArchiveName) (Join-Path $libDir 'libisal.a') -Force
}
$env:GOARCH='amd64';$env:CGO_ENABLED='1';$env:CC=Join-Path $wrapperDir 'cc-win.exe'
$env:GOOS='windows'
Push-Location $native
try {
    go build -trimpath -ldflags='-s -w' -o (Join-Path $root 'skills\isa-zip\bin\windows-x64\isa-zip.exe') .\cmd\isa-zip
    if ($LASTEXITCODE -ne 0) { throw 'Native Windows Go/CGo build failed.' }
    go test ./...
    if ($LASTEXITCODE -ne 0) { throw 'Native Windows tests failed.' }
    $env:GOOS='linux';$env:CC=Join-Path $wrapperDir 'cc-linux.exe'
    go build -trimpath -ldflags='-s -w -linkmode external -extldflags -static' -o (Join-Path $root 'skills\isa-zip\bin\linux-x64\isa-zip') .\cmd\isa-zip
    if ($LASTEXITCODE -ne 0) { throw 'Native Linux cross-build failed.' }
} finally { Pop-Location }
Write-Output 'Built native Windows x64 and Linux x86_64 Go binaries with Intel ISA-L C.'
Write-Output 'Windows tests passed. Run Linux smoke tests on Linux before calling Linux runtime validation complete.'

SHA-256: f3966760314fac1c01172906c98ba3c8087dc34ed5de45b4666998507b65cd6f