Skip to content

Repository files navigation

RustSharp logo

RustSharp

A Rust-compatible language toolchain for .NET.

English | 简体中文

Windows x64 P0 evidence Linux x64 Native AOT .NET SDK 10.0.400

🚧 In progress: RustSharp is experimental. Compatibility is declared by named profiles, not by a claim of full Rust support. Unsupported source is rejected with diagnostics instead of being silently assigned C# or CLR semantics.

RustSharp is implemented in C# on .NET 10 and targets a deliberately scoped Rust 1.98 / Edition 2024 language implementation. The rsc compiler consumes .rs source files and the supported subset of Cargo.toml package inputs, emits ECMA-335 assemblies and Portable PDB files, and can run on CoreCLR or publish through .NET Native AOT for covered profiles.

What works today

Area Current scope
vertical-slice-v1 The default profile: fn main() with literal println! statements.
safe-core-primitives-v1 An opt-in profile with bounded file modules and local path packages, nongeneric functions, i32 / bool, initialized mutable locals, if / else, returns, checked arithmetic, comparisons, boolean operators, and println!.
safe-core-types-v1 An opt-in, check-only type profile: primitive numeric types, tuples, arrays, slices, references, function pointers, nongeneric ADTs, aliases, patterns/match, closures, bounded const evaluation, inference and directional coercions. It does not check borrowing or emit executable output.
Output Direct ECMA-335 and Portable PDB emission, CoreCLR execution, and Native AOT publishing for covered profiles.

RustSharp is not a drop-in replacement for rustc. Full Rust compatibility, standard-library parity, general Cargo registry resolution, macro expansion, ownership and borrow checking, Rust ABI compatibility, and arbitrary unsafe code are not current commitments. See the compatibility contract for exact boundaries.

Quick start

Install .NET SDK 10.0.400 first. The repository pins that version in global.json and disables roll-forward. Rust 1.98.0 is only required when running differential conformance work.

git clone https://github.com/IoTSharp/RustSharp.git
cd RustSharp
dotnet restore RustSharp.slnx
dotnet build RustSharp.slnx -c Release --no-restore
dotnet run --project src/RustSharp.Cli -c Release --no-build --no-restore -- run samples/safe-core.rs --profile safe-core-primitives-v1

The sample prints a small i32 / bool program compiled by RustSharp.

CLI

The installed CLI is named rsc. From a source checkout, inspect the complete option list with:

dotnet run --project src/RustSharp.Cli -c Release --no-build --no-restore -- --help

Its current command surface is:

rsc check <source.rs|Cargo.toml> [--profile <name>]
rsc build <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
rsc compile <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
rsc run <source.rs|Cargo.toml> [--output <program.dll>] [--timeout <seconds>] [--profile <name>]
rsc publish <source.rs|Cargo.toml> [--runtime <rid>] [--output <directory>] [--timeout <seconds>] [--profile <name>]

compile is retained as a compatibility alias for build.

Use rsc check samples/type-system.rs --profile safe-core-types-v1 for the type-system sample. This profile accepts check; executable commands report RSC0009 before creating output. See the type-system contract for its scope and the separate lifetime/borrow-checking boundary.

P1-04 is ✅ Complete for this declared monomorphic type contract. The recorded Windows x64 gate passes 265/265 regressions and 96/96 rustc differential cases across sixteen required categories, with zero failures or skips.

Repository guide

Path Purpose
src Compiler, syntax, semantic, IL code generation, runtime, and CLI projects.
samples Small RustSharp programs for execution and type checking.
tests Bounded executable regression harness.
docs Compatibility contracts and architecture decisions.

Documentation

Development

After a Release build, run the bounded executable harness with:

dotnet run --project tests/RustSharp.Tests/RustSharp.Tests.csproj -c Release --no-build --no-restore

This repository does not currently use a Test SDK-based dotnet test suite.

Contributing

Before proposing a language behavior change, read the relevant compatibility contract and ADR. Keep implementation, tests, and affected documentation aligned in the same change.

Notices

LICENSE-UNICODE is included in this repository. Its scope and terms are stated in that file.

About

Rust#

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages