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

Blazor wasm dynamic linking native sidemodules #75257

Open
1 task done
Hazardu opened this issue Sep 8, 2022 · 12 comments
Open
1 task done

Blazor wasm dynamic linking native sidemodules #75257

Hazardu opened this issue Sep 8, 2022 · 12 comments
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono os-browser Browser variant of arch-wasm
Milestone

Comments

@Hazardu
Copy link

Hazardu commented Sep 8, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to link a C++ library compiled with Emscripten to a Blazor wasm application, and use pinvoke. Thus far, the only way to link the two is to use static linking via NativeFileReference, but emcc contains functionality to dynamically link side modules and a main module.

Comparing the generated JS in an app where both the lib and main app are written in C++ to one with Blazor Wasm and NativeFileReference, it seems that the code responsible for loading the functions into the Module object is missing, thus when the app tries to call them when they are uninitialized and abort is called and the whole thing breaks.

Trying a different approach of statically linking a part of the C++ code containing C wrapper functions that are PInvoked and dynamically linking the C++ class that is wrapped, the same issue happened after the C function reached a function call.

Describe the solution you'd like

NativeFileReference other than accepting relocatable wasm files for static linking, would accept native libs compiled with Emscripten's SIDE_MODULE flag and expand the generated javascript to load them at loadtime.

Additional context

https://github.com/Devsh-Graphics-Programming/GPU-With-C-Sharp-Angular-WASM
Thus far this app is on the small end, but we are considering making a robust native wasm library that contains the Nabla engine. For that dynamic linking is preferable.

Emscripten doc
https://emscripten.org/docs/compiling/Dynamic-Linking.html

@javiercn javiercn transferred this issue from dotnet/aspnetcore Sep 8, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 8, 2022
@marek-safar marek-safar added the arch-wasm WebAssembly architecture label Sep 8, 2022
@ghost
Copy link

ghost commented Sep 8, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to link a C++ library compiled with Emscripten to a Blazor wasm application, and use pinvoke. Thus far, the only way to link the two is to use static linking via NativeFileReference, but emcc contains functionality to dynamically link side modules and a main module.

Comparing the generated JS in an app where both the lib and main app are written in C++ to one with Blazor Wasm and NativeFileReference, it seems that the code responsible for loading the functions into the Module object is missing, thus when the app tries to call them when they are uninitialized ad abort is called and the whole thing breaks.

Trying a different approach of statically linking a part of the C++ code containing C wrapper functions that are PInvoked and dynamically linking the C++ class that is wrapped, the same issue happened after the C function reached a function call.

Describe the solution you'd like

NativeFileReference other than accepting relocatable wasm files for static linking, would accept native libs compiled with Emscripten's SIDE_MODULE flag and expand the generated javascript to load them at loadtime.

Additional context

https://github.com/Devsh-Graphics-Programming/GPU-With-C-Sharp-Angular-WASM
Thus far this app is on the small end, but we are considering making a robust native wasm library that contains the Nabla engine. For that dynamic linking is preferable.

Author: Hazardu
Assignees: -
Labels:

arch-wasm, untriaged

Milestone: -

@radical
Copy link
Member

radical commented Sep 8, 2022

cc @radekdoulik @pavelsavara @SteveSandersonMS @kg

@radical radical added this to the 8.0.0 milestone Sep 8, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 8, 2022
@lewing lewing modified the milestones: 8.0.0, 9.0.0 Jul 24, 2023
@BenMcLean
Copy link

BenMcLean commented May 22, 2024

I could be wrong here but it looks like this is the primary issue blocking Godot 4 and Stride and MonoGame and probably most / any other FOSS game engines / frameworks that support scripting in C# from building programs for WebAssembly on .NET Core 5+. It would be nice for it to get more attention.

@GeorgeS2019
Copy link

@BenMcLean

this is the primary issue blocking Godot 4 from building programs for WebAssembly on .NET Core 5+.

Will godot-dotnet helps to resolve this?

@BenMcLean
Copy link

@BenMcLean

this is the primary issue blocking Godot 4 from building programs for WebAssembly on .NET Core 5+.

Will godot-dotnet helps to resolve this?

Possibly. I'm not sure the Godot team would accept such a PR as I don't think embedding Godot as a library is something they even want to support, but if they will then that would be great.

@GeorgeS2019
Copy link

GeorgeS2019 commented May 29, 2024

@BenMcLean
https://chat.godotengine.org/channel/dotnet?msg=ow94ZyspFmyvvzGYh

There's also ongoing work on the .NET runtime to use a new NativeAOT-LLVM runtime for the web platform which may solve our problem, but it's very early and very experimental. Not sure how much of this will make it to .NET 9.0.

Anyone can share links to NativeAOT-LLVM?

Found

https://github.com/dotnet/runtimelab/tree/feature/NativeAOT-LLVM

https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net8plus%2Cwindows
image

@Delsin-Yu
Copy link

@GeorgeS2019

Will godot-dotnet helps to resolve this?

No, It won't.

@lewing lewing modified the milestones: 9.0.0, Future Jul 30, 2024
@BenMcLean
Copy link

BenMcLean commented Aug 15, 2024

@lewing Why did this get pushed into the indefinite future?

Seems like this one and also dotnet/aspnetcore#17730 are really important.

@lewing
Copy link
Member

lewing commented Aug 17, 2024

The limitations of emscripten's dynamic linking have made it quite challenging for us to use in practice. Can you explain in more detail what problem you are attempting to solve? We use feedback to help prioritize work.

As for browser-wasm threading it is functional and you can try in out in recent net9.0 previews, but only the runtime side and that will remain experimental in net9. The Blazor front end work as indicated in dotnet/aspnetcore#17730 is part of the planning for net10.

cc @danroth27

@BenMcLean
Copy link

BenMcLean commented Aug 17, 2024

This comment here offered an explanation of how lack of dynamic linking native sidemodules prevents Godot 4 from supporting WASM export for C# scripted projects: godotengine/godot#70796 (comment)

I believe Stride has a similar issue although I can't find it at the moment.

@JeroMiya
Copy link

I'm not an expert on the internals of Stride, but I don't believe this issue affects Stride, at least not in the same way as Godot. Web export doesn't exist yet in Stride, but if it were implemented similarly to the Desktop projects, the C# assembly is the main entry point into the application. Stride itself is a NuGet package you reference in your platform specific project. So theoretically, a WASM export should be possible - I think the missing piece is stable WebGL/WebGPU bindings for WASM/.NET, and of course developer resources to actually implement the web export functionality.

I think the Godot-as-library route is probably the best route for that engine, not just for WASM but also for more robust iOS/Android support and likely console support as well.

@pavelsavara pavelsavara added the os-browser Browser variant of arch-wasm label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

10 participants