The Rust compiler backend for .NET can now compile std with (numerous) errors, and supports allocation (Box, Vec, String, etc.)

58 points FractalFir

After adding support for statics and many bug fixes related to pointers/slices, my compiler backend targeting .NET can finally build a barely working version of the standard library.
It can be loaded into the .NET runtime, allocate memory (e.g. for a Box, Vec or String), push elements to Vec's and String's (currently without relocations). There are also some other parts of the standard library that already work, but I want to stress that the project is still fairly early into development (I started working on it late August), and you should expect most things in std to not work at all. Things working is the exception, not the rule.
This newest set of commits allows you to use a small subset of the standard library, within code running inside the .NET runtime.
|
Here is some Rust code that I wrote to demo the ability to use the Rust std within the .NET runtime:

Example code

And here is the result of running it within the .NET runtime:

Result of creating a Rust std::string::String at runtime, within the .NET runtime, and then calling \puts\\ to print it.

While the project is still far from being usable, I thought this might be a nice update to share.

KNOWN ISSUES:
One of the fields of core::time::Nanosecods somehow evades field name escape, and may cause the resulting .il file to not assemble into a .NET executable. In such case, open the .il file, replace all mentions of ::0 with ::m_0, and then run ilasm to assemble the .il file.

Drops are buggy and cause the assembled test program to crash shortly after printing the message.

The backend is relatively slow. When building any example which uses std, give it a minute or two to finish.

Technically speaking, Vec, Box, and String are within the alloc crate. However, std did not build at all before, so it building at all is progress. Additionally, there are some other std APIs that work to some degree, so I decided to treat this as "some parts of std work", and not bring up the distinction between alloc and std.