Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wasm): Enable Wasm EH and SIMD in all configurations for net8+ #2495

Merged
merged 4 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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