SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG] wasm-ld : error : --shared-memory is disallowed by libskia.SkOpts.o because it was not compiled with 'atomics' or 'bulk-memory' features.

Open Maxxen opened this issue 2 years ago • 5 comments

Description

Hey! Im trying to use SkiaSharp in combination with <WasmEnableThreads>true</WasmEnableThreads>, but I get the following error(s):

wasm-ld : error : --shared-memory is disallowed by libskia.SkOpts.o because it was not compiled with 'atomics' or 'bulk-memory' features.
wasm-ld : error : <....>/obj/Debug/net8.0/wasm/for-build/pinvoke.o: undefined symbol: InterceptGLObject
...

I do get the -msimd128 flag passed way down the end though.

It seems like a similar issue has been solved previously (https://github.com/mono/SkiaSharp/pull/2286), although I have not been able to get it working either on net7 + 2.88.4 or on the latest net8 RC1 and 2.88.6-preview, so Im not sure this is a regression. As it seems like others are also still running into this I'm guessing this never worked completely in the first place? Is there some flag I need to pass in <EmccExtraCFlags> or <EmccExtraLDFlags>?

My IDE is Rider.

Code

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <WasmBuildNative>true</WasmBuildNative>
    <RunAOTCompilation>true</RunAOTCompilation>
    <WasmEnableThreads>true</WasmEnableThreads>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.1.23421.29" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-rc.1.23421.29" PrivateAssets="all" />
    <PackageReference Include="Microsoft.NET.WebAssembly.Threading" Version="8.0.0-rc.1.23419.4" />
    <PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.6-preview.1.2" />
    <PackageReference Include="SkiaSharp.Views.Blazor" Version="2.88.6-preview.1.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\Project.Shared.csproj" />
  </ItemGroup>

</Project>

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

Other (Please indicate in the description)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Other (Please indicate in the description)

Platform / Operating System

macOS

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Maxxen avatar Sep 18 '23 18:09 Maxxen

Thanks for reporting this. I believe it is because we are including the wrong build of libSkiaSharp in your multi-threading blazor app.

I have some PRs to fix it, but for now, adding this to the csproj will/should fix it. I just typed this, so let me know:

<ItemGroup>
  <!-- remove all previous native files -->
  <NativeFileReference Remove="@(SkiaSharpStaticLibrary)" />
  <!-- include the multi-threaded build if WasmEnableThreads=true -->
  <NativeFileReference Include="$(SkiaSharpStaticLibraryPath)\3.1.34\mt\*.a" Condition="'$(WasmEnableThreads)' == 'True'" />
  <!-- otherwise use the single threaded build -->
  <NativeFileReference Include="$(SkiaSharpStaticLibraryPath)\3.1.34\st\*.a" Condition="'$(WasmEnableThreads)' != 'True'" />
</ItemGroup>

mattleibow avatar Sep 18 '23 21:09 mattleibow

Thanks for the quick reply! The workaround you posted seems to work - it compiles at least, so I'm guessing its all good!

Also just want to say thanks for all the work you guys are doing on this, I've tried to work with SKIA natively previously so I have a lot of respect for anybody capable to deal with it efficiently and Im super stoked for all the possibilities this enables. Kudos!

Maxxen avatar Sep 18 '23 21:09 Maxxen

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

ghost avatar Sep 22 '23 22:09 ghost

How are you currently running things? I have a new project and added:

<WasmEnableThreads>true</WasmEnableThreads>
<WasmBuildNative>true</WasmBuildNative>

But I am getting errors:

MONO_WASM: Assert failed: Expect to have one js-module-threads asset in resources

mattleibow avatar Mar 01 '24 18:03 mattleibow

Seems that most of this does not work in .NET 8 Blazor, and things are coming to .NET 9. I will fix this so we are ready for net9.0

mattleibow avatar Mar 01 '24 20:03 mattleibow