Skip to content

Add support for DOTNET Facade FFI#320

Open
TekuSP wants to merge 12 commits intoFrameworkComputer:mainfrom
TekuSP:dotnet_ffi
Open

Add support for DOTNET Facade FFI#320
TekuSP wants to merge 12 commits intoFrameworkComputer:mainfrom
TekuSP:dotnet_ffi

Conversation

@TekuSP
Copy link
Copy Markdown

@TekuSP TekuSP commented Apr 20, 2026

Hello,

I am .NET Developer and not RUST Developer, this is warning of things to come.
I needed to integrate Framework-System into .NET ecosystem, using export "c" of RUST.

I have no idea if I have done this right, but I tried my best.
I made .NET integration library of other side here: https://github.com/TekuSP/framework-dotnet
With GIT Submodule, sample output of my test console app is:

Product: Laptop 16 (AMD Ryzen AI 300 Series)
Platform: Framework16AmdAi300
Family: Framework16
Driver support:
  Portio: False
  CrosEc: False
  Windows: True
Active driver: Windows
Build info: tulip-3.0.5-178a77d 2026-03-12 05:51:52 lotus@ip-172-26-3-226
Flash: Ro, RO=tulip-3.0.5-178a77d, RW=tulip-3.0.5-178a77d
Battery: 99%
AC Present: True
Manufacturer: NVT
Fan count: 2
Temp0: 56C (Ok)

Therefore even if my solution is bad, it works. It would be silly and stupid of me to not push this idea upstream, maybe someone will do it better, maybe someone has better solution. But this is for me only way to access Framework-System from .NET.

I did in the past app for cooling fans of MSI, want to port that for my Framework, including separate fan curves and control.

TekuSP added 4 commits April 20, 2026 19:15
- Introduce a new crate that exposes C-compatible functions for interacting with the EC and SMBIOS.
- Integrate `csbindgen` to automatically generate C# bindings during the build process.
- Implement helper types and snapshot functions in `framework_lib` to facilitate structured data retrieval.
- Export functionality for platform identification, battery status, and thermal/fan control.
- Add build steps for the .NET interop crate to FreeBSD, Linux, and Windows CI jobs.
- Configure CI to upload compiled native libraries and generated C# bindings as build artifacts.
- Update README with build instructions and technical details for the optional .NET interop functionality.
@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 20, 2026

(And yes I did use Copilot for some tasks, as I have absolutely almost zero knowledge of RUST, I have knowledge of firmwares, OS, and frameworks in .NET (Yes we had C# OS))

@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 20, 2026

All tests pass and library works on my laptop, there is one slight formatting change (Cause meh Lint) and one extended helper in original source code for getting some internal values. No changes made to RUST functionality (I hope), just exported a lot of stuff for C (And C#)

Signed-off-by: TekuSP <richard.torhan@windowslive.com>
@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 20, 2026

Signed commit.

TekuSP added 3 commits April 26, 2026 22:52
Refactors the FFI boundary to provide more comprehensive and structured error reporting, and to consolidate function return values.

- The `FrameworkStatus` struct now uses a union to provide specific error details (e.g., invalid fan index, detailed EC response codes, device error messages).
- FFI functions now return dedicated `Result` structs that combine status and data, simplifying consumption from .NET.
- Introduces functions to retrieve human-readable descriptions for status codes and device errors.
- Updates `build.rs` to ensure `csbindgen` reruns when `src/lib.rs` changes, improving build reliability.
@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 26, 2026

Updated to latest main, after new Framework 13 Pro with new Intel CPUs. Reworked some internal structures to make more C# sense.

TekuSP added 3 commits April 26, 2026 23:12
…pshot

Consolidates fan RPM, presence, and stalled status into a `FrameworkFanReading`
struct, leveraging a new `FrameworkFanState` enum. This improves data
encapsulation and provides clearer, type-safe status information for each fan
within the `FrameworkThermalSnapshot`.
Modernizes the FFI interfaces by introducing type-safe enums for various states and capabilities, and by enabling dynamic length strings for textual data.

- Replaces boolean flags with dedicated enums (`FrameworkFanFeaturesState`, `FrameworkPowerSourceState`, `FrameworkBatteryState`) for clearer and more robust state representation in fan capabilities and power snapshots.
- Adopts `FrameworkByteBuffer` for variable-length strings in battery details (manufacturer, model, etc.) and EC flash versions, eliminating fixed-size buffer limitations.
- Restructures `FrameworkPowerSnapshot` to embed a new `FrameworkBatterySnapshot`, providing a more organized and extensible data model for power and battery information.
@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 27, 2026

Final C# version to have refactored objects, where original structs did not make sense (We have battery_count, but we cannot index batteries now etc)

@TekuSP
Copy link
Copy Markdown
Author

TekuSP commented Apr 27, 2026

Finalized, I am using it now in https://github.com/TekuSP/framework-dotnet and I am pretty happy about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant