Skip to content

Commit 52fdcbe

Browse files
committed
Adds a dotnet API
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 7a88a5e commit 52fdcbe

File tree

67 files changed

+8143
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+8143
-38
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
- When running examples in this repository, use the `Justfile` recipes instead of invoking `cargo run` or `python` directly.
44
- Use `just examples` from the repository root to run the full example suite.
5-
- To run examples for a specific sandbox, use module-scoped recipes: `just wasm examples`, `just js examples`, `just python examples`.
5+
- To run examples for a specific sandbox, use module-scoped recipes: `just wasm examples`, `just js examples`, `just python examples`, `just dotnet examples`.
66
- Use `just build` from the repository root to build all subprojects and SDKs.
77
- Reason: the example commands depend on `WIT_WORLD` being set to `src/wasm_sandbox/wit/sandbox-world.wasm`; the `Justfile` handles that setup.
88

99
Make things cross-platform where possible (window/mac/linux). Mac supprot for hyperlight isn't avaliable yet but is coming.
1010

1111
- **After changing WIT interfaces**: you must run `just build` (or at minimum rebuild the guest `.wasm` and `.aot` files) before running examples. The pre-compiled guest binaries embed the WIT signature; a mismatch causes "Host function vector parameter missing length" errors at runtime.
1212

13-
- **Formatting and linting**: always use `just fmt` and `just fmt-check` from the repository root instead of invoking `cargo fmt`, `ruff format`, or `ruff check` directly. The Justfile recipes run multiple tools in sequence (e.g. `ruff format` + `ruff check --fix` for Python) and missing a step causes CI failures.
13+
- **Formatting and linting**: always use `just fmt` and `just fmt-check` from the repository root instead of invoking `cargo fmt`, `ruff format`, `ruff check`, or `dotnet format` directly. The Justfile recipes run multiple tools in sequence and missing a step causes CI failures.

.github/workflows/ci.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,79 @@ jobs:
9999
- name: Run examples
100100
run: just wasm examples
101101

102+
dotnet-sdk:
103+
name: .NET SDK (${{ matrix.os }})
104+
runs-on: ${{ matrix.os }}
105+
strategy:
106+
matrix:
107+
os: [ubuntu-latest, windows-latest]
108+
steps:
109+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
110+
111+
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
112+
with:
113+
toolchain: nightly, 1.94
114+
components: rustfmt, clippy
115+
rustflags: ""
116+
117+
- uses: actions/setup-dotnet@v4
118+
with:
119+
dotnet-version: '8.0.x'
120+
121+
- uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
122+
123+
- name: Install Python
124+
run: uv python install 3.12
125+
126+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
127+
with:
128+
node-version: "latest"
129+
cache: npm
130+
cache-dependency-path: src/wasm_sandbox/guests/javascript/package-lock.json
131+
132+
- name: Install just
133+
run: cargo install --locked just
134+
135+
- name: Install clang (Linux)
136+
if: runner.os == 'Linux'
137+
run: sudo apt-get update && sudo apt-get install -y clang
138+
139+
- name: Install LLVM (Windows)
140+
if: runner.os == 'Windows'
141+
run: choco install llvm -y
142+
143+
- name: Enable KVM
144+
if: runner.os == 'Linux' && !env.ACT
145+
run: |
146+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
147+
sudo udevadm control --reload-rules
148+
sudo udevadm trigger --name-match=kvm
149+
sudo chmod 666 /dev/kvm
150+
151+
- name: Build guest modules
152+
run: just wasm guest-build
153+
154+
- name: Format check
155+
run: just dotnet fmt-check
156+
157+
- name: Lint
158+
run: just dotnet lint
159+
160+
- name: Build
161+
run: just dotnet build
162+
163+
- name: Test Rust FFI
164+
run: just dotnet test-rust
165+
166+
- name: Test .NET
167+
run: just dotnet test-dotnet
168+
169+
- name: Run examples
170+
run: just dotnet examples
171+
172+
- name: Package test
173+
run: just dotnet package-test
174+
102175
python-sdk:
103176
name: Python SDK (${{ matrix.os }})
104177
runs-on: ${{ matrix.os }}

.github/workflows/publish.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Python SDK
1+
name: Publish Python SDK & .NET SDK
22

33
on:
44
push:
@@ -112,3 +112,49 @@ jobs:
112112

113113
- name: Publish to PyPI
114114
run: just python python-publish
115+
116+
# Build and publish .NET NuGet packages.
117+
dotnet-publish:
118+
if: ${{ !github.event.act }}
119+
name: Publish .NET NuGet packages
120+
runs-on: ubuntu-latest
121+
environment:
122+
name: nuget
123+
steps:
124+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
125+
126+
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
127+
with:
128+
cache-key: release
129+
rustflags: ""
130+
131+
- uses: actions/setup-dotnet@v4
132+
with:
133+
dotnet-version: '8.0.x'
134+
135+
- name: Install just
136+
run: cargo install --locked just
137+
138+
- name: Install clang
139+
run: sudo apt-get update && sudo apt-get install -y clang
140+
141+
- name: Enable KVM
142+
run: |
143+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
144+
sudo udevadm control --reload-rules
145+
sudo udevadm trigger --name-match=kvm
146+
sudo chmod 666 /dev/kvm
147+
148+
- name: Build guest modules
149+
run: just wasm guest-build
150+
151+
- name: Build and pack
152+
run: just dotnet dist
153+
154+
- name: Package test
155+
run: just dotnet package-test release
156+
157+
- name: Publish to NuGet
158+
env:
159+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
160+
run: just dotnet publish

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ wheels/
1616
pip-wheel-metadata/
1717
src/sdk/python/wasm_backend/Cargo.lock
1818
src/sdk/python/hyperlight_js_backend/Cargo.lock
19+
src/sdk/dotnet/ffi/Cargo.lock
1920
docs/end-user-overview-slides.html
21+
22+
# dotnet
23+
[Bb]in/
24+
[Oo]bj/
25+
.vs/
26+
*.user
27+
*.nupkg

Cargo.lock

Lines changed: 27 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"src/sdk/python/pyo3_common",
77
"src/sdk/python/wasm_backend",
88
"src/sdk/python/hyperlight_js_backend",
9+
"src/sdk/dotnet/ffi",
910
]
1011
# nanvix_sandbox requires nightly Rust (nanvix uses #![feature(never_type)])
1112
exclude = [
@@ -27,17 +28,19 @@ hyperlight-sandbox-pyo3-common = { path = "src/sdk/python/pyo3_common" }
2728
hyperlight-common = { version = "0.14.0", default-features = false }
2829
hyperlight-component-macro = { version = "0.14.0" }
2930
hyperlight-host = { version = "0.14.0", default-features = false, features = ["executable_heap"] }
30-
hyperlight-wasm = { git = "https://github.com/jsturtevant/hyperlight-wasm", rev = "05a9eea" } #branch util-compont-fixes
31+
hyperlight-wasm = { git = "https://github.com/jsturtevant/hyperlight-wasm", rev = "05a9eea" }
3132
pyo3 = { version = "0.28", features = ["extension-module"] }
3233

33-
# Patched component-util (name collision fix, flags fix, empty-ns fix)
34-
# https://github.com/jsturtevant/hyperlight-1/tree/wasm-component-fixes
34+
# Patched component-util — the published 0.14.0 has name collision, flags,
35+
# and empty-namespace bugs that break the generated host bindings.
36+
# This patch will be removed once the fixes are merged upstream.
37+
[patch.crates-io]
38+
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev = "4701257034306b0978d49cc9140bc0b12de3b409", package = "hyperlight-component-util" }
39+
40+
# hyperlight-wasm 0.13.1 (git) depends on hyperlight-* from the hyperlight-dev
41+
# GitHub org. Redirect those to the published 0.14.0 crates.io versions.
3542
[patch."https://github.com/hyperlight-dev/hyperlight"]
3643
hyperlight-common = { version = "0.14.0" }
3744
hyperlight-guest = { version = "=0.14.0" }
3845
hyperlight-guest-bin = { version = "=0.14.0" }
3946
hyperlight-host = { version = "0.14.0" }
40-
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev="4701257034306b0978d49cc9140bc0b12de3b409", package = "hyperlight-component-util" }
41-
42-
[patch.crates-io]
43-
hyperlight-component-util = { git = "https://github.com/jsturtevant/hyperlight-1", rev="4701257034306b0978d49cc9140bc0b12de3b409", package = "hyperlight-component-util" }

Justfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@ mod wasm 'src/wasm_sandbox/Justfile'
44
mod js 'src/javascript_sandbox/Justfile'
55
mod nanvix 'src/nanvix_sandbox/Justfile'
66
mod python 'src/sdk/python/Justfile'
7+
mod dotnet 'src/sdk/dotnet/Justfile'
78
mod examples_mod 'examples/Justfile'
89

910
default-target := "debug"
1011

11-
clean: wasm::clean python::clean
12+
clean: wasm::clean python::clean dotnet::clean
1213
cargo clean
1314

1415
#### BUILD TARGETS ####
1516

16-
build target=default-target: (wasm::build target) (js::build target) nanvix::build python::build
17+
build target=default-target: (wasm::build target) (js::build target) nanvix::build python::build (dotnet::build target)
1718

1819
lint: lint-rust wasm::lint js::lint python::lint
1920

2021
lint-rust:
2122
cargo clippy -p hyperlight-sandbox --all-targets --features test-utils -- -D warnings
2223

23-
fmt: fmt-rust python::fmt
24+
fmt: fmt-rust python::fmt dotnet::fmt
2425

2526
fmt-rust:
2627
cargo +nightly fmt --all
2728

28-
fmt-check: fmt-check-rust python::fmt-check
29+
fmt-check: fmt-check-rust python::fmt-check dotnet::fmt-check
2930

3031
fmt-check-rust:
3132
cargo +nightly fmt --all -- --check
3233

3334
#### TESTS ####
3435

35-
test: wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test
36+
test: wasm::guest-build wasm::js-guest-build python::build python::python-test test-rust wasm::test dotnet::test-rust dotnet::test
3637

3738
fuzz seconds="60": (python::python-fuzz seconds)
3839

@@ -51,7 +52,7 @@ python-dist-backends: wasm::_clean-stale-wasm wasm::guest-compile-wit js::_clean
5152

5253
python-wheelhouse-test: python-dist python::python-wheelhouse-test
5354

54-
examples target=default-target: (wasm::examples target) (js::examples target) python::examples
55+
examples target=default-target: (wasm::examples target) (js::examples target) python::examples dotnet::examples
5556

5657
integration-examples target=default-target: (wasm::guest-build target) wasm::js-guest-build python::build examples_mod::integration-examples
5758

0 commit comments

Comments
 (0)