Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
pkg install -y rust hidapi pkgconf
run: |
cargo build -p framework_lib
cargo build -p framework_dotnet_ffi
cargo build -p framework_tool

build:
Expand All @@ -43,6 +44,17 @@ jobs:
- name: Build library (Linux)
run: cargo build -p framework_lib

- name: Build .NET FFI (Linux Release)
run: cargo build -p framework_dotnet_ffi --release

- name: Upload Linux .NET FFI
uses: actions/upload-artifact@v6
with:
name: framework_dotnet_ffi_linux
path: |
target/release/libframework_dotnet_ffi.so
framework_dotnet_ffi/csharp/NativeMethods.g.cs

- name: Build Linux tool
run: cargo build -p framework_tool

Expand Down Expand Up @@ -140,6 +152,19 @@ jobs:
- name: Build library (Windows)
run: cargo build -p framework_lib

- name: Build .NET FFI (Windows Release)
run: cargo build -p framework_dotnet_ffi --release

- name: Upload Windows .NET FFI
uses: actions/upload-artifact@v6
with:
name: framework_dotnet_ffi_windows
path: |
target/release/framework_dotnet_ffi.dll
target/release/framework_dotnet_ffi.dll.lib
target/release/framework_dotnet_ffi.pdb
framework_dotnet_ffi/csharp/NativeMethods.g.cs

- name: Build Windows tool
run: |
cargo build -p framework_tool
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ dump.bmp
OVMF.fd
OVMF_CODE.fd
OVMF_VARS.fd

*.g.cs
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
resolver = "2"

members = [
# Native FFI surface for .NET interop
"framework_dotnet_ffi",
# Linux and Windows tool to inspect and customize the system
"framework_tool",
# UEFI tool to inspect and customize the system
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Rust libraries and tools to interact with the system.
The tool works on Linux, Windows and the UEFI shell.
Most features are supported on every "OS".

The workspace also contains an optional .NET interop crate, `framework_dotnet_ffi`,
which exposes a native FFI surface over `framework_lib` and generates C# P/Invoke
bindings via `csbindgen`.

You can find lots of examples in [EXAMPLES.md](./EXAMPLES.md).

## Installation
Expand Down Expand Up @@ -260,12 +264,33 @@ cargo build -p framework_lib
cargo build -p framework_tool
ls -l target/debug/framework_tool

# Building the optional .NET interop crate
cargo build -p framework_dotnet_ffi

# Build the UEFI application
# Can't be built with cargo! That's why we need to exclude it in the other commands.
make -C framework_uefi
ls -l framework_uefi/build/x86_64-unknown-uefi/boot.efi
```

### Optional .NET Interop

The `framework_dotnet_ffi` crate is an optional workspace member and is not part of
the default `cargo build` / `cargo check` set.

Build it explicitly when you want to consume Framework functionality from .NET:

```sh
cargo build -p framework_dotnet_ffi
```

Building the crate also regenerates the low-level C# bindings at
`framework_dotnet_ffi/csharp/NativeMethods.g.cs` using `csbindgen`.

- Native library name: `framework_dotnet_ffi`
- Generated C# namespace: `Framework.System.Interop`
- Generated C# class: `NativeMethods`

## Install local package

```
Expand Down
19 changes: 19 additions & 0 deletions framework_dotnet_ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "framework_dotnet_ffi"
version = "0.6.2"
description = "Native FFI surface for Framework System .NET interop"
homepage = "https://github.com/FrameworkComputer/framework-system"
repository = "https://github.com/FrameworkComputer/framework-system"
license = "BSD-3-Clause"
edition = "2021"
rust-version = "1.81"
build = "build.rs"

[lib]
crate-type = ["cdylib", "rlib"]

[build-dependencies]
csbindgen = "1.9.7"

[dependencies]
framework_lib = { path = "../framework_lib" }
18 changes: 18 additions & 0 deletions framework_dotnet_ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::error::Error;
use std::fs;
use std::path::Path;

fn main() -> Result<(), Box<dyn Error>> {
let output_dir = Path::new("csharp");
fs::create_dir_all(output_dir)?;

csbindgen::Builder::default()
.input_extern_file("src/lib.rs")
.csharp_dll_name("framework_dotnet_ffi")
.csharp_namespace("Framework.System.Interop")
.csharp_class_name("NativeMethods")
.csharp_class_accessibility("internal")
.generate_csharp_file(output_dir.join("NativeMethods.g.cs"))?;

Ok(())
}
Loading