Skip to content

Make binding generation deterministic across platforms - #4612

Merged
mattleibow merged 3 commits into
mainfrom
mattleibow-deterministic-binding-generation
Jul 31, 2026
Merged

mattleibow merged 3 commits into
mainfrom
mattleibow-deterministic-binding-generation

Conversation

@mattleibow

@mattleibow mattleibow commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

Binding generation currently inherits filesystem enumeration order before parsing and uses default culture-sensitive string ordering when emitting declarations. Identical inputs can therefore produce large ordering-only diffs across Windows, macOS, and Linux.

This change makes ordering intrinsic to SkiaSharpGenerator: discovered files use normalized ordinal paths, emitted declarations use explicit ordinal keys, and generated files use canonical UTF-8/LF output. The first regeneration establishes that canonical order.

A narrowly triggered workflow generates independently on all three desktop OSes and first compares peer artifacts byte-for-byte without using the checked-in order as its source of truth. Once the hosts agree, it requires that canonical result to match the four committed Skia bindings, catching omitted regeneration and manual generated-code edits.

Related issues

None.

Required skia PR

None.

Areas affected

  • Managed API (binding/)
  • Native / C API (externals/skia/src/c, include/c)
  • Generated P/Invoke bindings
  • Native dependency or Skia update (libpng, HarfBuzz, FreeType, zlib, milestone bump, …)
  • Views & integrations (MAUI, Uno, WPF, WinUI, Blazor, …)
  • Rendering output / visual behavior
  • Performance
  • Tests
  • Build, packaging, or CI
  • Documentation or samples

Changes

None — generator and CI behavior only; there are no public API or runtime behavior changes. The one-time SkiaApi.generated.cs migration is ordering-only: all 23,630 lines are unchanged.

Testing

  • dotnet build utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj --no-restore
  • Repository binding regeneration completed successfully and was idempotent
  • Verified the committed SkiaApi.generated.cs has the same 23,630-line multiset as main
  • Verified exact committed/generated blob equality and that the stale main ordering is rejected
  • Fresh main-based PR run: Linux, macOS, and Windows generation plus byte-for-byte comparison passed
  • Checked-in binding freshness gate passed on the updated PR run

Focused generator unit tests are intentionally deferred to a follow-up.

Checklist

  • Tests added or updated — deferred; this PR adds the three-OS byte-comparison workflow
  • Changes above lists all public API and behavioral changes (None)
  • New/changed public API? N/A — no public API changes
  • Native change? N/A — no native or submodule changes

@github-actions

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 4612

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 4612"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-4612/packages --name skiasharp-pr-4612
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-4612

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

📊 SkiaSharp benchmarks — PR #4612

⭐ this PR (full source build) vs 🌙 nightly · Linux · Windows · macOS

Informational only — this never blocks the PR. 🟢 faster / less allocation · 🔴 slower / more allocation; moves under 5% are hidden as noise.

⏱️ Times are raw BenchmarkDotNet means, and the ⭐ PR and baseline legs run on separate CI runners, so microbenchmarks can swing run-to-run — treat small time deltas as noise. Allocations are deterministic and the reliable signal. The interactive perf-dashboard (linked below) applies smoothing for the trend view.

Highlights

⏱️ Time — 🔴 47 slower · 🟢 1 faster

  • 🔴 PathBoundsBenchmark.TightBounds(Points: 1024) · Windows · 15.15 µs → 22.68 µs (+50%)
  • 🔴 RasterImageLifecycleBenchmark.CreateDataWithReleaseProc(Count: 256) · Windows · 96.36 µs → 132.86 µs (+38%)
  • 🔴 RasterImageLifecycleBenchmark.CreateRasterImage(Count: 256) · Windows · 247.55 µs → 325.10 µs (+31%)
  • 🔴 PathBoundsBenchmark.TightBounds(Points: 1024) · Linux · 10.44 µs → 13.37 µs (+28%)
  • 🔴 PathBoundsBenchmark.TightBounds(Points: 64) · Windows · 1.52 µs → 1.94 µs (+28%)
  • …and 43 more (see details below)
Full per-OS benchmark deltas

Linux

⏱️ Time (vs 🌙 nightly 4.151.0-nightly.114)

Benchmark baseline this PR Δ
PathBoundsBenchmark.TightBounds(Points: 1024) 10.44 µs 13.37 µs 🔴 +28%
RasterImageLifecycleBenchmark.CreateDataWithReleaseProc(Count: 256) 100.65 µs 118.65 µs 🔴 +18%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 256) 957.37 µs 1.05 ms 🔴 +9%
ColorMathBenchmark.PreMultiply(Colors: 4096) 12.95 µs 14.10 µs 🔴 +9%
MatrixMapPointsBenchmark.MapPoints(Points: 4096) 2.73 µs 2.92 µs 🔴 +7%
RasterImageLifecycleBenchmark.CreateRasterImage(Count: 256) 261.73 µs 277.07 µs 🔴 +6%
ColorMathBenchmark.UnPreMultiply(Colors: 4096) 11.45 µs 12.12 µs 🔴 +6%
PathBoundsBenchmark.TightBounds(Points: 64) 986.4 ns 1.04 µs 🔴 +5%

Windows

⏱️ Time (vs 🌙 nightly 4.151.0-nightly.114)

Benchmark baseline this PR Δ
PathBoundsBenchmark.TightBounds(Points: 1024) 15.15 µs 22.68 µs 🔴 +50%
RasterImageLifecycleBenchmark.CreateDataWithReleaseProc(Count: 256) 96.36 µs 132.86 µs 🔴 +38%
RasterImageLifecycleBenchmark.CreateRasterImage(Count: 256) 247.55 µs 325.10 µs 🔴 +31%
PathBoundsBenchmark.TightBounds(Points: 64) 1.52 µs 1.94 µs 🔴 +28%
MatrixMapPointsBenchmark.MapRadius(Points: 4096) 142.18 µs 182.03 µs 🔴 +28%
MatrixMapPointsBenchmark.MapVector(Points: 4096) 120.21 µs 148.81 µs 🔴 +24%
MatrixOpsBenchmark.Concat(Count: 4096) 229.43 µs 281.32 µs 🔴 +23%
MatrixMapPointsBenchmark.MapRadius(Points: 256) 8.91 µs 10.86 µs 🔴 +22%
MatrixOpsBenchmark.Invert(Count: 4096) 130.42 µs 154.43 µs 🔴 +18%
MatrixMapPointsBenchmark.MapPoint(Points: 4096) 75.57 µs 89.10 µs 🔴 +18%
MatrixMapPointsBenchmark.MapPoint(Points: 256) 4.73 µs 5.57 µs 🔴 +18%
MatrixMapPointsBenchmark.MapRect(Points: 256) 7.50 µs 8.80 µs 🔴 +17%
MatrixMapPointsBenchmark.MapRect(Points: 4096) 119.57 µs 139.65 µs 🔴 +17%
ColorParseBenchmark.Parse(Iterations: 1000) 74.51 µs 86.77 µs 🔴 +16%
LargeImageScaleBenchmark.UpscaleOpaque(Size: 1024) 737.23 µs 857.64 µs 🔴 +16%
ColorMathBenchmark.PreMultiply(Colors: 4096) 13.19 µs 15.11 µs 🔴 +15%
MatrixMapPointsBenchmark.MapVector(Points: 256) 8.15 µs 9.22 µs 🔴 +13%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 256) 1.24 ms 1.39 ms 🔴 +13%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 2048) 10.06 ms 11.33 ms 🔴 +13%
LargeImageScaleBenchmark.UpscaleOpaque(Size: 2048) 2.87 ms 3.23 ms 🔴 +12%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 64) 240.43 µs 269.77 µs 🔴 +12%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 64) 334.00 µs 372.49 µs 🔴 +12%
RuntimeEffectShaderBenchmark.DrawFrame 1.14 ms 1.26 ms 🔴 +11%
LargeImageScaleBenchmark.UpscaleCrossfade(Size: 1024) 2.55 ms 2.83 ms 🔴 +11%
CanvasDrawBenchmark.Draw(Shapes: 512) 21.17 ms 23.42 ms 🔴 +11%
…and 6 more

macOS

⏱️ Time (vs 🌙 nightly 4.151.0-nightly.114)

Benchmark baseline this PR Δ
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 64) 181.09 µs 213.38 µs 🔴 +18%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 64) 148.29 µs 172.89 µs 🔴 +17%
SceneRenderBenchmark.RenderFrame(Complexity: 4) 5.36 ms 6.14 ms 🔴 +14%
BitmapDrawBenchmark.DrawScaledTiles(Tiles: 256) 680.06 µs 772.81 µs 🔴 +14%
RasterImageLifecycleBenchmark.CreateDataWithReleaseProc(Count: 256) 65.11 µs 73.55 µs 🔴 +13%
BitmapDrawBenchmark.DrawUnscaledTiles(Tiles: 256) 543.39 µs 596.13 µs 🔴 +10%
MatrixMapPointsBenchmark.MapPoints(Points: 256) 128.9 ns 140.1 ns 🔴 +9%
MatrixMapPointsBenchmark.MapPoints(Points: 4096) 1.56 µs 1.67 µs 🔴 +7%
MatrixMapPointsBenchmark.MapRect(Points: 4096) 50.65 µs 47.47 µs 🟢 -6%

📈 Full interactive perf-dashboard & run details →

mattleibow and others added 2 commits July 31, 2026 20:02
Sort discovered headers and emitted declarations by normalized ordinal keys,
and emit canonical LF output so binding generation no longer depends on host
filesystem or culture ordering. Regenerate the canonical binding order and
compare independently generated artifacts across Linux, macOS, and Windows.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f532599a-b19b-4923-a723-e91f86ecff4e
Run dependency sync and binding generation directly so automatic CI only watches true generator inputs. Add the committed generated files because their XML documentation is preserved during generation, and replace broad config and Cake-related patterns with the exact maintained input set.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: f532599a-b19b-4923-a723-e91f86ecff4e
@mattleibow
mattleibow force-pushed the mattleibow-deterministic-binding-generation branch from ea63695 to ad43bd0 Compare July 31, 2026 18:02
@mattleibow
mattleibow changed the base branch from mattleibow-dev-vulkan-sync-validation to main July 31, 2026 18:02
After all three hosts agree byte-for-byte, compare the canonical generated Skia outputs with the committed bindings. Fail with per-file diffs when regeneration was omitted or generated code was edited manually; keep HarfBuzz freshness out of scope because its bindings are versioned separately from Skia DEPS.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: f532599a-b19b-4923-a723-e91f86ecff4e
@mattleibow
mattleibow marked this pull request as ready for review July 31, 2026 18:30
@mattleibow
mattleibow merged commit 8afade0 into main Jul 31, 2026
79 of 88 checks passed
@mattleibow
mattleibow deleted the mattleibow-deterministic-binding-generation branch July 31, 2026 18:31
@github-actions

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

The documentation for this PR has been deployed and is available at:

🔗 View Staging Site
🔗 View Staging Docs
🔗 View Staging Gallery (Blazor)
🔗 View Staging Gallery (Uno Platform)
🔗 View Staging SkiaFiddle

This preview will be updated automatically when you push new commits to this PR.


This comment is automatically updated by the documentation staging workflow.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Artifact size report

Packages from this PR (build 1535126) vs the latest nightly baseline 4.151.0-nightly.114 (observed 2026-07-31).

Total .nupkg size: 569.2 MB → 568.7 MB (−587.9 KB, -0.1%)

Packages

⚠️ marks growth over 500.0 KB or 2%. Changes under 50.0 KB are treated as noise.

Package baseline this PR Δ Δ%
SkiaSharp.NativeAssets.WinUI 109.0 MB 108.3 MB 🟢 −681.7 KB -0.6%

+39 package(s) unchanged (< 50.0 KB).

Per-file changes

SkiaSharp.NativeAssets.WinUI

File Size
runtimes/win-arm64/native/libGLESv2.pdb 64.5 MB → 64.4 MB (🟢 −128.0 KB)
runtimes/win-x64/native/libGLESv2.pdb 66.6 MB → 66.5 MB (🟢 −128.0 KB)
runtimes/win-x86/native/libGLESv2.pdb 67.3 MB → 67.2 MB (🟢 −80.0 KB)

Informational only — this never blocks the PR. Native binaries are labelled by os/arch.

mattleibow added a commit that referenced this pull request Aug 4, 2026
[bindings] Make generation deterministic across platforms (#4612)

Context: #4612

SkiaSharpGenerator relied on filesystem enumeration and culture-sensitive
string ordering, causing identical inputs to produce different function and
type ordering across Windows, macOS, and Linux.

Use normalized relative paths, ordinal comparisons, and canonical UTF-8/LF
output. The resulting SkiaApi migration only reorders its existing 23,630
lines.

Add CI that independently generates bindings on all three platforms, compares
their outputs byte-for-byte, then verifies the canonical result matches the
four committed Skia bindings. This detects cross-host nondeterminism, omitted
regeneration, and manual generated-file edits. HarfBuzz freshness remains out
of scope because its bindings are versioned separately.

Co-authored-by: Matthew Leibowitz <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@mattleibow mattleibow added this to the 4.152.0-preview.1 milestone Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant