-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Developers can AOT compile .NET apps into WebAssembly format #44316
Comments
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. |
Tagging subscribers to this area: @CoffeeFlux |
Is it possible compile a .net library to WebAssembly without blazor? |
@mbeauchamp7 what do you intend to do with it ? (e.g. Make an NPM package out of it) |
Have you seen this? |
I want to reuse some logic done in c# but in the browser. I would like to have a static .wasm file that I can simply load with an http request and communicate with it's exposed methods afterwards, something like sql.js is doing.
Yes I tried to use it but didn't seem very stable and was getting compilation errors. |
@mbeauchamp7 it's not yet possible to create a single wasm file at this point, because of the way emscripten works. There's also a bit packaging work that is needed to be done in the .NET side. As for the uno.wasm.bootstrap package, I'm the author and I'm interested in the errors you got. If you have a chance, can you open an issue with your errors ? |
@jeromelaban Thanks for the info, I will try to reproduce the errors as I did get it to compile properly in visual studio. The errors I got was when I started, I was reading an older blog post that was setting an older version of the nuget package (1.1.0-dev.426) and building it with the command line, it was saying something along the lines of "WSL missing something something"... Anyways now it's compiling with version 2.0.0-dev.69(nice)! |
I would definitely use Uno Bootstrapper but just note that even today without AOT you can make an interpreted Mono WASM project using the Blazor template, Blazor bootstrapper and Javascript interop without actually making a full blown Blazor app. Just get rid of everything in |
Interesting. Would you have a simple sample of this available? |
I don't, but just create a Blazor app using the default template, and then remove everything from In Just note that you won't be able to use Blazor's Javascript interop classes directly because they depend on injection and the stuff you need is all internal. Instead you can easily cannibalize from the Blazor source code, e.g., https://github.com/dotnet/aspnetcore/blob/52eff90fbcfca39b7eb58baad597df6a99a542b0/src/Components/WebAssembly/JSInterop/src/InternalCalls.cs#L13. |
It would be really cool to be able to compile .NET console application to WASI |
At the moment, we have a situation where we might want to generate PDF reports using WebAssembly. Specifically WebAssembly as that seems to be the easiest way of integrating .NET in our existing solution. We already found the PDF generation library we are familiar with to be working perfectly fine in AoT compiled Blazor. It runs even faster than we expected beforehand and even with minimal code changes. For this specific situation it would be optimal if we could convert our Blazor PoC to a wasm library that can be run by a CLI based runner (for testing) or a WASM runtime library (for production). It does seem almost all parts of this puzzle are there already, it just seems there is currently no convenient way to compile a .NET console app or .NET library to WASM. It could be incredible helpful functionality to be able to use .NET in more platforms using WASM There are native solutions which we could use for PDF report generation, but this specific .NET/WASM solution would be almost optimal for us in terms of code sharing between platforms and solutions and utilizing technologies we are already very familiar with. |
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsAs more applications target .Net in the Browser there is a growing demand to support workloads that require additional performance. The .NET5 browser-wasm runtime supports only interpreted mode and can considerably underperform in performance-sensitive code paths. Large performance gains can be realized by compiling the code ahead of time (AOT) rather than interpreting it. Performance, size, and other considerations dictate that the AOT compilation step should run after assemblies have been aggressively trimmed. This will require that additional tooling be installed on the developer's machine when targeting AOT, including native and managed cross compilers appropriate for their host environment (emscripten SDK and mono AOT). AOT compilation also typically generates much less compact code than the original IL. To avoid prohibitively large assets, we will likely need to offer a mode of operation where performance critical code is AOT compiled and the remaining code is interpreted. Work Items
|
This issue Blazor AOT .Net6 Preview 7 - Still downloading Dlls suggests that full AOT is not complete and that what is currently called AOT by blazor is a mixed-mode AOT. |
@danroth27 Since this user story is marked as completed, do you have any preliminary documentation that we can have use to get started? |
@danroth27 Thank you! |
As more applications target .Net in the Browser there is a growing demand to support workloads that require additional performance. The .NET5 browser-wasm runtime supports only interpreted mode and can considerably underperform in performance-sensitive code paths. Large performance gains can be realized by compiling the code ahead of time (AOT) rather than interpreting it.
Performance, size, and other considerations dictate that the AOT compilation step should run after assemblies have been aggressively trimmed. This will require that additional tooling be installed on the developer's machine when targeting AOT, including native and managed cross compilers appropriate for their host environment (emscripten SDK and mono AOT).
AOT compilation also typically generates much less compact code than the original IL. To avoid prohibitively large assets, we will likely need to offer a mode of operation where performance critical code is AOT compiled and the remaining code is interpreted.
Work Items
The text was updated successfully, but these errors were encountered: