Skip to content

Commit 393b755

Browse files
authored
fix(wasm): Enable Wasm EH and SIMD in all configurations for net8+ (#2495)
1 parent 2e722cc commit 393b755

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

native/wasm/build.cake

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ Task("libSkiaSharp")
2323
.WithCriteria(IsRunningOnLinux())
2424
.Does(() =>
2525
{
26-
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd");
26+
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd") || EMSCRIPTEN_FEATURES.Contains("_simd");
2727
bool hasThreadingEnabled = EMSCRIPTEN_FEATURES.Contains("mt");
28+
bool hasWasmEH = EMSCRIPTEN_FEATURES.Contains("_wasmeh");
29+
30+
var emscriptenFeaturesModifiers =
31+
EMSCRIPTEN_FEATURES
32+
.Where(f => !f.StartsWith("_"))
33+
.ToArray();
2834

2935
GnNinja($"wasm", "SkiaSharp",
3036
$"target_os='linux' " +
@@ -63,9 +69,10 @@ Task("libSkiaSharp")
6369
$" '-s', 'WARN_UNALIGNED=1' " + // '-s', 'USE_WEBGL2=1' (experimental)
6470
$" { (hasSimdEnabled ? ", '-msimd128'" : "") } " +
6571
$" { (hasThreadingEnabled ? ", '-pthread'" : "") } " +
72+
$" { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } " +
6673
$"] " +
6774
// SIMD support is based on https://github.com/google/skia/blob/1f193df9b393d50da39570dab77a0bb5d28ec8ef/modules/canvaskit/compile.sh#L57
68-
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } ] " +
75+
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } ] " +
6976
COMPILERS +
7077
ADDITIONAL_GN_ARGS);
7178

@@ -99,8 +106,8 @@ Task("libSkiaSharp")
99106
var outDir = OUTPUT_PATH.Combine($"wasm");
100107
if (!string.IsNullOrEmpty(EMSCRIPTEN_VERSION))
101108
outDir = outDir.Combine("libSkiaSharp.a").Combine(EMSCRIPTEN_VERSION);
102-
if (EMSCRIPTEN_FEATURES.Length != 0)
103-
outDir = outDir.Combine(string.Join(",", EMSCRIPTEN_FEATURES));
109+
if (emscriptenFeaturesModifiers.Length != 0)
110+
outDir = outDir.Combine(string.Join(",", emscriptenFeaturesModifiers));
104111
EnsureDirectoryExists(outDir);
105112
CopyFileToDirectory(a, outDir);
106113
});
@@ -109,24 +116,30 @@ Task("libHarfBuzzSharp")
109116
.WithCriteria(IsRunningOnLinux())
110117
.Does(() =>
111118
{
112-
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd");
119+
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd") || EMSCRIPTEN_FEATURES.Contains("_simd");;
113120
bool hasThreadingEnabled = EMSCRIPTEN_FEATURES.Contains("mt");
121+
bool hasWasmEH = EMSCRIPTEN_FEATURES.Contains("_wasmeh");
122+
123+
var emscriptenFeaturesModifiers =
124+
EMSCRIPTEN_FEATURES
125+
.Where(f => !f.StartsWith("_"))
126+
.ToArray();
114127

115128
GnNinja($"wasm", "HarfBuzzSharp",
116129
$"target_os='linux' " +
117130
$"target_cpu='wasm' " +
118131
$"is_static_skiasharp=true " +
119132
$"visibility_hidden=false " +
120-
$"extra_cflags=[ { (hasSimdEnabled ? "'-msimd128', " : "") } { (hasThreadingEnabled ? "'-pthread'" : "") } ] " +
121-
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } ] " +
133+
$"extra_cflags=[ '-s', 'WARN_UNALIGNED=1' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } ] " +
134+
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } ] " +
122135
COMPILERS +
123136
ADDITIONAL_GN_ARGS);
124137

125138
var outDir = OUTPUT_PATH.Combine($"wasm");
126139
if (!string.IsNullOrEmpty(EMSCRIPTEN_VERSION))
127140
outDir = outDir.Combine("libHarfBuzzSharp.a").Combine(EMSCRIPTEN_VERSION);
128-
if (EMSCRIPTEN_FEATURES.Length != 0)
129-
outDir = outDir.Combine(string.Join(",", EMSCRIPTEN_FEATURES));
141+
if (emscriptenFeaturesModifiers.Length != 0)
142+
outDir = outDir.Combine(string.Join(",", emscriptenFeaturesModifiers));
130143
EnsureDirectoryExists(outDir);
131144
var so = SKIA_PATH.CombineWithFilePath($"out/wasm/libHarfBuzzSharp.a");
132145
CopyFileToDirectory(so, outDir);

scripts/azure-templates-stages.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,19 +405,11 @@ stages:
405405
- 3.1.34:
406406
displayName: 3.1.34
407407
version: 3.1.34
408-
features: st
409-
- 3.1.34:
410-
displayName: '3.1.34_SIMD'
411-
version: 3.1.34
412-
features: simd
408+
features: _wasmeh,_simd,st
413409
- 3.1.34:
414410
displayName: '3.1.34_Threading'
415411
version: 3.1.34
416-
features: mt
417-
- 3.1.34:
418-
displayName: '3.1.34_Threading_SIMD'
419-
version: 3.1.34
420-
features: mt,simd
412+
features: _wasmeh,_simd,mt
421413

422414
- ${{ if ne(parameters.buildPipelineType, 'tests') }}:
423415
- stage: managed

0 commit comments

Comments
 (0)