Skip to content

MichalStrehovsky/zerosharp

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

* Update ZeroSharp to .NET 7

With runtime does not working, since it missing some bits
```
 (Code generation failed for method '[Test.CoreLib]System.Runtime.RuntimeExports.RhUnboxNullable(uint8&,MethodTable*,object)') (Code generation failed
  for method '[Test.CoreLib]System.Runtime.RuntimeExports.RhGetCurrentThreadStackTrace(native int[])') (Code generation failed for method '[Test.CoreLib]System.Runtime.EH.RhThrowEx(object,ExInfo&)') (Code gen
  eration failed for method '[Test.CoreLib]System.Runtime.TypeCast.CheckCastInterface(MethodTable*,object)') (Code generation failed for method '[Test.CoreLib]System.Runtime.TypeCast.CheckCast(MethodTable*,ob
  ject)') (Code generation failed for method '[Test.CoreLib]System.Runtime.TypeCast.StelemRef(Array,int32,object)') (Code generation failed for method '[Test.CoreLib]System.Runtime.CachedInterfaceDispatch.Rhp
  ResolveInterfaceMethod(object,native int)') (Code generation failed for method '[Test.CoreLib]System.Runtime.RuntimeExports.RhTryGetThunkData(object,native int,native int&,native int&)')
     ---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[Test.CoreLib]System.Runtime.RuntimeExports.RhUnboxNullable(uint8&,MethodTable*,object)'
   ---> System.InvalidOperationException: Expected type 'System.RuntimeType' not found in module 'Test.CoreLib'
```

* Nits

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
fd4a7b7

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

C# for systems programming

These samples show how to compile C# to native code using the .NET Native AOT technology (NativeAOT, also known as CoreRT previously).

The samples are for people who would like to use C#, but don't want to be bound by the choices of the base class libraries that normally come with C# (in the form that it's bundled in .NET). If you just want to native compile your .NET apps, go to the NativeAOT repo/branch instead. Nothing to see for you in this repo.

no-runtime is a rather pointless sample that demonstrates how to write code in C# that is directly runnable without a runtime. C# has value types and you can p/invoke into an unmanaged memory allocator, so you can do things with this, but you're so severily limited it's rather pointless. But Hello world ends up being about 8 kB native EXE with no dependencies, so that's rather cool.

with-runtime is something that can be actually useful. This includes the full managed and unmanaged runtime - GC, exception handling, and interface dispatch all work. Test.CoreLib used as the class library here is the same Test.CoreLib that you can find in the NativeAOT repo. Don't look for things like Object.ToString() because being compatible with .NET is not the point. This sample comes down to about 400 kB, most of which is the C runtime library.

efi-no-runtime is an EFI boot application that lets you run C# on bare metal, without an OS. Similar restrictions to the no-runtime sample apply. Making a version of this sample with a runtime would require some porting work on the runtime side.

Building the samples

.NET 7 SDK is a prerequisite for building these on all platforms.

In addition to the .NET 7 SDK, these are needed:

  • On Windows: Visual Studio 2022 with C++ development support and a Windows SDK
  • On Linux: clang
  • On macOS (untested): XCode

One you made sure you have the prerequisites, enter the appropriate sample directory and type:

$ dotnet publish -c Release

Some samples also come with a shell script (*.cmd) that pieces together all the tools and avoid MSBuild or dotnet. You need to make sure you have environment set up before running the script. Look at the script for details. The script is redundant with the *.csproj project files.

About

Demo of the potential of C# for systems programming with the .NET native ahead-of-time compilation technology.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •