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

Developers can AOT compile .NET apps into WebAssembly format #44316

Closed
12 of 15 tasks
Tracked by #5466 ...
marek-safar opened this issue Nov 5, 2020 · 18 comments
Closed
12 of 15 tasks
Tracked by #5466 ...

Developers can AOT compile .NET apps into WebAssembly format #44316

marek-safar opened this issue Nov 5, 2020 · 18 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Meta Cost:XL Work that requires one engineer more than 4 weeks Priority:0 Work that we can't release without User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@marek-safar
Copy link
Contributor

marek-safar commented Nov 5, 2020

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

@marek-safar marek-safar added User Story A single user-facing feature. Can be grouped under an epic. Priority:0 Work that we can't release without Cost:XL Work that requires one engineer more than 4 weeks labels Nov 5, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

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.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Nov 5, 2020
@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Nov 5, 2020
@marek-safar marek-safar changed the title User Story: Developers can compile .NET apps into WebAssembly format User Story: Developers can AOT compile .NET apps into WebAssembly format Nov 5, 2020
@ghost
Copy link

ghost commented Nov 6, 2020

Tagging subscribers to this area: @CoffeeFlux
See info in area-owners.md if you want to be subscribed.

@marek-safar marek-safar added this to the 6.0.0 milestone Nov 10, 2020
@marek-safar marek-safar changed the title User Story: Developers can AOT compile .NET apps into WebAssembly format .NET Developers can AOT compile .NET apps into WebAssembly format Nov 25, 2020
@danmoseley danmoseley changed the title .NET Developers can AOT compile .NET apps into WebAssembly format Developers can AOT compile .NET apps into WebAssembly format Dec 1, 2020
@baktun14
Copy link

Is it possible compile a .net library to WebAssembly without blazor?

@jeromelaban
Copy link
Contributor

@mbeauchamp7 what do you intend to do with it ? (e.g. Make an NPM package out of it)

@ChristianWeyer
Copy link

Is it possible compile a .net library to WebAssembly without blazor?

Have you seen this?
https://github.com/unoplatform/Uno.Wasm.Bootstrap

@baktun14
Copy link

Is it possible compile a .net library to WebAssembly without blazor?

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.

Have you seen this?
https://github.com/unoplatform/Uno.Wasm.Bootstrap

Yes I tried to use it but didn't seem very stable and was getting compilation errors.

@jeromelaban
Copy link
Contributor

@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 ?

@baktun14
Copy link

@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)!

@legistek
Copy link

Is it possible compile a .net library to WebAssembly without blazor?

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 Program.Main and do your own thing. So it certainly should be possible with AOT also, but your final compiled WASM might be unnecessarily bloated.

@ChristianWeyer
Copy link

Is it possible compile a .net library to WebAssembly without blazor?

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 Program.Main and do your own thing. So it certainly should be possible with AOT also, but your final compiled WASM might be unnecessarily bloated.

Interesting. Would you have a simple sample of this available?
Thanks.

@legistek
Copy link

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 Program.Main and do your own thing.

In index.html just make sure you keep
<script src="_framework/blazor.webassembly.js"></script>

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.

@microhobby
Copy link
Contributor

It would be really cool to be able to compile .NET console application to WASI

@h3x4d3c1m4l
Copy link

h3x4d3c1m4l commented Jul 16, 2021

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.

@jeffhandley jeffhandley added the arch-wasm WebAssembly architecture label Aug 11, 2021
@ghost
Copy link

ghost commented Aug 11, 2021

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

Issue Details

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

Author: marek-safar
Assignees: lewing
Labels:

arch-wasm, area-Meta, User Story, Priority:0, Cost:XL

Milestone: 6.0.0

@charlesroddie
Copy link

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.

@bilalchraibi
Copy link

@danroth27 Since this user story is marked as completed, do you have any preliminary documentation that we can have use to get started?

@danroth27
Copy link
Member

@bilalchraibi We have some initial docs here: https://docs.microsoft.com/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-6.0#ahead-of-time-aot-compilation

@bilalchraibi
Copy link

@danroth27 Thank you!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Meta Cost:XL Work that requires one engineer more than 4 weeks Priority:0 Work that we can't release without User Story A single user-facing feature. Can be grouped under an epic.
Projects
No open projects
Development

No branches or pull requests