Skip to content

Commit

Permalink
fix(wasm): Enable Wasm EH and SIMD in all configurations for net8+ (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban authored Jun 19, 2023
1 parent 2e722cc commit 393b755
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
31 changes: 22 additions & 9 deletions native/wasm/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ Task("libSkiaSharp")
.WithCriteria(IsRunningOnLinux())
.Does(() =>
{
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd");
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd") || EMSCRIPTEN_FEATURES.Contains("_simd");
bool hasThreadingEnabled = EMSCRIPTEN_FEATURES.Contains("mt");
bool hasWasmEH = EMSCRIPTEN_FEATURES.Contains("_wasmeh");

var emscriptenFeaturesModifiers =
EMSCRIPTEN_FEATURES
.Where(f => !f.StartsWith("_"))
.ToArray();

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

Expand Down Expand Up @@ -99,8 +106,8 @@ Task("libSkiaSharp")
var outDir = OUTPUT_PATH.Combine($"wasm");
if (!string.IsNullOrEmpty(EMSCRIPTEN_VERSION))
outDir = outDir.Combine("libSkiaSharp.a").Combine(EMSCRIPTEN_VERSION);
if (EMSCRIPTEN_FEATURES.Length != 0)
outDir = outDir.Combine(string.Join(",", EMSCRIPTEN_FEATURES));
if (emscriptenFeaturesModifiers.Length != 0)
outDir = outDir.Combine(string.Join(",", emscriptenFeaturesModifiers));
EnsureDirectoryExists(outDir);
CopyFileToDirectory(a, outDir);
});
Expand All @@ -109,24 +116,30 @@ Task("libHarfBuzzSharp")
.WithCriteria(IsRunningOnLinux())
.Does(() =>
{
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd");
bool hasSimdEnabled = EMSCRIPTEN_FEATURES.Contains("simd") || EMSCRIPTEN_FEATURES.Contains("_simd");;
bool hasThreadingEnabled = EMSCRIPTEN_FEATURES.Contains("mt");
bool hasWasmEH = EMSCRIPTEN_FEATURES.Contains("_wasmeh");

var emscriptenFeaturesModifiers =
EMSCRIPTEN_FEATURES
.Where(f => !f.StartsWith("_"))
.ToArray();

GnNinja($"wasm", "HarfBuzzSharp",
$"target_os='linux' " +
$"target_cpu='wasm' " +
$"is_static_skiasharp=true " +
$"visibility_hidden=false " +
$"extra_cflags=[ { (hasSimdEnabled ? "'-msimd128', " : "") } { (hasThreadingEnabled ? "'-pthread'" : "") } ] " +
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } ] " +
$"extra_cflags=[ '-s', 'WARN_UNALIGNED=1' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } ] " +
$"extra_cflags_cc=[ '-frtti' { (hasSimdEnabled ? ", '-msimd128'" : "") } { (hasThreadingEnabled ? ", '-pthread'" : "") } { (hasWasmEH ? ", '-fwasm-exceptions'" : "") } ] " +
COMPILERS +
ADDITIONAL_GN_ARGS);

var outDir = OUTPUT_PATH.Combine($"wasm");
if (!string.IsNullOrEmpty(EMSCRIPTEN_VERSION))
outDir = outDir.Combine("libHarfBuzzSharp.a").Combine(EMSCRIPTEN_VERSION);
if (EMSCRIPTEN_FEATURES.Length != 0)
outDir = outDir.Combine(string.Join(",", EMSCRIPTEN_FEATURES));
if (emscriptenFeaturesModifiers.Length != 0)
outDir = outDir.Combine(string.Join(",", emscriptenFeaturesModifiers));
EnsureDirectoryExists(outDir);
var so = SKIA_PATH.CombineWithFilePath($"out/wasm/libHarfBuzzSharp.a");
CopyFileToDirectory(so, outDir);
Expand Down
12 changes: 2 additions & 10 deletions scripts/azure-templates-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,11 @@ stages:
- 3.1.34:
displayName: 3.1.34
version: 3.1.34
features: st
- 3.1.34:
displayName: '3.1.34_SIMD'
version: 3.1.34
features: simd
features: _wasmeh,_simd,st
- 3.1.34:
displayName: '3.1.34_Threading'
version: 3.1.34
features: mt
- 3.1.34:
displayName: '3.1.34_Threading_SIMD'
version: 3.1.34
features: mt,simd
features: _wasmeh,_simd,mt

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

0 comments on commit 393b755

Please sign in to comment.