SourceGear.Rust.NET preview 0.1.0

A few weeks ago I posted a blog entry about stuff I've been building to compile Rust code for .NET.

You wanna try it? :-)

First let me try to scare away the sane people.

Coder Beware

This project is not production ready.

Think of this as just a demo or a proof of concept.

Don't even think about trying to use this for real work.

Lots of things are broken or incomplete.

This has never been used to write anything but Hello World and test cases.

This is not open source.

I am making no promises about the future of this project.

If more releases happen in the future, things may change with no regard whatsoever for backward compatibility.

This preview release is simply for interested folks who want to fiddle around with Rust and .NET.

Preview release 0.1.0

Making a release of this project has forced me to give it a name, so I'm calling it SourceGear.Rust.NET. The preview release consists of two NuGet packages:

SourceGear.Rust.NET.Templates -- for use with `dotnet new`

SourceGear.Rust.NET.Sdk -- an MSBuild Sdk

You'll need .NET Core 3.1 on one of the following platforms:

Windows (x64)

MacOS

Ubuntu 18.04 (x64)

(The Sdk includes a native code library (libLLVM), and for now, I am only bundling it for the 3 platforms above.)

And you'll need Rust nightly, plus its `rust-src` component.

rustup toolchain install nightly rustup component add rust-src --toolchain nightly

First, install the templates:

dotnet new -i SourceGear.Rust.NET.Templates

Now create a project:

mkdir MyRustProject1 cd MyRustProject1 dotnet new console -lang Rust

The project directory should now contain an .rsproj file. This is very similar to a .csproj or .fsproj, except of course that it's for Rust.

The source code for the console app is in `src/main.rs`, and it's pretty ugly at the moment, because there is a bunch of ceremony at the top that I need to find a way to move out.

Now build:

dotnet build

This will take quite a while and you'll see a bunch of output scrolling by. Subsequent builds of the project will be quicker because the Rust core library and the .NET Core bindings are already compiled.

If the build succeeds, try running the app:

dotnet run

And you should see it say Hello World.

Limitations:

The Sdk's compiler can only target .NET Core 3.1. No netstandard, no Xamarin, no Mono, no .NET Framework.

The Rust std library is absent. Only core and alloc.

The Sdk only works with Rust nightly, not stable.

There is no support yet for Rust code referencing other assemblies (besides .NET Core itself).

The bindings for .NET Core are missing quite a few methods.

Followups

If you want to talk to me about this project, feel free to drop me an email or a tweet.