mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 10:00:14 +01:00
basics for uniffi
This commit is contained in:
parent
12ba47a281
commit
07a1b8810c
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,8 +1,6 @@
|
||||||
target
|
target
|
||||||
.idea
|
.idea
|
||||||
out
|
out
|
||||||
bin
|
|
||||||
obj
|
|
||||||
.direnv
|
.direnv
|
||||||
.envrc
|
.envrc
|
||||||
result
|
result
|
||||||
|
|
|
@ -3,7 +3,8 @@ resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/servicepoint",
|
"crates/servicepoint",
|
||||||
"crates/servicepoint_binding_c",
|
"crates/servicepoint_binding_c",
|
||||||
"crates/servicepoint_binding_c/examples/lang_c"
|
"crates/servicepoint_binding_c/examples/lang_c",
|
||||||
|
"crates/servicepoint_binding_uniffi"
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|
49
crates/servicepoint_binding_uniffi/Cargo.toml
Normal file
49
crates/servicepoint_binding_uniffi/Cargo.toml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
[package]
|
||||||
|
name = "servicepoint_binding_uniffi"
|
||||||
|
version.workspace = true
|
||||||
|
publish = false
|
||||||
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-or-later"
|
||||||
|
description = "C bindings for the servicepoint crate."
|
||||||
|
homepage = "https://docs.rs/crate/servicepoint_binding_c"
|
||||||
|
repository = "https://github.com/cccb/servicepoint"
|
||||||
|
#readme = "README.md"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
uniffi = { version = "0.25.0" , features = [ "build" ] }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
uniffi = { version = "0.25.0" }
|
||||||
|
thiserror = "1.0.66"
|
||||||
|
|
||||||
|
[dependencies.servicepoint]
|
||||||
|
version = "0.11.0"
|
||||||
|
path = "../servicepoint"
|
||||||
|
features = ["all_compressions"]
|
||||||
|
|
||||||
|
[dependencies.uniffi-bindgen-cs]
|
||||||
|
git="https://github.com/NordSecurity/uniffi-bindgen-cs"
|
||||||
|
# tag="v0.8.3+v0.25.0"
|
||||||
|
rev="f68639fbc720b50ebe561ba75c66c84dc456bdce"
|
||||||
|
optional=true
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
#workspace = true
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "uniffi-bindgen"
|
||||||
|
required-features = ["uniffi/cli"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "uniffi-bindgen-cs"
|
||||||
|
required-features= ["cs"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
cs = ["dep:uniffi-bindgen-cs"]
|
19
crates/servicepoint_binding_uniffi/generate-bindings.sh
Executable file
19
crates/servicepoint_binding_uniffi/generate-bindings.sh
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
TARGETPATH="$(realpath $SCRIPTPATH/../../target/release/)"
|
||||||
|
SERVICEPOINT_SO="$TARGETPATH/libservicepoint_binding_uniffi.so"
|
||||||
|
CONFIG_TOML="$(realpath $SCRIPTPATH/../uniffi.toml)"
|
||||||
|
|
||||||
|
BINDGEN="cargo run --features=uniffi/cli --bin uniffi-bindgen -- "
|
||||||
|
BINDGEN_CS="cargo run --features=cs --bin uniffi-bindgen-cs -- "
|
||||||
|
COMMON_ARGS="--library $SERVICEPOINT_SO"
|
||||||
|
|
||||||
|
${BINDGEN} generate $COMMON_ARGS --language python --out-dir libraries/python
|
||||||
|
${BINDGEN} generate $COMMON_ARGS --language kotlin --out-dir libraries/kotlin
|
||||||
|
${BINDGEN} generate $COMMON_ARGS --language swift --out-dir libraries/swift
|
||||||
|
${BINDGEN_CS} $COMMON_ARGS --out-dir libraries/csharp/ServicePoint
|
2
crates/servicepoint_binding_uniffi/libraries/csharp/.gitignore
vendored
Normal file
2
crates/servicepoint_binding_uniffi/libraries/csharp/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bin
|
||||||
|
obj
|
2
crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint.Example/.gitignore
vendored
Normal file
2
crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint.Example/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bin
|
||||||
|
obj
|
|
@ -0,0 +1,5 @@
|
||||||
|
using ServicePoint;
|
||||||
|
|
||||||
|
var connection = new Connection("");
|
||||||
|
|
||||||
|
var clear = new Clear();
|
|
@ -0,0 +1,15 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RootNamespace>ServicePoint.Example</RootNamespace>
|
||||||
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../ServicePoint/ServicePoint.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,27 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../ServicePoint/ServicePoint.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.5.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
using ServicePoint;
|
||||||
|
|
||||||
|
namespace ServicePoint.Tests;
|
||||||
|
|
||||||
|
public class UnitTest1
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test1()
|
||||||
|
{
|
||||||
|
Assert.Throws<ConnectionException.IoException>(() => new Connection(""));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<PackageId>ServicePoint</PackageId>
|
||||||
|
<Version>0.10.0</Version>
|
||||||
|
<Authors>Repository Authors</Authors>
|
||||||
|
<Company>None</Company>
|
||||||
|
<Product>ServicePoint</Product>
|
||||||
|
<PackageTags>CCCB</PackageTags>
|
||||||
|
<Description>
|
||||||
|
C# bindings for the rust crate servicepoint. You will need a suitable native shared library to use this.
|
||||||
|
For documentation, see the rust documentation: https://docs.rs/servicepoint/latest/servicepoint/.
|
||||||
|
Note that this library is still in early development. Breaking changes are expected before 1.0 is released.
|
||||||
|
</Description>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- generate C# bindings -->
|
||||||
|
<Target Name="BuildBindings" Condition="'$(Configuration)'=='Release'" BeforeTargets="PrepareForBuild">
|
||||||
|
<Exec Command="cargo build -p servicepoint_binding_uniffi --release"/>
|
||||||
|
</Target>
|
||||||
|
<Target Name="BuildBindings" Condition="'$(Configuration)'=='Debug'" BeforeTargets="PrepareForBuild">
|
||||||
|
<Exec Command="cargo build -p servicepoint_binding_uniffi"/>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- include native binary in output -->
|
||||||
|
<ItemGroup Condition="'$(Configuration)'=='Debug'">
|
||||||
|
<Content Include="../../../../../target/debug/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||||
|
<Link>libservicepoint_binding_uniffi.so</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup Condition="'$(Configuration)'=='Release'">
|
||||||
|
<Content Include="../../../../../target/release/libservicepoint_binding_uniffi.so" CopyToOutputDirectory="Always">
|
||||||
|
<Link>libservicepoint_binding_uniffi.so</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- add README.md to package -->
|
||||||
|
<None Include="../README.md" Pack="true" PackagePath="\"/>
|
||||||
|
<!-- include link to source code at revision -->
|
||||||
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.0.31903.59
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint", "ServicePoint\ServicePoint.csproj", "{53576D3C-E32E-49BF-BF10-2DB504E50CE1}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint.Example", "ServicePoint.Example\ServicePoint.Example.csproj", "{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServicePoint.Tests", "ServicePoint.Tests\ServicePoint.Tests.csproj", "{9DC15508-A980-4135-9FC6-659FF54B4E5C}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{53576D3C-E32E-49BF-BF10-2DB504E50CE1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{FEF24227-090E-46C2-B8F6-ACB5AA1A4309}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9DC15508-A980-4135-9FC6-659FF54B4E5C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
uniffi_bindgen_cs::main().unwrap();
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
uniffi::uniffi_bindgen_main()
|
||||||
|
}
|
20
crates/servicepoint_binding_uniffi/src/command.rs
Normal file
20
crates/servicepoint_binding_uniffi/src/command.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
trait Command: Send + Sync {}
|
||||||
|
|
||||||
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct Clear {
|
||||||
|
actual: servicepoint::Command,
|
||||||
|
}
|
||||||
|
#[uniffi::export]
|
||||||
|
impl Command for Clear {}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
impl Clear {
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new() -> Arc<Self> {
|
||||||
|
let actual = servicepoint::Command::Clear;
|
||||||
|
Arc::new(Clear { actual })
|
||||||
|
}
|
||||||
|
}
|
23
crates/servicepoint_binding_uniffi/src/connection.rs
Normal file
23
crates/servicepoint_binding_uniffi/src/connection.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
use std::{sync::Arc};
|
||||||
|
|
||||||
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct Connection {
|
||||||
|
actual: servicepoint::Connection,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(uniffi::Error, thiserror::Error, Debug)]
|
||||||
|
pub enum ConnectionError {
|
||||||
|
#[error("An IO error occured: {error}")]
|
||||||
|
IOError {
|
||||||
|
error: String}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
impl Connection {
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new(host: String) -> Result<Arc<Self>, ConnectionError> {
|
||||||
|
servicepoint::Connection::open(host)
|
||||||
|
.map(|actual|Arc::new(Connection { actual}) )
|
||||||
|
.map_err(|err| ConnectionError::IOError { error: err.to_string()})
|
||||||
|
}
|
||||||
|
}
|
4
crates/servicepoint_binding_uniffi/src/lib.rs
Normal file
4
crates/servicepoint_binding_uniffi/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
uniffi::setup_scaffolding!();
|
||||||
|
|
||||||
|
mod command;
|
||||||
|
mod connection;
|
3
crates/servicepoint_binding_uniffi/uniffi.toml
Normal file
3
crates/servicepoint_binding_uniffi/uniffi.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[bindings.csharp]
|
||||||
|
namespace = "ServicePoint"
|
||||||
|
access_modifier = "public"
|
Loading…
Reference in a new issue