Add linux musl static graphics support
This commit is contained in:
1 parent
294b2f67d4
commit
5f21d670b0
8 files changed
+646
-21
No files matched your search
@@ -72,6 +72,275 @@ function Copy-FirstExisting($Destination, [string[]]$Candidates) {
|
||||
throw "None of the expected files exist for ${Destination}: $($Candidates -join ', ')"
|
||||
}
|
||||
|
||||
function Split-ParameterList($Parameters) {
|
||||
if ([string]::IsNullOrWhiteSpace($Parameters)) {
|
||||
return @()
|
||||
}
|
||||
|
||||
$items = [System.Collections.Generic.List[string]]::new()
|
||||
$start = 0
|
||||
$depth = 0
|
||||
for ($i = 0; $i -lt $Parameters.Length; $i++) {
|
||||
$ch = $Parameters[$i]
|
||||
if ($ch -eq '[' -or $ch -eq '(' -or $ch -eq '<') {
|
||||
$depth++
|
||||
} elseif ($ch -eq ']' -or $ch -eq ')' -or $ch -eq '>') {
|
||||
if ($depth -gt 0) { $depth-- }
|
||||
} elseif ($ch -eq ',' -and $depth -eq 0) {
|
||||
$items.Add($Parameters.Substring($start, $i - $start).Trim())
|
||||
$start = $i + 1
|
||||
}
|
||||
}
|
||||
$items.Add($Parameters.Substring($start).Trim())
|
||||
return $items | Where-Object { $_ }
|
||||
}
|
||||
|
||||
function Get-X86NativeParameterSize($Parameter) {
|
||||
$parameter = [regex]::Replace($Parameter, '/\*.*?\*/', '').Trim()
|
||||
$parameter = [regex]::Replace($parameter, '\[[^\]]+\]\s*', '').Trim()
|
||||
$parameter = [regex]::Replace($parameter, '\b(ref|out|in)\b\s*', '').Trim()
|
||||
if (-not $parameter) { return 0 }
|
||||
|
||||
$parts = $parameter -split '\s+'
|
||||
if ($parts.Length -gt 1) {
|
||||
$type = ($parts[0..($parts.Length - 2)] -join ' ')
|
||||
} else {
|
||||
$type = $parts[0]
|
||||
}
|
||||
$type = $type.Trim()
|
||||
|
||||
if ($script:X86GeneratedStructSizes -and $script:X86GeneratedStructSizes.ContainsKey($type)) {
|
||||
return $script:X86GeneratedStructSizes[$type]
|
||||
}
|
||||
|
||||
if ($type.Contains('*') -or $type.EndsWith('[]') -or $type -eq 'String' -or $type -eq 'string' -or $type.EndsWith('Delegate')) {
|
||||
return 4
|
||||
}
|
||||
|
||||
switch -Regex ($type) {
|
||||
'^(Int64|UInt64|long|ulong|Double|double)$' { return 8 }
|
||||
default { return 4 }
|
||||
}
|
||||
}
|
||||
|
||||
function Align-X86Size($Size, $Alignment) {
|
||||
if ($Alignment -le 1) { return $Size }
|
||||
return [int]([Math]::Ceiling($Size / [double]$Alignment) * $Alignment)
|
||||
}
|
||||
|
||||
function Get-X86ManagedTypeLayout($Type, $KnownSizes) {
|
||||
if ($Type.Contains('*') -or $Type.Contains('delegate*') -or $Type.EndsWith('[]') -or $Type.EndsWith('Delegate')) {
|
||||
return @{ Size = 4; Alignment = 4 }
|
||||
}
|
||||
|
||||
switch -Regex ($Type) {
|
||||
'^(Byte|SByte|bool)$' { return @{ Size = 1; Alignment = 1 } }
|
||||
'^(Int16|UInt16|short|ushort|Char)$' { return @{ Size = 2; Alignment = 2 } }
|
||||
'^(Int64|UInt64|long|ulong|Double|double)$' { return @{ Size = 8; Alignment = 4 } }
|
||||
default {
|
||||
if ($KnownSizes.ContainsKey($Type)) {
|
||||
return @{ Size = $KnownSizes[$Type]; Alignment = 4 }
|
||||
}
|
||||
return @{ Size = 4; Alignment = 4 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-X86GeneratedStructSizes($BindingFiles) {
|
||||
$structFields = @{}
|
||||
|
||||
foreach ($bindingFile in $BindingFiles) {
|
||||
$lines = Get-Content -Path $bindingFile
|
||||
$current = $null
|
||||
$depth = 0
|
||||
$includeStack = @($true)
|
||||
foreach ($line in $lines) {
|
||||
if ($line -match '^\s*#if\s+USE_LIBRARY_IMPORT\b') {
|
||||
$includeStack += $includeStack[-1]
|
||||
continue
|
||||
}
|
||||
if ($line -match '^\s*#else\b') {
|
||||
if ($includeStack.Count -gt 1) {
|
||||
$parentActive = $includeStack[-2]
|
||||
$includeStack[-1] = $parentActive -and (-not $includeStack[-1])
|
||||
}
|
||||
continue
|
||||
}
|
||||
if ($line -match '^\s*#endif\b') {
|
||||
if ($includeStack.Count -gt 1) {
|
||||
$includeStack = @($includeStack[0..($includeStack.Count - 2)])
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (-not $includeStack[-1]) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (-not $current -and $line -match '\bstruct\s+([A-Za-z0-9_]+)\b') {
|
||||
$current = $Matches[1]
|
||||
$structFields[$current] = [System.Collections.Generic.List[string]]::new()
|
||||
$depth = ([regex]::Matches($line, '\{')).Count - ([regex]::Matches($line, '\}')).Count
|
||||
continue
|
||||
}
|
||||
|
||||
if ($current) {
|
||||
if ($depth -eq 1 -and $line -match '^\s*public\s+(.+?)\s+[A-Za-z0-9_]+;\s*$') {
|
||||
$fieldType = ([regex]::Replace($Matches[1].Trim(), '#if.*$', '')).Trim()
|
||||
$structFields[$current].Add($fieldType)
|
||||
}
|
||||
|
||||
$depth += ([regex]::Matches($line, '\{')).Count
|
||||
$depth -= ([regex]::Matches($line, '\}')).Count
|
||||
if ($depth -le 0) {
|
||||
$current = $null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sizes = @{}
|
||||
$pending = @($structFields.Keys)
|
||||
while ($pending.Count -gt 0) {
|
||||
$next = @()
|
||||
$progress = $false
|
||||
foreach ($name in $pending) {
|
||||
$offset = 0
|
||||
$maxAlign = 1
|
||||
$resolved = $true
|
||||
foreach ($fieldType in $structFields[$name]) {
|
||||
if ($structFields.ContainsKey($fieldType) -and -not $sizes.ContainsKey($fieldType)) {
|
||||
$resolved = $false
|
||||
break
|
||||
}
|
||||
$layout = Get-X86ManagedTypeLayout $fieldType $sizes
|
||||
$maxAlign = [Math]::Max($maxAlign, [Math]::Min($layout.Alignment, 4))
|
||||
$offset = Align-X86Size $offset ([Math]::Min($layout.Alignment, 4))
|
||||
$offset += $layout.Size
|
||||
}
|
||||
if ($resolved) {
|
||||
$sizes[$name] = Align-X86Size $offset $maxAlign
|
||||
$progress = $true
|
||||
} else {
|
||||
$next += $name
|
||||
}
|
||||
}
|
||||
if (-not $progress) { break }
|
||||
$pending = $next
|
||||
}
|
||||
|
||||
return $sizes
|
||||
}
|
||||
|
||||
function Get-X86PInvokeThunks($BindingFiles, $DefinedSymbols) {
|
||||
$thunks = @{}
|
||||
$signaturePattern = 'internal static (?:extern|partial)\s+.+?\s+((?:sk|gr|hb)_[A-Za-z0-9_]+)\s*\((.*?)\);'
|
||||
$script:X86GeneratedStructSizes = Get-X86GeneratedStructSizes $BindingFiles
|
||||
|
||||
foreach ($bindingFile in $BindingFiles) {
|
||||
if (-not (Test-Path $bindingFile)) {
|
||||
throw "Missing binding file for win-x86 thunk generation: $bindingFile"
|
||||
}
|
||||
|
||||
$content = Get-Content -Raw -Path $bindingFile
|
||||
foreach ($match in [regex]::Matches($content, $signaturePattern, [System.Text.RegularExpressions.RegexOptions]::Singleline)) {
|
||||
$symbol = "_$($match.Groups[1].Value)"
|
||||
if (-not $DefinedSymbols.ContainsKey($symbol)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$bytes = 0
|
||||
foreach ($parameter in Split-ParameterList $match.Groups[2].Value) {
|
||||
$bytes += Get-X86NativeParameterSize $parameter
|
||||
}
|
||||
|
||||
$decorated = "${symbol}@${bytes}"
|
||||
$thunks[$decorated] = [pscustomobject]@{
|
||||
Symbol = $symbol
|
||||
Bytes = $bytes
|
||||
Decorated = $decorated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $thunks.Values | Sort-Object Symbol, Bytes
|
||||
}
|
||||
|
||||
function New-WinX86SkiaStdcallThunks([string[]]$InputLibraries, [string[]]$BindingFiles, $Destination) {
|
||||
if ($TargetCpu -ne "x86") {
|
||||
return
|
||||
}
|
||||
|
||||
$llvmNm = Get-Command llvm-nm.exe -ErrorAction SilentlyContinue
|
||||
if (-not $llvmNm) {
|
||||
$llvmNm = Get-Command llvm-nm -ErrorAction SilentlyContinue
|
||||
}
|
||||
if (-not $llvmNm) {
|
||||
throw "Missing required command: llvm-nm"
|
||||
}
|
||||
Require-Command ml.exe
|
||||
Require-Command lib.exe
|
||||
|
||||
$thunkDir = Join-Path $WorkDir "win-x86-skia-stdcall-thunks"
|
||||
New-Item -ItemType Directory -Path $thunkDir -Force | Out-Null
|
||||
$asmPath = Join-Path $thunkDir "skia_x86_stdcall_thunks.asm"
|
||||
$objPath = Join-Path $thunkDir "skia_x86_stdcall_thunks.obj"
|
||||
|
||||
$definedSymbols = @{}
|
||||
foreach ($library in $InputLibraries) {
|
||||
& $llvmNm.Source --defined-only $library |
|
||||
ForEach-Object {
|
||||
if ($_ -match '\sT\s(_(?:sk|gr|hb)_[A-Za-z0-9_]+)$') {
|
||||
$definedSymbols[$Matches[1]] = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $definedSymbols.Count) {
|
||||
throw "No SkiaSharp/HarfBuzzSharp C API symbols found in $($InputLibraries -join ', ')"
|
||||
}
|
||||
|
||||
$thunks = @(Get-X86PInvokeThunks $BindingFiles $definedSymbols)
|
||||
if (-not $thunks) {
|
||||
throw "No win-x86 stdcall thunks generated from $($BindingFiles -join ', ')"
|
||||
}
|
||||
|
||||
$lines = [System.Collections.Generic.List[string]]::new()
|
||||
$lines.Add("OPTION CASEMAP:NONE")
|
||||
$lines.Add(".386")
|
||||
$lines.Add(".model flat")
|
||||
foreach ($symbol in ($thunks | Select-Object -ExpandProperty Symbol -Unique)) {
|
||||
$lines.Add("EXTERN ${symbol}:PROC")
|
||||
}
|
||||
$lines.Add("_TEXT SEGMENT")
|
||||
foreach ($thunk in $thunks) {
|
||||
$lines.Add("PUBLIC $($thunk.Decorated)")
|
||||
$lines.Add("$($thunk.Decorated) PROC")
|
||||
for ($offset = 0; $offset -lt $thunk.Bytes; $offset += 4) {
|
||||
$lines.Add(" push DWORD PTR [esp+$($thunk.Bytes)]")
|
||||
}
|
||||
$lines.Add(" call $($thunk.Symbol)")
|
||||
if ($thunk.Bytes -gt 0) {
|
||||
$lines.Add(" add esp, $($thunk.Bytes)")
|
||||
}
|
||||
$lines.Add(" ret $($thunk.Bytes)")
|
||||
$lines.Add("$($thunk.Decorated) ENDP")
|
||||
}
|
||||
$lines.Add("_TEXT ENDS")
|
||||
$lines.Add("END")
|
||||
Set-Content -Path $asmPath -Value $lines -Encoding ASCII
|
||||
|
||||
& ml.exe /nologo /c /coff /safeseh /Fo$objPath $asmPath
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to assemble win-x86 Skia stdcall thunks."
|
||||
}
|
||||
|
||||
& lib.exe /nologo /out:$Destination $objPath
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to archive win-x86 Skia stdcall thunks."
|
||||
}
|
||||
Write-Host "Wrote $Destination"
|
||||
}
|
||||
|
||||
function Sync-SkiaSharp {
|
||||
$src = Join-Path $WorkDir "SkiaSharp-$SkiaSharpVersion"
|
||||
if (-not (Test-Path (Join-Path $src ".git"))) {
|
||||
@@ -146,7 +415,7 @@ skia_use_system_libpng = false
|
||||
skia_use_system_libwebp = false
|
||||
skia_use_system_zlib = false
|
||||
skia_use_vulkan = false
|
||||
skia_use_xps = false
|
||||
skia_use_xps = true
|
||||
extra_cflags = [ "-DSKIA_C_DLL" ]
|
||||
extra_cflags_cc = [ "/GR" ]
|
||||
"@ | Set-Content -Path (Join-Path $outDir "args.gn") -Encoding ASCII
|
||||
@@ -159,9 +428,12 @@ extra_cflags_cc = [ "/GR" ]
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Copy-FirstExisting (Join-Path $OutputDir "skia.lib") @((Join-Path $outDir "skia.lib"), (Join-Path $outDir "obj\skia.lib"))
|
||||
Copy-FirstExisting (Join-Path $OutputDir "SkiaSharp.lib") @((Join-Path $outDir "SkiaSharp.lib"), (Join-Path $outDir "obj\SkiaSharp.lib"))
|
||||
Copy-FirstExisting (Join-Path $OutputDir "libHarfBuzzSharp.lib") @(
|
||||
$skiaLib = Join-Path $OutputDir "skia.lib"
|
||||
$skiaSharpLib = Join-Path $OutputDir "SkiaSharp.lib"
|
||||
$harfbuzzLib = Join-Path $OutputDir "libHarfBuzzSharp.lib"
|
||||
Copy-FirstExisting $skiaLib @((Join-Path $outDir "skia.lib"), (Join-Path $outDir "obj\skia.lib"))
|
||||
Copy-FirstExisting $skiaSharpLib @((Join-Path $outDir "SkiaSharp.lib"), (Join-Path $outDir "obj\SkiaSharp.lib"))
|
||||
Copy-FirstExisting $harfbuzzLib @(
|
||||
(Join-Path $outDir "libHarfBuzzSharp.lib"),
|
||||
(Join-Path $outDir "HarfBuzzSharp.lib"),
|
||||
(Join-Path $outDir "obj\libHarfBuzzSharp.lib"),
|
||||
@@ -169,6 +441,10 @@ extra_cflags_cc = [ "/GR" ]
|
||||
(Join-Path $outDir "obj\HarfBuzzSharp\libHarfBuzzSharp.lib"),
|
||||
(Join-Path $outDir "obj\HarfBuzzSharp\HarfBuzzSharp.lib")
|
||||
)
|
||||
New-WinX86SkiaStdcallThunks `
|
||||
-InputLibraries @($skiaLib, $skiaSharpLib, $harfbuzzLib) `
|
||||
-BindingFiles @((Join-Path $src "binding\SkiaSharp\SkiaApi.generated.cs"), (Join-Path $src "binding\HarfBuzzSharp\HarfBuzzApi.generated.cs")) `
|
||||
-Destination (Join-Path $OutputDir "skia_x86_stdcall_thunks.lib")
|
||||
}
|
||||
|
||||
function Sync-Angle {
|
||||
|
||||
Reference in new issue
Block a user