Skip to content

Commit 643b9e3

Browse files
authored
chore(bindings/dotnet): update framework and use LibraryImport (#7222)
1 parent ef35d31 commit 643b9e3

File tree

8 files changed

+110
-54
lines changed

8 files changed

+110
-54
lines changed

.github/workflows/ci_bindings_dotnet.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,55 @@ permissions:
4040
contents: read
4141

4242
jobs:
43-
test:
43+
check:
4444
runs-on: ubuntu-latest
4545
steps:
4646
- uses: actions/checkout@v6
4747
- name: Setup dotnet toolchain
4848
uses: actions/setup-dotnet@v5
4949
with:
50-
dotnet-version: '7.0.x'
50+
dotnet-version: '10.0.x'
5151
- name: Setup Rust toolchain
5252
uses: ./.github/actions/setup
53+
with:
54+
need-nextest: true
55+
need-protoc: true
56+
need-rocksdb: true
57+
github-token: ${{ secrets.GITHUB_TOKEN }}
5358

5459
- name: Clippy Check
5560
working-directory: "bindings/dotnet"
5661
run: |
5762
cargo clippy -- -D warnings
5863
64+
test:
65+
runs-on: ${{ matrix.os }}
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
os:
70+
- ubuntu-latest
71+
- macos-latest
72+
- windows-latest
73+
dotnet-version:
74+
- '8.0.x'
75+
- '10.0.x'
76+
steps:
77+
- uses: actions/checkout@v6
78+
- name: Setup dotnet toolchain
79+
uses: actions/setup-dotnet@v5
80+
with:
81+
dotnet-version: ${{ matrix.dotnet-version }}
82+
- name: Setup Rust toolchain
83+
uses: ./.github/actions/setup
84+
with:
85+
need-nextest: true
86+
need-protoc: true
87+
need-rocksdb: true
88+
github-token: ${{ secrets.GITHUB_TOKEN }}
89+
5990
- name: Build & Test
6091
working-directory: "bindings/dotnet"
6192
run: |
6293
cargo build
63-
dotnet test
94+
dotnet test -f ${{ matrix.dotnet-version == '8.0.x' && 'net8.0' || 'net10.0' }}

bindings/dotnet/Cargo.toml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ doc = false
3434
# this crate won't be published, we always use the local version
3535
opendal = { version = ">=0", path = "../../core", features = [
3636
"blocking",
37+
"reqwest-rustls-tls",
38+
"executors-tokio",
3739

38-
# These are default features before v0.46. TODO: change to optional features
40+
# enabled layers
41+
"layers-concurrent-limit",
42+
"layers-logging",
43+
"layers-retry",
44+
"layers-timeout",
45+
46+
# enabled services
3947
"services-azblob",
4048
"services-azdls",
4149
"services-cos",
@@ -50,6 +58,45 @@ opendal = { version = ">=0", path = "../../core", features = [
5058
"services-s3",
5159
"services-webdav",
5260
"services-webhdfs",
61+
"services-aliyun-drive",
62+
"services-cacache",
63+
"services-dashmap",
64+
"services-dropbox",
65+
"services-etcd",
66+
# FIXME this requires a preinstalled fdb library
67+
# "services-foundationdb",
68+
# FIXME requires openssl.
69+
# "services-ftp",
70+
"services-gdrive",
71+
# FIXME how to support HDFS services in bindings?
72+
# "services-hdfs",
73+
# "services-hdfs-native",
74+
"services-hf",
75+
"services-ipfs",
76+
"services-memcached",
77+
"services-mini-moka",
78+
"services-moka",
79+
"services-onedrive",
80+
"services-persy",
81+
"services-postgresql",
82+
"services-koofr",
83+
"services-mysql",
84+
"services-redb",
85+
"services-redis",
86+
# FIXME: rocksdb will lead to "cannot allocate memory in static TLS block" while linking.
87+
# "services-rocksdb",
88+
"services-sled",
89+
"services-tikv",
90+
"services-vercel-artifacts",
91+
"services-mongodb",
92+
"services-gridfs",
93+
"services-sqlite",
5394
"services-azfile",
95+
"services-swift",
96+
"services-alluxio",
97+
"services-b2",
98+
"services-seafile",
99+
"services-upyun",
100+
"services-yandex-disk",
54101
] }
55-
tokio = { version = "1", features = ["full"] }
102+
tokio = { version = "1.49.0", features = ["full"] }

bindings/dotnet/DotOpenDAL.Tests/DotOpenDAL.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -13,7 +13,7 @@
1313
<ProjectReference Include="../DotOpenDAL/DotOpenDAL.csproj" />
1414
</ItemGroup>
1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1717
<PackageReference Include="xunit" Version="2.4.2" />
1818
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

bindings/dotnet/DotOpenDAL/BlockingOperator.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace DotOpenDAL;
2424

25-
public class BlockingOperator
25+
public partial class BlockingOperator
2626
{
2727
public IntPtr Op { get; }
2828

@@ -41,24 +41,12 @@ public string Read(string path)
4141
return blocking_operator_read(Op, path);
4242
}
4343

44-
[DllImport(
45-
"opendal_dotnet",
46-
EntryPoint = "blocking_operator_construct",
47-
CallingConvention = CallingConvention.Cdecl,
48-
CharSet = CharSet.Auto)]
49-
private static extern IntPtr blocking_operator_construct(string scheme);
44+
[LibraryImport("opendal_dotnet", EntryPoint = "blocking_operator_construct", StringMarshalling = StringMarshalling.Utf8)]
45+
private static partial IntPtr blocking_operator_construct(string scheme);
5046

51-
[DllImport(
52-
"opendal_dotnet",
53-
EntryPoint = "blocking_operator_write",
54-
CallingConvention = CallingConvention.Cdecl,
55-
CharSet = CharSet.Auto)]
56-
private static extern void blocking_operator_write(IntPtr op, string path, string content);
47+
[LibraryImport("opendal_dotnet", EntryPoint = "blocking_operator_write", StringMarshalling = StringMarshalling.Utf8)]
48+
private static partial void blocking_operator_write(IntPtr op, string path, string content);
5749

58-
[DllImport(
59-
"opendal_dotnet",
60-
EntryPoint = "blocking_operator_read",
61-
CallingConvention = CallingConvention.Cdecl,
62-
CharSet = CharSet.Auto)]
63-
private static extern string blocking_operator_read(IntPtr op, string path);
50+
[LibraryImport("opendal_dotnet", EntryPoint = "blocking_operator_read", StringMarshalling = StringMarshalling.Utf8)]
51+
private static partial string blocking_operator_read(IntPtr op, string path);
6452
}

bindings/dotnet/DotOpenDAL/DotOpenDAL.csproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,24 @@
1111
<Copyright>$(Company)</Copyright>
1212
<PackageTags>Apache;OpenDAL</PackageTags>
1313
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
14-
15-
<TargetFramework>net7.0</TargetFramework>
14+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
15+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
1616
<ImplicitUsings>enable</ImplicitUsings>
1717
<Nullable>enable</Nullable>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<None Include="../target/debug/libopendal_dotnet.*">
22-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
<!-- Linux/macOS -->
22+
<None Include="../target/debug/libopendal_dotnet.*"
23+
Condition="'$(OS)' != 'Windows_NT'">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
26+
27+
<!-- Windows -->
28+
<None Include="../target/debug/opendal_dotnet.dll"
29+
Condition="'$(OS)' == 'Windows_NT'">
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2331
</None>
2432
</ItemGroup>
2533

26-
</Project>
34+
</Project>

bindings/dotnet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This binding is currently under development. Please check back later.
1010

1111
To compile OpenDAL .NET binding from source code, you need:
1212

13-
- [.NET](https://dotnet.microsoft.com/en-us/download/dotnet) version 7.0
13+
- [.NET](https://dotnet.microsoft.com/en-us/download/dotnet) version 10.0
1414

1515
```bash
1616
cargo build

bindings/dotnet/dotnet.sln

Lines changed: 0 additions & 22 deletions
This file was deleted.

bindings/dotnet/dotnet.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Solution>
2+
<Project Path="DotOpenDAL.Tests/DotOpenDAL.Tests.csproj" />
3+
<Project Path="DotOpenDAL/DotOpenDAL.csproj" />
4+
</Solution>

0 commit comments

Comments
 (0)