Files
IKAR/scripts/prepare-plugin-runtime.ps1
T

42 lines
2.5 KiB
PowerShell

param()
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
$clangDirectory = Join-Path $projectRoot 'build/native-tests/clang'
New-Item -ItemType Directory -Force $clangDirectory | Out-Null
$clangLibrary = Join-Path $clangDirectory 'libclang.dll'
if (-not (Test-Path -LiteralPath $clangLibrary)) {
$archivePath = Join-Path $clangDirectory 'libclang.whl'
Invoke-WebRequest 'https://files.pythonhosted.org/packages/0b/2d/3f480b1e1d31eb3d6de5e3ef641954e5c67430d5ac93b7fa7e07589576c7/libclang-18.1.1-py2.py3-none-win_amd64.whl' -OutFile $archivePath
$expectedHash = '4dd2d3b82fab35e2bf9ca717d7b63ac990a3519c7e312f19fa8e86dcc712f7fb'
if ((Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant() -ne $expectedHash) {
throw 'libclang archive checksum mismatch'
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($archivePath)
try {
$entry = $archive.Entries | Where-Object FullName -eq 'libclang-18.1.1.data/platlib/clang/native/libclang.dll' | Select-Object -First 1
if ($null -eq $entry) { throw 'libclang archive has no native library' }
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $clangLibrary, $true)
} finally { $archive.Dispose() }
}
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer/vswhere.exe'
$installation = & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (-not $installation) { throw 'Visual C++ Build Tools are required' }
$compiler = Get-ChildItem -LiteralPath (Join-Path $installation 'VC/Tools/MSVC') -Directory | Sort-Object Name -Descending | Select-Object -First 1
$sdkRoot = Join-Path ${env:ProgramFiles(x86)} 'Windows Kits/10/Include'
$sdk = Get-ChildItem -LiteralPath $sdkRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1
$includes = @((Join-Path $compiler.FullName 'include'), (Join-Path $sdk.FullName 'ucrt'), (Join-Path $sdk.FullName 'shared'))
$oldClang = $env:LIBCLANG_PATH
$oldArgs = $env:BINDGEN_EXTRA_CLANG_ARGS
Push-Location $projectRoot
try {
$env:LIBCLANG_PATH = $clangDirectory
$env:BINDGEN_EXTRA_CLANG_ARGS = ($includes | ForEach-Object { '-isystem "' + $_.Replace('\', '/') + '"' }) -join ' '
dart run tool/prepare_plugin_runtime.dart
if ($LASTEXITCODE -ne 0) { throw 'Native plugin runtime build failed' }
} finally {
$env:LIBCLANG_PATH = $oldClang
$env:BINDGEN_EXTRA_CLANG_ARGS = $oldArgs
Pop-Location
}