Skip to content
Merged
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
164 changes: 164 additions & 0 deletions .github/workflows/release_dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Release Dotnet Binding

on:
push:
tags:
- 'dotnet-v[0-9]+.[0-9]+.[0-9]+*'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe change to v[0-9]+.[0-9]+.[0-9]+ or v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+ depending on how the .NET release workflow would actually trigger.

I think we don't push tags like dotnet-v[0-9]+.[0-9]+.[0-9]+* so far.

But I'm OK to leave it as is for now since this workflow is untested anyway.

pull_request:
branches:
- main
paths:
- ".github/workflows/release_dotnet.yml"
- "bindings/dotnet/build.py"
- "bindings/dotnet/DotOpenDAL/DotOpenDAL.csproj"
workflow_dispatch:
inputs:
dotnet_publish:
description: "Publish DotOpenDAL to nuget.org"
required: true
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build-native:
name: Build Native - ${{ matrix.classifier }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: "bindings/dotnet"
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
classifier: linux-x86_64
artifact: libopendal_dotnet.so
- os: windows-latest
classifier: windows-x86_64
artifact: opendal_dotnet.dll
- os: macos-latest
classifier: osx-aarch_64
artifact: libopendal_dotnet.dylib

steps:
- uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-protoc: true
need-rocksdb: true
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build native library
run: python build.py --classifier ${{ matrix.classifier }}

- name: Upload native artifact
uses: actions/upload-artifact@v6
with:
name: native-${{ matrix.classifier }}
path: bindings/dotnet/target/native/${{ matrix.classifier }}/${{ matrix.artifact }}
if-no-files-found: error

package:
name: Pack NuGet package
runs-on: ubuntu-latest
needs:
- build-native
defaults:
run:
working-directory: "bindings/dotnet"

steps:
- uses: actions/checkout@v6
- name: Setup dotnet toolchain
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"

- name: Download native artifacts
uses: actions/download-artifact@v7
with:
pattern: native-*
merge-multiple: true
path: bindings/dotnet/target/release-assets

- name: Prepare runtime assets
shell: bash
run: |
mkdir -p DotOpenDAL/runtimes/win-x64/native
mkdir -p DotOpenDAL/runtimes/linux-x64/native
mkdir -p DotOpenDAL/runtimes/osx-arm64/native

cp target/release-assets/opendal_dotnet.dll DotOpenDAL/runtimes/win-x64/native/
cp target/release-assets/libopendal_dotnet.so DotOpenDAL/runtimes/linux-x64/native/
cp target/release-assets/libopendal_dotnet.dylib DotOpenDAL/runtimes/osx-arm64/native/

- name: Pack DotOpenDAL
run: dotnet pack DotOpenDAL/DotOpenDAL.csproj -c Release -o artifacts/package

- name: Upload NuGet package
uses: actions/upload-artifact@v6
with:
name: dotnet-package
path: bindings/dotnet/artifacts/package/*.nupkg
if-no-files-found: error

publish:
name: Publish
if: ${{ startsWith(github.ref, 'refs/tags/dotnet-v') || (github.event_name == 'workflow_dispatch' && inputs.dotnet_publish) }}
runs-on: ubuntu-latest
needs:
- package
permissions:
contents: read
id-token: write
environment: production

steps:
- name: Setup dotnet toolchain
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"

- name: Download NuGet package
uses: actions/download-artifact@v7
with:
name: dotnet-package
path: bindings/dotnet/artifacts/package

- name: NuGet login
uses: NuGet/login@v1
id: login
with:
user: Apache.OpenDAL

- name: Publish package
run: dotnet nuget push bindings/dotnet/artifacts/package/*.nupkg --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
14 changes: 1 addition & 13 deletions bindings/dotnet/DotOpenDAL.Tests/DotOpenDAL.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@
<ItemGroup>
<ProjectReference Include="../DotOpenDAL/DotOpenDAL.csproj" />
</ItemGroup>
<ItemGroup>
<!-- Linux/macOS -->
<None Include="../target/debug/libopendal_dotnet.*"
Condition="'$(OS)' != 'Windows_NT'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<!-- Windows -->
<None Include="../target/debug/opendal_dotnet.dll"
Condition="'$(OS)' == 'Windows_NT'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit.v3" Version="3.2.0" />
Expand All @@ -39,4 +27,4 @@
</PackageReference>
</ItemGroup>

</Project>
</Project>
19 changes: 18 additions & 1 deletion bindings/dotnet/DotOpenDAL/AsyncState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static long Register<T>(out AsyncState<T> state)

if (AsyncStates.TryAdd(id, state))
{
state.Context = id;
return id;
}
}
Expand All @@ -66,6 +67,8 @@ public static bool TryTake<TState>(long context, [NotNullWhen(true)] out TState?

public sealed class AsyncState<T>
{
internal long Context { get; set; }

public TaskCompletionSource<T> Completion { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);

public CancellationTokenRegistration CancellationRegistration { get; private set; }
Expand All @@ -77,10 +80,24 @@ public void BindCancellation(CancellationToken cancellationToken)
return;
}

CancellationRegistration = cancellationToken.Register(static value =>
var registration = cancellationToken.Register(static value =>
{
var current = (AsyncState<T>)value!;
AsyncStateRegistry.Unregister(current.Context);
current.Completion.TrySetCanceled();
}, this);

if (Completion.Task.IsCompleted)
{
registration.Dispose();
return;
}

CancellationRegistration = registration;

if (Completion.Task.IsCompleted)
{
CancellationRegistration.Dispose();
}
}
}
28 changes: 25 additions & 3 deletions bindings/dotnet/DotOpenDAL/DotOpenDAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,39 @@
</PropertyGroup>

<ItemGroup>
<!-- Linux/macOS -->
<None Include="../target/debug/libopendal_dotnet.*"
<None Include="runtimes\win-x64\native\opendal_dotnet.dll"
Pack="true"
PackagePath="runtimes/win-x64/native/" />
<None Include="runtimes\linux-x64\native\libopendal_dotnet.so"
Pack="true"
PackagePath="runtimes/linux-x64/native/" />
<None Include="runtimes\osx-arm64\native\libopendal_dotnet.dylib"
Pack="true"
PackagePath="runtimes/osx-arm64/native/" />
</ItemGroup>

<!-- Resolve Rust build output path -->
<PropertyGroup>
<RustTargetDir>../target</RustTargetDir>
<NativeOutputDir Condition="'$(Configuration)' == 'Debug'">$(RustTargetDir)/debug</NativeOutputDir>
<NativeOutputDir Condition="'$(Configuration)' == 'Release'">$(RustTargetDir)/release</NativeOutputDir>
</PropertyGroup>

<!-- Copy native libs for local run -->
<ItemGroup Condition="Exists('$(NativeOutputDir)')">

<!-- Unix (Linux + macOS) -->
<None Include="$(NativeOutputDir)/libopendal_dotnet.*"
Condition="'$(OS)' != 'Windows_NT'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<!-- Windows -->
<None Include="../target/debug/opendal_dotnet.dll"
<None Include="$(NativeOutputDir)/opendal_dotnet.dll"
Condition="'$(OS)' == 'Windows_NT'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions bindings/dotnet/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
def classifier_to_target(classifier: str) -> str:
if classifier == "osx-aarch_64":
return "aarch64-apple-darwin"
if classifier == "osx-x86_64":
return "x86_64-apple-darwin"
Comment on lines -30 to -31
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Fatorin Is this something .NET cannot support, or we do not support it due to its outdated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not a limitation of .NET.
As modern Macs have largely transitioned to Apple Silicon (M-series), So I decided not to include osx-x64.
However, it can still be added if needed.

if classifier == "linux-x86_64":
return "x86_64-unknown-linux-gnu"
if classifier == "windows-x86_64":
Expand All @@ -39,8 +37,6 @@ def classifier_to_target(classifier: str) -> str:
def get_cargo_artifact_name(classifier: str) -> str:
if classifier == "osx-aarch_64":
return "libopendal_dotnet.dylib"
if classifier == "osx-x86_64":
return "libopendal_dotnet.dylib"
if classifier == "linux-x86_64":
return "libopendal_dotnet.so"
if classifier == "windows-x86_64":
Expand Down
Loading