danipen / TextMateSharp

A port of tm4e to bring TextMate grammars to dotnet ecosystem
MIT License
87 stars 15 forks source link

[WIP] Use Task.Run instead ThreadPool.QueueUserWorkItem #18

Closed danipen closed 1 year ago

danipen commented 2 years ago

Fixes #9

danipen commented 1 year ago

Some progress. I was able to have a working POC: avaloniaedit-wasm

I basically compiled oniguruma using emcc:

autoreconf -vfi
emconfigure ./configure
emmake make

and included the native references into the WebAssembly project as NativeFileReference.

<ItemGroup>
    <NativeFileReference Include="libonig.a" />
    <NativeFileReference Include="onigwrap.c" />
</ItemGroup>

However, I have no idea about how to generate a nuget for TextmateSharp supporting wasm.

Issues:

Numpsy commented 1 year ago

However, I have no idea about how to generate a nuget for TextmateSharp supporting wasm.

I'm a total beginner with web assembly so I can't speak from experience, but there are a few docs at https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies?view=aspnetcore-6.0#package-native-dependencies-in-a-nuget-package about how it might be done, and I've seen mention elsewhere of using the 'browser-wasm' identifier to include the binaries in a nuget package.

From the links on tha MS article, there is a 'SkiaSharp.NativeAssets.WebAssembly' package that contains the Wasm build of Skia, and a 'SkiaSharp.Views.Blazor' which contains MSBuild files which add the 'NativeFileReference' entries for the .a files, which might be an example of how the properties can be set up?

danipen commented 1 year ago

Yes, I tried this here, with no luck. Not sure if here I need to add the .wasm or the .a file in the nuget.

Numpsy commented 1 year ago

There's a note in that MS documentation that says

Prebuilt dependencies typically must be built using the same version of Emscripten used to build the .NET WebAssembly runtime.

So I don't know if distributing the .wasm file is safe there?

For (2), Can you put a TextMateSharp.props file inside the 'build' directory in the nuget package which contains the NativeFileReference item? e.g. in The SkiaSharp/Blazor package it has:

image

(However, I'm not sure what the conditions and such should be to control when it's included)

danipen commented 1 year ago

So it seems I need to ship these two files in the nuget...

libonig.a
onigwrap.c

I only need to ship them for browser-wasm platform ...and I need to include as NativeFileReference for the project being built.

Honestly...im not sure about the syntax to do that docs are not very verbose.

danipen commented 1 year ago

@Numpsy good news! I got it working here! https://github.com/danipen/TextMateSharp/pull/36

danipen commented 1 year ago

I'll discard this PR.

danipen commented 1 year ago

For the threading issue, it seems that is going to be supported in .net 7 via WasmEnableThreads ...

<PropertyGroup>
  <WasmEnableThreads>true</WasmEnableThreads>
</PropertyGroup>

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-rc-2/#webassembly-multithreading-experimental