Skip to content

Ship emdawnwebgpu's webgpu.cpp inside libSkiaSharp.a - #5316

Merged
mattleibow merged 2 commits into
mono:mainfrom
ramezgerges:dev/rara/wasm-webgpu-cpp-archive
Oct 14, 2026
Merged

mattleibow merged 2 commits into
mono:mainfrom
ramezgerges:dev/rara/wasm-webgpu-cpp-archive

Conversation

@ramezgerges

@ramezgerges ramezgerges commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Since #3968, the WASM targets hand Dawn's emdawnwebgpu port to the app's link as source: webgpu.cpp, its include paths and -std=c++20 all go through EmccExtraLDFlags. The .NET WebAssembly SDK compiles every source on that one emcc link line with the same flags, so the C++ standard also reaches any C file the app links, and clang rejects it:

error : invalid argument '-std=c++20' not allowed with 'C'

Clang has no per-language -std, so no flag can serve both languages on that line. The fix is to stop compiling on it:

  • Native build: on Graphite builds (emsdk ≥ 3.1.51), native/wasm/build.cake passes the port's directory to Skia's GN build as skiasharp_emdawnwebgpu_dir (added in Build emdawnwebgpu's webgpu.cpp into SkiaSharp on WASM skia#396). GN builds webgpu.cpp as a static library that SkiaSharp depends on, so it lands in libSkiaSharp.a compiled with the same flags as the rest of SkiaSharp (C++20, no exceptions, optimized, NDEBUG, plus the variant's SIMD/threads/exceptions flags), with no flag list of its own to keep in sync with the port.
  • WASM targets (the shipped buildTransitive/SkiaSharp.targets and the in-repo IncludeNativeAssets.SkiaSharp.targets): the source, its include paths, -std=c++20 and -s DEFAULT_TO_CXX=1 are gone from EmccExtraLDFlags. The port's four JS libraries go to the link as Content with Kind="js-library", which the SDK links as --js-library. They're added in a target just before the SDK writes the link response file, not as static items, because hosts that deploy every .js Content item would otherwise publish them (Uno Platform's bootstrapper does).

What still reaches the link from SkiaSharp is -s USE_WEBGL2=1.

Who hits the bug today: any WASM app on 4.152 or later that links a C source of its own. Uno Platform 7's WebAssembly runtime links uno_gl_shim.c (its GLCanvasElement support), so every Uno Platform 7 WASM app fails once it moves past SkiaSharp 4.151. That's why #5174's samples needed it.

Transition: the targets now expect the port inside libSkiaSharp.a. Archives built before this change don't contain it, so linking against them (e.g. natives fetched by externals-download before this lands on the artifact server) fails with undefined wgpu* symbols until the WASM natives are rebuilt.

Related issues

Related to #3968 (introduced the link-line compile) and #5174 (Uno Platform 7, which links a C source).

Required skia PR

Requires mono/skia#396 (this PR bumps externals/skia to it).

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, …): externals/skia bump for Build emdawnwebgpu's webgpu.cpp into SkiaSharp on WASM skia#396
  • Views & integrations (MAUI, Uno, WPF, WinUI, Blazor, …)
  • Rendering output / visual behavior
  • Performance
  • Tests
  • Build, packaging, or CI
  • Documentation or samples

Changes

Behavior

WASM apps no longer compile webgpu.cpp at link time, and SkiaSharp no longer puts -std=c++20 or DEFAULT_TO_CXX on their link line, so apps that link C sources build. No API change.

Testing

The native build itself was not run: it's Linux-only and needs a full Skia WASM build. In its place:

  • gn gen for WASM with the Graphite args and the new arg: //:emdawnwebgpu resolves, SkiaSharp depends on it, and gn desc shows the flags it will build with (-std=c++20 -fno-exceptions -O3 -DNDEBUG -fvisibility=hidden, the variant's -msimd128, the port's include dirs).
  • webgpu.cpp compiled by hand with exactly those flags through the .NET WASM SDK's own emscripten (3.1.56), and emar'd into the existing libSkiaSharp.a/3.1.56/st/libSkiaSharp.a.

Against that archive, with these targets, on Windows:

  • Uno Platform 7 Gallery (net10.0-browserwasm, on the [FEATURE] Uno Platform 7.0 support for SkiaSharp.Views.Uno.WinUI #5174 branch, which also links Uno's uno_gl_shim.c): before, the link fails with the error above; after, it publishes, the link response file carries the four --js-library entries and no -std / source / DEFAULT_TO_CXX, nothing from the port lands in wwwroot, and the app runs in Edge with no console errors.
  • Blazor WebAssembly sample: publishes against the same archive, with the same link-line contents and no deployed port files.
  • C++ linking resolves without DEFAULT_TO_CXX, and _wgpuCreateInstance / _wgpuTextureRelease stay exported despite -fvisibility=hidden.

Not covered: the mt / simd variants, emsdk 5.x/6.x (.NET 11), and WebGPU rendering at runtime (the Uno app renders through WebGL).

Checklist

  • Tests added or updated (if omitted, explain why above): build/packaging change; validated by building and running the WASM samples as described.
  • Changes above lists all public API and behavioral changes (or "None.")
  • New/changed public API? Added or updated accurate source /// documentation and regenerated bindings when applicable: no API change.
  • Native change? Companion mono/skia PR linked above and bindings regenerated: Build emdawnwebgpu's webgpu.cpp into SkiaSharp on WASM skia#396 is GN-only, no C API change, so no bindings to regenerate.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 9, 2026

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 -- 5316

PowerShell / Windows:

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

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-5316/packages --name skiasharp-pr-5316
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-5316

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@ramezgerges! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Dawn's emdawnwebgpu port ships webgpu.cpp as source, so the WASM
targets passed it, its include paths and -std=c++20 through
EmccExtraLDFlags. The .NET WebAssembly SDK compiles every source on that
one link line, so the -std flag also reached the app's C sources and
clang rejected it:

  invalid argument '-std=c++20' not allowed with 'C'

Any app linking a C file failed, Uno Platform 7 apps included.

The native build now passes the port's directory to Skia's GN build
(skiasharp_emdawnwebgpu_dir, from mono/skia), which compiles webgpu.cpp
with the rest of SkiaSharp and the same per-variant flags, into
libSkiaSharp.a. Apps link an object: no source, no compile flag and no
DEFAULT_TO_CXX reach their link.

The port's JS libraries go to the link as js-library Content, added just
before the SDK writes the link response file so hosts that deploy every
.js Content item (Uno Platform's bootstrapper) don't publish them.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The full native build and variant compatibility remain unvalidated, and raster-only builds have an unresolved link failure.

1 open finding
What changed in this PR

Moves emdawnwebgpu compilation into the native WASM archive so C++ flags no longer break apps linking C sources, including Uno 7 apps.

Changes:

  • Passes the port directory to Skia’s native build.
  • Removes source compilation flags from app linking.
  • Adds JavaScript libraries immediately before linking to avoid deployment.
File Description
native/​wasm/​build.cake Enables native compilation of the WebGPU port.
binding/​SkiaSharp.NativeAssets.WebAssembly/​buildTransitive/​SkiaSharp.targets Updates packaged link flags and JavaScript inputs.
binding/​IncludeNativeAssets.SkiaSharp.targets Applies matching changes to in-repository builds.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread native/wasm/build.cake Resolved
Use the squash commit from mono/skia#396 in the submodule and component manifest. Its tree matches reviewed commit f58e2b3d8a9fd645dc9e9fd78612eb3852e35d37 exactly.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f174e671-3c47-4bff-8ae6-fa4a64991ab1
@mattleibow
mattleibow merged commit 9745920 into mono:main Oct 14, 2026
28 of 31 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/wasm-webgpu-cpp-archive branch October 15, 2026 11:01
@github-actions github-actions Bot added this to the 4.156.0-rc.1 milestone Nov 9, 2026
mattleibow added a commit to mono/skia that referenced this pull request Nov 17, 2026
[m155] Backport Skia security fixes and WASM build hook (#462)

Context: mono/SkiaSharp#5797
Context: #396
Context: mono/SkiaSharp#5316
Changes: 168d720...221ae11

Backport four Google m156 security fixes and the existing WASM hook
to 4.155. Preserve the m155 baseline, prior fork changes, C API and DEPS.

~~ CVE-2026-118340: image-filter cache ID wraparound ~~

32-bit filter IDs can wrap and collide with live cache entries.
Backport c68d7fd (upstream 8700229): use 64-bit filter/cache IDs
and initialize key padding for byte hashing. The regression distinguishes
IDs differing by 1 << 32 and checks independent cache results.

~~ CVE-2026-119261: reserved SkSL types outside declarations ~~

Private runtime-effect types alias the invalid type. Checking variable
declarations misses struct fields. Backport 961c7e8 (upstream
0a8b2fc): reject aliases in Parser::type, suppress duplicate diagnostics
and carry the struct-field regression and expected-error updates.

~~ CVE-2026-121086: conic region edge-buffer sizing ~~

Two budgeted edges per conic are insufficient for up to 32 subdivided
quadratics and 64 monotonic edges. Backport c433a0f (upstream
50a301a): share SkConic's subdivision limit, budget the worst case
and return an empty region on checked edge-count overflow.

Changed lines match upstream; m155's existing array syntax explains the
context difference, not a custom rewrite. Carry Region_ConicMaxEdges;
its 32-span trigger requires SK_SUPPORT_LEGACY_CONIC_CHOP.

~~ CVE-2026-126912: clipped convex rasterization ~~

Right-boundary edge cancellation can leave a convex walker without both
edges; stale scan positions across Y-gaps can overflow fixed-point X.
Backport 0ac7dc6 (upstream 866b61c): preserve required edges,
advance/flush across gaps, saturate/clamp X and reject non-positive runs.
Keep SK_LEGACY_ALPHA_RUNS guards and the convex-path/oval regression.

~~ Compile the WASM port before the application's mixed-language link ~~

Compiling webgpu.cpp on the app's emcc link line applies -std=c++20 to
C inputs too. Clang rejects this; Uno Platform 7's uno_gl_shim.c exposes it.

Backport #396 unchanged as 221ae11. A nonempty
skiasharp_emdawnwebgpu_dir on WASM builds the port into a static library
that SkiaSharp depends on; unset, it adds no target or dependency.
mono/SkiaSharp#5797 supplies the directory and backports the consumer
changes from mono/SkiaSharp#5316.

Retain mono/SkiaSharp#5316's accepted constraint: custom GPU-disabled
WASM archives can omit port exports required by .NET 9+ targets.
Shipping WASM packages remain GPU-enabled; this backport does not fix
the unsupported custom configuration.

Co-authored-by: alexis cruz-ayala <[email protected]>
Co-authored-by: Nathan Sanchez <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Ramez Ragaa <[email protected]>
Co-authored-by: Ramez Ragaa <[email protected]>
Co-authored-by: Matthew Leibowitz <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Co-authored-by: Copilot App <[email protected]>
mattleibow added a commit that referenced this pull request Nov 17, 2026
…5316) (#5797)

* [4.155] Backport four Skia CVE fixes and the emdawnwebgpu link fix (#5316)

Pin externals/skia to an m155 backport carrying four more upstream Skia
security fixes, and backport #5316 (and its Skia half, mono/skia#396) so
WASM apps that link C sources build again.

~~ Skia security fixes (all Chrome-assigned, Chromium severity High) ~~

- CVE-2026-118340, integer overflow leaking cross-origin data. Chromium
  bug 568936530, upstream 8700229923 "[skif] Update SkImageFilter_Base
  uniqueID to 64-bit" (M156: c68d7fd343).
- CVE-2026-119261, SkSL buffer overflow. Chromium bug 574213633, upstream
  0a8b2fc486 "[SkSL] Reject invalid types when parsing" (M156: 961c7e83d9).
- CVE-2026-121086, heap OOB write in SkRgnBuilder for conic paths.
  Chromium bug 569674218, upstream 50a301ac1c (M156: c433a0fce9).
- CVE-2026-126912, heap-buffer-overflow in RunBasedAdditiveBlitter and the
  AAA convex walker. Chromium bug 569286603, upstream reland 866b61ca92
  (M156: 0ac7dc6087).

Google backported these to m156 and later but not m155. All four
M156 cherry-picks applied to m155 without conflicts.

~~ Ship emdawnwebgpu's webgpu.cpp inside libSkiaSharp.a (#5316) ~~

4.155 includes #3968, so its WASM targets compile Dawn's webgpu.cpp on the
app's emcc link line with -std=c++20, which clang rejects for any C source
the app links (for example Uno Platform 7's uno_gl_shim.c). Build the port
into libSkiaSharp.a through mono/skia#396's skiasharp_emdawnwebgpu_dir GN
argument instead, and stop putting the source, -std=c++20 and
DEFAULT_TO_CXX on the link line. The targets and build.cake changes are
identical to #5316; only the submodule and cgmanifest pins differ.

C API declarations, DEPS, managed APIs and package versions are unchanged,
and upstream_merge_commit still names the last incorporated chrome/m155
commit.

(cherry picked from commit 9745920)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [m155] Repin Skia to the ancestry-preserving CVE repair

Context: mono/skia#465

Point externals/skia and the matching component manifest entry at
e6cfc7a5d6dea7e8c21a59782c672a00b1fff28c. The repaired native history
contains all seven original reviewed commits from mono/skia#461 and
mono/skia#462 while retaining both squash landings.

The native tree is identical to reviewed head 221ae11c5318. This
changes only the two pins, not the security or WASM implementation.
For this combined repair, verify original-commit ancestry and tree
equality explicitly rather than requiring a direct-parent relationship.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Matthew Leibowitz <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants