Comments (3)
At a high level, the NativeAOT toolchain works like so:
- Compile the managed IL into an object file for a particular OS/architecture
- Compile a C++ "bootstrap" source file that provides the actual
main
function - Compile all the C/C++ .NET runtime native libraries (Runtime, System.Globalization.Native, etc.)
- Link all of the above into the final executable
We have our own way of dealing with these steps for consoles, which allows us to reuse most of upstream .NET and not have our own custom forks of dotnet/runtime.
Even for consoles, Part 1 is completely handled by upstream .NET -- we don't need to touch the ILCompiler at all. We just tell it to spit out object files for linux/windows-x64/arm64 (depending on the platform). That's the hardest part taken care of!
Part 2 is also pretty straightforward. For each console, we take the official Bootstrap.cpp and tweak it slightly for any platform-specific idiosyncrasies around initialization.
Part 3 is where it gets interesting. We use as many official .NET source files as we can, and only add/substitute our own when absolutely necessary. The general process is the following:
- Create a VS project for each native library for the given console, using the upstream CMake build system as a guide. (Which files need to be included in the project, what preprocessor definitions need to be set, etc.)
- Attempt to build the project, as-is.
- For each compile error, evaluate what can be done to fix it. Imagine that one of the consoles doesn't support the POSIX function
fread
. In that scenario, we'd need to either create our own versions of each source file that usesfread
and replace it with a console-specific API call, or we can hack infread
support via preprocessor trickery. (#define fread MySpecialFreadFunction
implemented elsewhere in the project.) - Repeat (3) until the project compiles successfully.
Part 4 is similar to Part 3, but focused on linker errors instead.
When there's a new version of .NET, we basically just git pull
the latest .NET release tag and check where we get compile/link errors in the console projects, then update our console code accordingly. The APIs used by .NET native libraries are not stable, so we often have to update a bunch of function signatures to get it to build again. This is not typically a huge effort, just a few days of tedious work.
One thing that's very important to us on the FNA team is that the NativeAOT console projects are shared freely (or, as freely as they can be with NDAs). Ideally, there should be one singular repository for each console that is shared by FNA, MonoGame, Godot, Raylib-CS, and any other interested parties. We're trying to push for that, so we'll see how that goes.
from fna.
Thanks, very interesting stuff!
I'm glad there's finally a good, scalable approach for running C# on consoles
Ideally, there should be one singular repository for each console that is shared by FNA, MonoGame, Godot, Raylib-CS, and any other interested parties. We're trying to push for that, so we'll see how that goes.
I remember reading something similar in the flibitPlan, and I'm very happy this is still the case.
While I don't plan to use FNA for my project, I must admit you do a really good job for the entire C# gamedev community, and I wish you all good luck going forward :)
from fna.
Also, do you know if this approach could be used to possibly port NativeAOT-Mint for consoles when/if it gets out of the experimental phase?
It could be used for many interesting things, and maybe even something close to modding on consoles
from fna.
Related Issues (20)
- Document a stable .NET 7 workflow HOT 5
- Fn HOT 2
- [MojoShader] Preshaders with bool outputs aren't supported HOT 3
- mono_thread_internal_set_priority: unknown policy 5
- Expose FAudioContext or Device Handle HOT 3
- arm64 fnalibs for Apple Silicone Macs HOT 3
- Add GitHub Actions HOT 1
- Terraria: sigsegv when using vulkan renderer in newer versions of FNA HOT 3
- Add DPI Awareness hint for Windows
- Do a second take of #442 HOT 1
- Support for net8.0-ios targets HOT 2
- Incorrect Wiki instructions: Chapter 5 Creating New Projects HOT 1
- SharpFont + SpriteFont HOT 2
- VertexPositionColorNormalTexture HOT 3
- System.NullReferenceException when using BasicEffect HOT 2
- Newer Shader Models
- Add extension method for loading mipmap texture from stream HOT 3
- White artifacts on certain color values in DDS HOT 5
- [BUG] Can't download clone the Wiki HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fna.