Skip to content

Add support for Rust#214

Merged
AaronRobinsonMSFT merged 24 commits intomasterfrom
add_rust
Feb 9, 2026
Merged

Add support for Rust#214
AaronRobinsonMSFT merged 24 commits intomasterfrom
add_rust

Conversation

@AaronRobinsonMSFT
Copy link
Owner

This pull request adds first-class Rust output support to DNNE, enabling .NET assemblies to export native methods as idiomatic Rust crates in addition to C99. It updates documentation, extends the code generator and analyzer with Rust-specific attributes, and clarifies platform requirements and usage for Rust consumers.

Rust support and documentation:

  • Added a comprehensive section to the documentation (readme.md, .github/copilot-instructions.md) describing how to generate and consume Rust crates from .NET assemblies, including build instructions, crate structure, usage examples, and platform-specific notes. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Analyzer and attribute enhancements:

  • Introduced RustDeclCodeAttribute and RustTypeAttribute in the analyzer-generated attributes, allowing users to provide Rust-specific type mappings and declaration code for export customization.

Code generator improvements:

  • Extended the CLI (dnne-gen) to accept a -l/--language option for selecting the output language (c99 or rust), defaulting to C99 for backward compatibility. The generator now passes the language selection throughout the pipeline. [1] [2] [3] [4]

Sample and platform requirements:

  • Updated sample references and platform requirements to include Rust toolchain dependencies and Rust usage examples. [1] [2] [3]

These changes collectively make DNNE a multi-language export solution, with robust support for both C99 and Rust native interop.

Most important changes:

Rust support and documentation

  • Added detailed documentation for generating and consuming Rust crates, including new sections on Rust attributes, crate structure, usage, and platform-specific details in readme.md and .github/copilot-instructions.md. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Analyzer and attribute enhancements

  • Introduced RustDeclCodeAttribute and RustTypeAttribute to the analyzer-generated source, enabling Rust-specific type and declaration customization for exported methods and parameters.

Code generator improvements

  • Updated the dnne-gen CLI to accept a -l <language> argument, allowing selection between C99 and Rust output, and propagated this option through the generator pipeline. [1] [2] [3] [4]

Sample and platform requirements

  • Updated documentation and sample references to include Rust toolchain requirements and new Rust consumption examples. [1] [2] [3]

- dnne-gen: Add -l flag to select output language (c99 default, rust)
  - RustTypeProvider maps .NET types to Rust (i32, f64, *mut c_void, etc.)
  - EmitRust generates idiomatic Rust with pub unsafe fn exports,
    AtomicPtr lazy init, and #[cfg(target_os)] platform guards
  - Language-aware attribute detection via TryGetLanguageTypeAttributeValue
    and TryGetLanguageDeclCodeAttributeValue
  - Exports with unsupplied value types are skipped in Rust mode

- dnne-analyzers: Add RustTypeAttribute and RustDeclCodeAttribute
  source-generated into consuming projects

- platform.rs: Rust equivalent of platform.c (.NET Core only)
  - Runtime hosting via nethost/hostfxr
  - Thread-safe init with std::sync::Mutex
  - Idiomatic Rust public API (FailureType enum, FailureFn, Result returns)
  - Cross-platform with cfg modules for Unix and Windows
  - UTF-8 string interface with internal wide-string conversion on Windows

- Updated copilot-instructions.md to document Rust support
- Rust.cs: Generate Cargo.toml and build.rs instead of invoking rustc
- Propagate .NET assembly version to Cargo.toml
- Emit --cfg flags and nethost link directives in build.rs
- Copy generated crate to output directory (dnne-rust-crate/)
- DNNE.targets: Skip compile/copy steps for Rust language
- Fix MapOSPlatformToRustCfg: custom names emit plain cfg flags
- Add ImportingProcess.Rust as Cargo project consuming the crate
- Add AssemblyVersion property to CreateCompileCommand task
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Rust output mode to DNNE so managed exports can be consumed as an idiomatic Cargo crate (in addition to existing C99 output), with accompanying MSBuild integration, generator/analyzer updates, and docs/samples.

Changes:

  • Introduces a Rust output language path through MSBuild (DnneLanguage) and dnne-gen (-l rust), including generation/copying of Rust crate files.
  • Adds Rust-specific customization attributes (RustDeclCodeAttribute, RustTypeAttribute) and Rust code emission in dnne-gen.
  • Adds a Rust consuming sample project and updates repo documentation and ignore patterns.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
test/ImportingProcess.Rust/src/main.rs Adds a Rust sample executable consuming generated DNNE Rust crate exports.
test/ImportingProcess.Rust/Cargo.toml Adds Cargo manifest for the Rust sample with a path dependency on the generated crate.
test/ImportingProcess.Rust/Cargo.lock Locks dependencies for the Rust sample.
test/ExportingAssembly/ExportingAssembly.csproj Adjusts test assembly build flags to support Rust (--cfg ...) vs C99 (override.c).
test/DNNE.UnitTests/DNNE.UnitTests.csproj Changes unit test TFM (now net10.0).
src/platform/platform.rs Adds Rust platform hosting layer (nethost/hostfxr) for generated Rust crates.
src/msbuild/DNNE.targets Adds DnneLanguage, switches generated source extension (.g.c vs .g.rs), and adds Rust crate generation/copy steps.
src/msbuild/DNNE.props Documents/configures DnneLanguage MSBuild property.
src/msbuild/DNNE.BuildTasks/Rust.cs Adds Rust crate file generation (Cargo.toml/build.rs) in build tasks.
src/msbuild/DNNE.BuildTasks/CreateCompileCommand.cs Routes Rust builds to crate generation instead of native compilation; plumbs Language/AssemblyVersion.
src/dnne-gen/Program.cs Adds -l/--language CLI option and passes language to the generator.
src/dnne-gen/Generator.cs Adds Rust emission path (type provider, attribute selection, Rust codegen, cfg mapping).
src/dnne-analyzers/AttributesGenerator.cs Adds analyzer-generated Rust attribute types.
readme.md Documents Rust crate generation/consumption and Rust-specific customization.
.gitignore Ignores Cargo target/ directories.
.github/copilot-instructions.md Adds repo guidance including Rust pipeline documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AaronRobinsonMSFT and others added 2 commits February 6, 2026 16:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AaronRobinsonMSFT AaronRobinsonMSFT marked this pull request as ready for review February 8, 2026 00:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 23 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 2a810d0 into master Feb 9, 2026
6 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the add_rust branch February 9, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants