Code Monkey home page Code Monkey logo

zerosharp's Introduction

C# for systems programming

These samples show how to compile C# to native code using a minimalist .NET runtime (CoreRT).

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 4-5 kB native EXE, 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 CoreRT 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

There are some prerequisites for running the build scripts:

  • A CoreRT drop
  • Visual Studio 2017 with C++ support and a Windows SDK

You can run these without building CoreRT yourself. Just point the DROPPATH environment variable to the ILCompiler package in your NuGet package cache (if you ever played with using CoreRT, it will be somewhere like C:\Users\{user}\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\1.0.0-alpha-27402-01). If you haven't tried CoreRT for your normal .NET Core projects yet, go try it out, it's cool. Alternatively, clone the CoreRT GitHub project and build it yourself (more prerequisites apply - see that repo for instructions). Once you have a local build of CoreRT, the DROPPATH to use will be something like D:\git\rt\bin\Windows_NT.x64.Debug.

The build.cmd script needs to be executed from a "x64 Native Tools Command Prompt for VS 2017" - it's in your Start menu. Also make sure DROPPATH is set as above.

zerosharp's People

Contributors

michalstrehovsky avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.