Home About Eric Topics SourceGear

2020-04-20 12:00:00

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 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:

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

(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:

Followups

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