Microsoft's CoreRT turns C# into cross-platform C++

Want to run .Net applications on platforms with no .Net framework? Microsoft's brewing up a way to do so by translating C# apps into platform-native C++ counterparts

Microsoft is slowly changing the .Net toolchain to allow ahead-of-time compilation for applications on platforms where there is no .Net toolchain.

The open source CoreRT project does away with using .Net's standard Command Line Runtime (CLR) to run applications. Instead, it generates C++ code from a given .Net C# app's code, which can then be compiled and linked on any target platform that supports C++.

In a post on Microsoft's AlphaGeek development blog, Microsoft briefly laid out its plans for how CoreRT will work, along with its rationale for creating it.

"If I really want to write some C# code and have it 'just work' on a new IoT device," wrote Microsoft, "I don’t have any options until the RyuJIT is capable of generating machine code that works with that processor and operating system." By cross-compiling C# to C++, .Net developers can then deliver their applications without needing to wait for .Net to be deployed on a given platform, says Microsoft.

Microsoft noted it had made some significant process toward this goal over the course of the year, although it acknowledged that the task is easier said than done. The most prominent problem is common to projects that involve transpiling one language into another. C++ and .Net do not have a one-to-one correspondence between their features -- the syntax, the data structures, the language logic, and so on. Therefore, CoreRT has to elegantly map certain .Net features into C++.

One other major project that transpiles a language into C++ to speed its execution is Nuitka, which converts Python programs into C++. Nuitka is an ongoing project that faces many of the same issues as CoreRT and has perhaps an even tougher time reconciling them. Python's dynamic nature makes it difficult to convert into an ahead-of-time compiled language, since every construction in the language is potentially an object with highly mutable properties. C# is less problematic from that standpoint, since it uses static typing for variables, but as noted above, it still comes with a host of difficulties.

There's a lot about CoreRT that descends directly from Microsoft's ongoing realignment around open source and popular non-Microsoft technologies. But Microsoft has always been pragmatic about why it does this, and here the pragmatism is about seeing how .Net applications can run on platforms and in ecosystems that previously didn't support them.

CoreRT can theoretically broaden the reach of the .Net ecosystem without Microsoft having to make undue effort. It's easier to write a one-time transpilation system from C# to C++ than it is to create runtimes for any number of other target platforms. Sure, third parties can create such runtimes thanks to .Net now being an open source concern. But Microsoft's plan is to find one way to save them -- and itself -- the trouble.

Copyright © 2016 IDG Communications, Inc.