Skip to content

Commit c93ccc1

Browse files
committed
feat: generate dotnet bindings with uniffy
Signed-off-by: Laszlo Gecse <[email protected]>
1 parent dbedc17 commit c93ccc1

File tree

20 files changed

+2976
-0
lines changed

20 files changed

+2976
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright AGNTCY Contributors (https://github.com/agntcy)
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using System;
5+
using Agntcy.Slim;
6+
7+
/// <summary>
8+
/// Installation test for SLIM .NET bindings.
9+
///
10+
/// This test verifies that the slim_bindings package can be imported
11+
/// and initialized successfully.
12+
/// </summary>
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
Console.WriteLine("SLIM .NET Bindings Installation Test");
18+
Console.WriteLine("==================================================");
19+
20+
try
21+
{
22+
// Initialize SLIM (required before any operations)
23+
Slim.Initialize();
24+
Console.WriteLine("SLIM initialized successfully");
25+
26+
// Verify initialization state
27+
if (!Slim.IsInitialized)
28+
{
29+
Console.WriteLine("SLIM initialization check failed");
30+
Environment.Exit(1);
31+
}
32+
Console.WriteLine("SLIM is initialized");
33+
34+
// Get and display version information
35+
string version = Slim.Version;
36+
Console.WriteLine($"SLIM version: {version}");
37+
38+
// Get and display build information
39+
string buildInfo = Slim.BuildInfo;
40+
Console.WriteLine($"SLIM build info: {buildInfo}");
41+
42+
// Clean shutdown
43+
Slim.Shutdown();
44+
Console.WriteLine("SLIM shutdown successfully");
45+
46+
Console.WriteLine("Installation test passed!");
47+
Environment.Exit(0);
48+
}
49+
catch (Exception ex)
50+
{
51+
Console.WriteLine($"Test failed with exception: {ex.Message}");
52+
Console.WriteLine(ex.StackTrace);
53+
Environment.Exit(1);
54+
}
55+
}
56+
}

.github/workflows/release-bindings.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ on:
1212
env:
1313
LIBRARY_NAME: slim_bindings
1414
GO_BINDINGS_REPO: agntcy/slim-bindings-go
15+
NUGET_PACKAGE_NAME: Agntcy.Slim
1516
UNIFFI_BINDGEN_GO_VERSION: v0.4.0+v0.28.3
17+
UNIFFI_BINDGEN_CS_VERSION: v0.9.0+v0.28.3
18+
DOTNET_VERSION: "8.0.x"
1619

1720
jobs:
1821
# ==========================================================================
@@ -128,3 +131,13 @@ jobs:
128131
with:
129132
password: ${{ secrets.PYPI_API_TOKEN }}
130133
packages-dir: dist
134+
135+
# ==========================================================================
136+
# Job 5: Release .NET bindings to NuGet
137+
# ==========================================================================
138+
release-dotnet-bindings:
139+
name: "Release .NET Bindings"
140+
needs: build-and-test-bindings
141+
uses: ./.github/workflows/reusable-dotnet-bindings-release.yaml
142+
secrets:
143+
nuget-api-key: ${{ secrets.NUGET_API_TOKEN }}

.github/workflows/reusable-bindings-build-and-test.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
with:
150150
workspace: ./data-plane
151151
- name: Build library
152+
working-directory: ./data-plane/bindings/rust
152153
run: |
153154
task bindings:build:all TARGET=${{ matrix.platform.target }} PROFILE=release
154155
- name: Strip and rename artifacts
@@ -408,3 +409,53 @@ jobs:
408409
run: |
409410
echo "✅ Python wheel verification completed successfully on ${{ matrix.platform.target }}"
410411
echo "The wheel can be safely published."
412+
413+
dotnet-bindings-build-and-test:
414+
runs-on: ${{ inputs.runner }}
415+
needs: build-libraries
416+
417+
defaults:
418+
run:
419+
shell: bash
420+
working-directory: ./data-plane/bindings/dotnet
421+
422+
steps:
423+
- name: Checkout Repo
424+
uses: actions/checkout@v4
425+
426+
- name: Setup Rust
427+
uses: ./.github/actions/setup-rust
428+
with:
429+
workspace: ${{ inputs.rust-workspace }}
430+
431+
- name: Setup .NET
432+
uses: actions/setup-dotnet@v4
433+
with:
434+
dotnet-version: "8.0.x"
435+
436+
- name: Setup Task
437+
uses: ./.github/actions/setup-task
438+
with:
439+
version: latest
440+
github-token: ${{ secrets.GITHUB_TOKEN }}
441+
442+
# Download all library artifacts
443+
- name: Download library artifacts
444+
uses: actions/download-artifact@v4
445+
with:
446+
pattern: bindings-*
447+
path: ./data-plane/bindings/dotnet/artifacts/
448+
449+
- name: List downloaded artifacts
450+
run: |
451+
echo "Downloaded artifacts:"
452+
find ./artifacts -type f -ls
453+
454+
- name: Generate bindings, build, test, and pack
455+
run: task ci ARTIFACTS_DIR=./artifacts BINDGEN_LIB=./artifacts/bindings-x86_64-unknown-linux-gnu/libslim_bindings_x86_64_linux_gnu.so
456+
457+
- name: Upload NuGet package
458+
uses: actions/upload-artifact@v4
459+
with:
460+
name: dotnet-bindings-nuget
461+
path: ./data-plane/bindings/dotnet/artifacts/*.nupkg
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Copyright AGNTCY Contributors (https://github.com/agntcy)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
name: Reusable .NET Bindings Release
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
library-name:
11+
description: Name of the library
12+
required: false
13+
type: string
14+
default: slim_bindings
15+
dotnet-version:
16+
description: .NET SDK version
17+
required: false
18+
type: string
19+
default: "8.0.x"
20+
dotnet-bindings-working-directory:
21+
description: Working directory for .NET bindings
22+
required: false
23+
type: string
24+
default: ./data-plane/bindings/dotnet
25+
nuget-package-name:
26+
description: NuGet package name
27+
required: false
28+
type: string
29+
default: Agntcy.Slim
30+
secrets:
31+
nuget-api-key:
32+
description: NuGet API key for publishing
33+
required: true
34+
35+
env:
36+
LIBRARY_NAME: ${{ inputs.library-name }}
37+
NUGET_PACKAGE_NAME: ${{ inputs.nuget-package-name }}
38+
39+
jobs:
40+
# ==========================================================================
41+
# Job 1: Publish NuGet package
42+
# ==========================================================================
43+
release-dotnet-bindings:
44+
name: Release .NET Bindings
45+
runs-on: ubuntu-latest
46+
defaults:
47+
run:
48+
shell: bash
49+
working-directory: ${{ inputs.dotnet-bindings-working-directory }}
50+
steps:
51+
- name: Checkout source repo
52+
uses: actions/checkout@v4
53+
54+
- name: Setup .NET
55+
uses: actions/setup-dotnet@v4
56+
with:
57+
dotnet-version: ${{ inputs.dotnet-version }}
58+
59+
# Download NuGet package artifact
60+
- name: Download NuGet Package Artifact
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: dotnet-bindings-nuget
64+
path: ${{ inputs.dotnet-bindings-working-directory }}/nupkg
65+
66+
- name: List downloaded artifacts
67+
run: |
68+
echo "Downloaded NuGet package:"
69+
ls -lah ./nupkg/
70+
71+
- name: Extract version from tag
72+
id: extract-version
73+
run: |
74+
# Extract version from tag name (remove 'slim-bindings-' prefix)
75+
VERSION="${{ github.ref_name }}"
76+
VERSION="${VERSION#slim-bindings-}"
77+
echo "Extracted version: $VERSION"
78+
echo "version=$VERSION" >> $GITHUB_OUTPUT
79+
80+
- name: Determine if pre-release
81+
id: prerelease
82+
run: |
83+
VERSION="${{ steps.extract-version.outputs.version }}"
84+
if [[ "$VERSION" =~ (alpha|beta|rc) ]]; then
85+
echo "is_prerelease=true" >> $GITHUB_OUTPUT
86+
echo "This is a pre-release version"
87+
else
88+
echo "is_prerelease=false" >> $GITHUB_OUTPUT
89+
echo "This is a stable release"
90+
fi
91+
92+
- name: Publish to NuGet.org
93+
run: |
94+
PACKAGE=$(ls ./nupkg/*.nupkg | head -1)
95+
echo "Publishing package: $PACKAGE"
96+
97+
dotnet nuget push "$PACKAGE" \
98+
--api-key "${{ secrets.nuget-api-key }}" \
99+
--source https://api.nuget.org/v3/index.json \
100+
--skip-duplicate
101+
102+
echo "Successfully published to NuGet.org"
103+
104+
# ==========================================================================
105+
# Job 2: Test the published .NET bindings work as expected
106+
# ==========================================================================
107+
test-dotnet-bindings:
108+
name: Test .NET Bindings (${{ matrix.platform.target }})
109+
runs-on: ${{ matrix.platform.runner }}
110+
needs: release-dotnet-bindings
111+
if: startsWith(github.ref, 'refs/tags/slim-bindings-')
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
platform:
116+
# Linux x86_64 variants
117+
- runner: ubuntu-24.04
118+
os: linux
119+
target: x86_64-unknown-linux-gnu
120+
- runner: ubuntu-24.04
121+
os: linux
122+
target: x86_64-unknown-linux-musl
123+
# Windows variant
124+
- runner: windows-latest
125+
os: windows
126+
target: x86_64-pc-windows-msvc
127+
# macOS variants
128+
- runner: macos-15-intel
129+
os: macos
130+
target: x86_64-apple-darwin
131+
- runner: macos-15
132+
os: macos
133+
target: aarch64-apple-darwin
134+
defaults:
135+
run:
136+
shell: bash
137+
steps:
138+
- name: Checkout code
139+
uses: actions/checkout@v4
140+
141+
- name: Setup .NET
142+
uses: actions/setup-dotnet@v4
143+
with:
144+
dotnet-version: ${{ inputs.dotnet-version }}
145+
146+
- name: Wait for NuGet package propagation
147+
run: |
148+
echo "Waiting 60 seconds for NuGet.org package index to update..."
149+
sleep 60
150+
151+
- name: Test bindings installation and usage
152+
run: |
153+
# Extract version from tag name
154+
VERSION="${{ github.ref_name }}"
155+
VERSION="${VERSION#slim-bindings-}"
156+
echo "Testing version: $VERSION"
157+
echo "Platform: ${{ matrix.platform.target }}"
158+
echo "Runner: ${{ matrix.platform.runner }}"
159+
160+
# Create a temporary test directory
161+
if [ "$RUNNER_OS" = "Windows" ]; then
162+
TEST_DIR=$(mktemp -d -p "$RUNNER_TEMP")
163+
else
164+
TEST_DIR=$(mktemp -d)
165+
fi
166+
cd "$TEST_DIR"
167+
echo "Testing in: $TEST_DIR"
168+
169+
# Create a test console application
170+
dotnet new console -n SlimBindingsTest
171+
cd SlimBindingsTest
172+
173+
# Install the package from NuGet.org
174+
echo "Installing package ${{ env.NUGET_PACKAGE_NAME }} version $VERSION"
175+
dotnet add package ${{ env.NUGET_PACKAGE_NAME }} --version $VERSION
176+
echo "Package installed successfully"
177+
178+
# Copy and run test program
179+
cp $GITHUB_WORKSPACE/.github/tests/dotnet/test_installation.cs ./Program.cs
180+
181+
# Build and run
182+
dotnet build
183+
dotnet run
184+
185+
echo ""
186+
echo "All tests passed on ${{ matrix.platform.target }}!"
187+
188+
- name: Test result summary
189+
if: success()
190+
run: |
191+
echo ".NET bindings verification completed successfully on ${{ matrix.platform.target }}"
192+
echo "The published package is working correctly."
193+
194+
# ==========================================================================
195+
# Job 3: Finalize release - create summary
196+
# ==========================================================================
197+
finalize-dotnet-release:
198+
name: Finalize Release
199+
runs-on: ubuntu-latest
200+
needs: test-dotnet-bindings
201+
if: startsWith(github.ref, 'refs/tags/slim-bindings-')
202+
steps:
203+
- name: Extract version
204+
id: extract-version
205+
run: |
206+
VERSION="${{ github.ref_name }}"
207+
VERSION="${VERSION#slim-bindings-}"
208+
echo "version=$VERSION" >> $GITHUB_OUTPUT
209+
210+
- name: Verify package availability
211+
run: |
212+
VERSION="${{ steps.extract-version.outputs.version }}"
213+
echo "Verifying package is discoverable on NuGet.org..."
214+
215+
# Query NuGet API to verify package availability
216+
RESPONSE=$(curl -s "https://api.nuget.org/v3/registration5-semver1/${{ env.NUGET_PACKAGE_NAME }}/index.json")
217+
218+
if echo "$RESPONSE" | grep -q "$VERSION"; then
219+
echo "Package version $VERSION is discoverable on NuGet.org"
220+
else
221+
echo "Package might still be indexing on NuGet.org"
222+
fi
223+
224+
- name: Release complete
225+
run: |
226+
VERSION="${{ steps.extract-version.outputs.version }}"
227+
echo ""
228+
echo "Release $VERSION complete!"
229+
echo ".NET bindings published to https://www.nuget.org/packages/${{ env.NUGET_PACKAGE_NAME }}"
230+
echo "Version: $VERSION"
231+
echo "All tests passed on 5 platforms"
232+
echo ""
233+
echo "Install with:"
234+
echo " dotnet add package ${{ env.NUGET_PACKAGE_NAME }} --version $VERSION"

0 commit comments

Comments
 (0)