This rust compiler backend emmits valid CLR IR, enambling you to use Rust in .NET projects

Overview

What is rustc_codegen_clr?

NOTE: this project is a very early proof-of-concept This is a compiler backend for rustc which targets the .NET platform and runtime, and could enable compiling rust code for the .NET runtime. This would enable you to use some Rust libraries from C#/F#, with little effort.

.NET runtime has GC, so would not Rusts memory management be useless here?

Rust code usually heavily uses stack instead of Heap. This would speed up code ruining within the CLR runtime too. As for the heap allocated objects, they will be allocated from unmanged(non-GC) memory, and will be allocated/freed exactly like in Rust.

I can already load shared libraries from C# code, so is this not useless? Does this improve interop?

The Rust APIs this codegen exposes to C#/F# code would be only slightly easier to use than something you could expose in a .so or .dll rust library.

Interop would still require some effort, but the Rust code would be bundled together with everything else. You will also have the guarantee that types you use from C# are exactly the same as the ones in C#, preventing any issues coming from such mismatch. All types can be safely send between Rust and C#, with exactly the same layout.

Additionally, since all Rust code compiled with this codegen can be bundled with C#/F# code, you would no longer need to ship different versions of the library for different architectures. Any architecture supported by CLR would work out of the box, without the exact same binary.

You also avoid the cost of switches between code running within the runtime and outside it. While this cost is not something unbearable, it is not something you can easily get rid of, and reducing it has some safety penalties associated with. In this case, all code will run inside the runtime, meaning no transition between code running inside runtime and outside of it will occur.

Compiling Rust to CLR is potentially better for the JIT. Since CLR's JIT now "sees" all the code, it can make better decisions regarding optimization, producing faster code.

Licensing

rustc_codegen_clr is dual licensed under MIT license or Apache License, Version 2.0.

Compatibility?

rustc_codegen_clr is tested solely on Linux x86_64. Anything else should, but does not have to work.

How far is the project along:

Functionality

  • Basic functions get translated properly.
  • Arithmetic operations work
  • Most if's work.
  • Basic match works.
  • While loops work.
  • Calls
  • Basic IL optimization.
  • Setting value of a reference
  • Getting value of a reference
  • Creating slices from arrays
  • Creating arrays
  • Indexing arrays broken
  • Getting values of fields
  • Setting fields
  • Pointer dereferecing
  • Basic generics
  • for loops

Types

NOTE This section says only if a type can be translated for .NET to understand. This does not mean the type is fully usable.

  • All integer and float types are supported.
  • Tuples are supported
  • References are supported
  • Arrays, slices
  • Void type
  • Combinations of all of the above.
  • Structs
  • Enums
  • Traits Some, not all
  • iterators

Issues

The backend is still very much untested and may contain a litany of buggs. The backend crashes any time it encounters something not supported yet.

You might also like...
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

๐Ÿ“Œ This program is designed to translate text into the correct layout when typing is incorrect. ๐Ÿ“Œ Example ghbdtn - ะฟั€ะธะฒะตั‚ Just (by default) pressing

ISG lets you use YouTube as cloud storage for ANY files, not just video
ISG lets you use YouTube as cloud storage for ANY files, not just video

I was working on this instead of my finals, hope you appreciate it. I'll add all relevant executables when I can Infinite-Storage-Glitch AKA ISG (writ

Koi is a simple tool built to let you use ChatGPT through the command line

Koi is a simple tool built to let you use ChatGPT through the command line. It adds the ability to let ChatGPT run commands on your computer in order to help you out, or to help you out with complicated tasks.

zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

fas stand for Find all stuff and it's a go app that simplify the find command and allow you to easily search everything you nedd
fas stand for Find all stuff and it's a go app that simplify the find command and allow you to easily search everything you nedd

fas fas stands for Find all stuff and it's a rust app that simplify the find command and allow you to easily search everything you need. Note: current

Shellfirm - Intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification
Shellfirm - Intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification

shellfirm Opppppsss you did it again? ๐Ÿ˜ฑ ๐Ÿ˜ฑ ๐Ÿ˜ฐ Protect yourself from yourself! rm -rf * git reset --hard before saving? kubectl delete ns which going

Dura - You shouldn't ever lose your work if you're using Git

Dura Dura is a background process that watches your Git repositories and commits your uncommitted changes without impacting HEAD, the current branch,

This automatically patches the RoPro extension for you, allowing you to have pro_tier for free.

RoPro Patcher This automatically patches the RoPro extension for you, allowing you to have pro_tier for free. NOTE Chrome, Brave (and possibly other b

Sero is a web server that allows you to easily host your static sites without pain. The idea was inspired by surge.sh but gives you full control.

sero Lightning-fast, static web publishing with zero configuration and full control ๐Ÿ“– Table Of Contents ๐Ÿ“– Table Of Contents ๐Ÿ”ง Tools โ“ About The Pro

Comments
  • Noticed by HN

    Noticed by HN

    Thought you might like to know that you made Hacker News: https://news.ycombinator.com/item?id=37304167

    (There wasn't an email address on your blog, so I figured this was the easiest way to get in touch.)

    opened by andrewducker 2
  • Assembly export API - Classes

    Assembly export API - Classes

    This issue is related to the design of the Assembly Export API, and the new CLI exporter. There will also be a ILASM exporter, created manly for manual debugging. What needs to be supported:

    • [ ] Ability to create a class, derived from some other class. The name of the parent class will be given as a string. Even tough structs always derive from System.ValueType, ability to specify any parent class, will be needed for future interop.
    • [ ] Ability to describe the fields of a class: their names and types.
    • [ ] Fields must allow explicit offset: this is needed for enums.

    What is nice to have, and could potentially help (In order of decreasing importance):

    • [ ] Ability to specify visibility modifiers of a class, such as private/public - makes final assembly cleaner
    • [ ] Member functions - can greatly simplify indexing into arrays and slices, and be used to simplify interop
    • [ ] Support for generic arguments (can be used to reduce amount of CIL required to describe fixed-size array).
    • [ ] Attribute support - could potentially help guide the JIT.
    opened by FractalFir 10
  • Switching to a rust-native CIL emitting API

    Switching to a rust-native CIL emitting API

    Hi! I saw this project on reddit and was very excited; I've been trying to accomplish this exact project before and stalled multiple times due to realizing the amount of work it would require and the potential for failure. However, I was halfway through writing an ECMA-335 compliant CIL ser/de (shorthand, not serde) library on my last attempt. Would you be interested in working together to port this compiler to my own CIL backend, to hopefully achieve better efficiency and maybe even better validation? Not to mention cutting out the need to invoke ILASM or any non-rust dependencies.

    If not, I'd still like to contribute to the project, and might make periodic PRs to improve it in whatever ways I see. I likely won't have a lot of time to dedicate to it any time soon, but I might be able to work on it every now and then.

    opened by PROMETHIA-27 5
  • Cross pollinate ideas

    Cross pollinate ideas

    As on of the developer for C to .NET compiler https://github.com/fornever/cesium I notice that we can/have share potentially same issues when working on FFI with native world/existing libraries. So want to ley you know about our existence.

    I think the only one most interesting thing for you, is how we handle pointers. This is not rocket since obviously, but still open to learn something new from your project too.

    Have a good day, and keep working on cool projects

    opened by kant2002 1
Owner
Young programmer from Poland, interested in writing 3D graphics software and procedural generation
null
Tool written in Rust to enumerate the valid email addresses of an Azure/Office 365 Tenant

AzureEmailChecker Tool written in Rust to enumerate the valid email addresses of an Azure/Office 365 Tenant. It is multi threaded and makes no connect

Pierre 11 Feb 27, 2024
Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed)

imgur_id7 Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed) Optionally uses supplied http pr

Robin Rolf 6 Jun 3, 2023
A simple cli to clone projects and fetch all projects in a GitHub org..

stupid-git A simple cli to clone projects and update all projects. get all repository from GitHub clone all pull all with git stash Usage create sgit.

Fengda Huang 5 Sep 15, 2022
.NET assembly loader with patchless AMSI and ETW bypass in Rust

RustPatchlessCLRLoader The RustPatchlessCLRLoader leverages a sophisticated integration of patchless techniques for bypassing both Event Tracing for W

C2Pain 25 Oct 23, 2024
.NET PhysX 5 binding to all platforms(win, osx, linux) for 3D engine, deep learning, dedicated server of gaming.

MagicPhysX .NET PhysX 5 binding to all platforms(win-x64, osx-x64, osx-arm64, linux-x64, linux-arm64) for 3D engine, deep learning, dedicated server o

Cysharp, Inc. 37 Jul 4, 2023
A cli utility for playing music mixes for programming & focus from musicforprogramming.net

mfp: music for programming A command-line utility for playing music mixes for programming & focus (from musicforprogramming.net), unlocking the flow s

Rohit Gupta 10 Jul 12, 2023
Convert your .NET dependencies to the Directory.Packages.props format

directory-packages-props-converter Converts your projects to use Central Package Management. <PackageReference> dependencies have their Version remove

Jeroen Vannevel 18 Aug 7, 2023
Command-line tool designed to simplify the process of managing multiple .NET SDK versions on your system

.NET Version Manager (dver) Overview dver is a command-line tool designed to simplify the process of managing multiple .NET SDK versions on your syste

Sergio Triana Escobedo 5 Aug 23, 2024
rpm (Rust project manager) is a tool that helps you to manage your rust projects

rpm rpm (Rust project manager) is a open source tool for managing your rust project in an organized way Installation # make sure you have rust install

Dilshad 4 May 4, 2023
A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

Sebastiรกn Romero Cruz 1 Apr 10, 2022