WebAssembly head fails to link with SkiaSharp 4.x: `-std=c++20` is applied to `uno_gl_shim.c`
Summary
Setting SkiaSharpVersion to 4.x in an Uno WebAssembly app breaks the native link:
emcc: error: invalid argument '-std=c++20' not allowed with 'C'SkiaSharp.NativeAssets.WebAssembly 4.x enables Dawn's WebGPU port by appending -std=c++20 and its own webgpu.cpp to EmccExtraLDFlags. The .NET WebAssembly SDK compiles every native source in a single emcc invocation, and -std= applies to the whole command line rather than to one input, so the flag also lands on uno_gl_shim.c from Uno.WinUI.Runtime.Skia.WebAssembly.Browser. clang rejects a C++ standard for a C input.
Environment
- Uno Platform 6.7.103 / Uno.Sdk 6.7.22,
net10.0-browserwasm - SkiaSharp 4.152.0 (
<SkiaSharpVersion>4.152.0</SkiaSharpVersion>) - .NET SDK 10.0.11,
Microsoft.NET.Runtime.Emscripten.3.1.56.Sdk - Windows 11
Repro
- Uno single-project app with a
net10.0-browserwasmhead. - Add
<SkiaSharpVersion>4.152.0</SkiaSharpVersion>. dotnet publish -f net10.0-browserwasm -c Release.
Detail
SkiaSharp.NativeAssets.WebAssembly.targets (buildTransitive/netstandard1.0/):
<_SkiaSharpEmdawnwebgpuFlags Condition="'$(_SkiaSharpUseEmdawnwebgpu)' == 'true'">-s DEFAULT_TO_CXX=1 ... -std=c++20 $(_SkiaSharpEmdawnwebgpuPkg)/webgpu/src/webgpu.cpp</_SkiaSharpEmdawnwebgpuFlags>
<EmccExtraLDFlags Condition="'$(_SkiaSharpUseEmdawnwebgpu)' == 'true'">$(EmccExtraLDFlags) -s USE_WEBGL2=1 $(_SkiaSharpEmdawnwebgpuFlags)</EmccExtraLDFlags>_SkiaSharpUseEmdawnwebgpu defaults to true on net9.0+, so this is the default path. The generated emcc-link.rsp ends up containing both inputs:
-s USE_WEBGL2=1 -s DEFAULT_TO_CXX=1 ... -std=c++20 .../emdawnwebgpu_pkg/webgpu/src/webgpu.cpp
"...\\\uno.winui.runtime.skia.webassembly.browser\6.7.103\build\native/uno_gl_shim.c"-s DEFAULT_TO_CXX=1 does not help, because the .c extension still selects C as the input language for that translation unit.
It looks intermittent
The error only occurs when both sources are compiled in the same invocation. One clean build linked fine (the shim had already been compiled to an object), and every incremental build afterwards failed. So it can pass once and then fail consistently, which reads as flakiness rather than a hard incompatibility.
Dropping the flag is not an option
webgpu.cpp genuinely needs C++20. Compiling it with identical flags minus -std=c++20:
webgpu.cpp:1640:14: error: no member named 'span' in namespace 'std'
webgpu.cpp:1841:12: error: no template named 'span' in namespace 'std'Possible fixes
Either side can resolve this, and since Uno co-maintains SkiaSharp you are better placed than me to judge which is right:
- Uno side: ship
uno_gl_shimas C++ (or precompile it to an object), so no C translation unit is present in a link that other packages may add C++ flags to. The shim is 80 lines and compiles cleanly as C++20 as-is; I verified that before using it as a workaround. - SkiaSharp side: compile
webgpu.cppto an object or static library inside the package's own targets and pass that to the link, instead of putting the source plus-std=c++20intoEmccExtraLDFlags. Object inputs carry no language, so nothing leaks onto other packages' sources. This is the more general fix, since-std=in a shared flags property breaks any package contributing a C source, not just Uno's.
Happy to open the corresponding issue on the SkiaSharp repo instead, or as well, if you would rather track it there.
Workarounds
Opt out of the Dawn backend, falling back to emscripten's built-in WebGPU:
<PropertyGroup> <_SkiaSharpUseEmdawnwebgpu>false</_SkiaSharpUseEmdawnwebgpu> </PropertyGroup>Keep Dawn and hand
emcca.cppcopy of the shim (_UnoAdjustCompatibilityis the Uno.Wasm.Bootstrap target that mapsWasmShellNativeCompileintoNativeFileReference):<Target Name="CompileUnoGlShimAsCxx" BeforeTargets="_UnoAdjustCompatibility" Condition="$(TargetFramework.Contains('browserwasm'))"> <ItemGroup> <_UnoGlShimSource Include="@(WasmShellNativeCompile)" Condition="'%(Filename)%(Extension)' == 'uno_gl_shim.c'" /> </ItemGroup> <Copy SourceFiles="@(_UnoGlShimSource)" DestinationFiles="$(IntermediateOutputPath)uno_gl_shim.cpp" SkipUnchangedFiles="true" Condition="'@(_UnoGlShimSource)' != ''" /> <ItemGroup Condition="'@(_UnoGlShimSource)' != ''"> <WasmShellNativeCompile Remove="@(_UnoGlShimSource)" /> <WasmShellNativeCompile Include="$(IntermediateOutputPath)uno_gl_shim.cpp" Visible="false" /> </ItemGroup> </Target>
Both produce a working build; the second keeps the Dawn backend enabled.
For what it's worth, on our app the two backends perform indistinguishably, which is expected given the WebAssembly head renders through WebGL (-s USE_WEBGL2=1, uno_gl_shim.c) rather than WebGPU. So opting out costs nothing today, but it will matter once the WebGPU path is actually used.
Source: unoplatform/uno