Skip to content

Commit 1ad4795

Browse files
committed
Initial commit
0 parents  commit 1ad4795

File tree

14 files changed

+544
-0
lines changed

14 files changed

+544
-0
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
- package-ecosystem: "nuget"
8+
directory: "/src/"
9+
schedule:
10+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: 'CI'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
publish_release:
7+
description: If this build should publish nuget packages
8+
required: true
9+
type: boolean
10+
version_suffix:
11+
description: Suffix of the version number. Can be used to create a preview package.
12+
required: false
13+
type: string
14+
push:
15+
branches:
16+
- main
17+
paths-ignore:
18+
- '**.md'
19+
pull_request:
20+
21+
env:
22+
configuration: Release
23+
publish_release: ${{ github.event.inputs.publish_release }}
24+
version_suffix: ${{ github.event.inputs.version_suffix }}
25+
tester_framework: net8.0
26+
27+
jobs:
28+
build:
29+
name: Build
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
matrix:
33+
os: [ windows-latest, macos-latest, ubuntu-latest ]
34+
35+
steps:
36+
- name: Checkout with submodules
37+
uses: actions/checkout@v4
38+
with:
39+
submodules: 'true'
40+
41+
- name: Prepare .NET
42+
uses: actions/setup-dotnet@v4
43+
with:
44+
dotnet-version: |
45+
6.0.x
46+
8.0.x
47+
48+
- name: Verify code format
49+
if: matrix.os == 'ubuntu-latest'
50+
run: dotnet format --verify-no-changes
51+
working-directory: './src'
52+
53+
- name: Run unit tests ubuntu
54+
if: matrix.os == 'ubuntu-latest'
55+
env:
56+
RuntimeIdentifier: unix
57+
run: dotnet test -c ${{ env.configuration }}
58+
working-directory: './src'
59+
60+
- name: Run unit tests macos
61+
if: matrix.os == 'macos-latest'
62+
env:
63+
RuntimeIdentifier: unix
64+
run: dotnet test -c ${{ env.configuration }}
65+
working-directory: './src'
66+
67+
- name: Run unit tests windows
68+
if: matrix.os == 'windows-latest'
69+
env:
70+
RuntimeIdentifier: windows
71+
run: dotnet test -c ${{ env.configuration }}
72+
working-directory: './src'
73+
74+
- name: Build solution
75+
run: dotnet fsi build.fsx
76+
working-directory: './src'
77+
78+
- name: Pack release version
79+
if: env.publish_release == 'true' && matrix.os == 'ubuntu-latest'
80+
run: dotnet pack WCharT.Net/WCharT.Net.csproj --no-build --nologo -c ${{ env.configuration }} --version-suffix "${{ env.version_suffix }}" -o ../Nuget
81+
working-directory: './src'
82+
83+
- name: Publish to nuget org
84+
if: env.publish_release == 'true' && matrix.os == 'ubuntu-latest'
85+
run: dotnet nuget push "*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s nuget.org
86+
working-directory: './Nuget'

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Build results
2+
[Dd]ebug/
3+
[Rr]elease/
4+
[Bb]in/
5+
[Oo]bj/
6+
*.Artifacts
7+
8+
*.nupkg
9+
10+
#.vscode/
11+
global.json
12+
coverage.*
13+
14+
*~
15+
16+
#meson
17+
18+
#Rider
19+
*.idea
20+
21+
# Visual Studio
22+
.vs/
23+
*.DotSettings.user
24+
25+
#Docs
26+
_site/

license.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Marcel Tiede
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

readme.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# WCharT.Net
2+
[![Build Status](https://img.shields.io/github/actions/workflow/status/badcel/WCharT.Net/ci.yml?branch=main)](https://github.com/badcel/WCharT.Net/actions/workflows/ci.yml)[![NuGet](https://img.shields.io/nuget/v/WCharT.Net)](https://www.nuget.org/packages/WCharT.Net/)[![License (MIT)](https://img.shields.io/github/license/badcel/WCharT.Net)](https://github.com/badcel/WCharT.Net/blob/main/license.txt)
3+
4+
Welcome to WCharT.Net a modern cross platform package to interop with WCharT data.
5+
6+
## Use
7+
To work with WCharT data create a new instance of `WCharTString`:
8+
9+
```csharp
10+
//Read data from a byte*
11+
byte* pointer = NativeCal();
12+
var data = new WCharTString(pointer).GetString();
13+
14+
//Create a buffer for a native library and read the data after it was filled
15+
ReadOnlySpan<byte> data = new WCharTString(int bufferCharSize);
16+
NativeCall(data);
17+
var str = data.GetString();
18+
19+
//Pass a string to a native library
20+
ReadOnlySpan<byte> data = new WCharTString(string str);
21+
NativeCall(data);
22+
```
23+
24+
## Build
25+
To build the solution locally execute the following commands:
26+
27+
```sh
28+
$ git clone https://github.com/badcel/WCharT.Net.git
29+
$ cd WCharT.Net/src
30+
$ dotnet fsi build.fsx
31+
```
32+
33+
## Native AOT
34+
If the application targets at least .NET 8 the nuget package allows applications to be published as _Native AOT_ as itself is AOT compatible.
35+
36+
## Licensing terms
37+
HidApi.Net is licensed under the terms of the MIT-License. Please see the [license file][license] for further information.
38+
39+
[license]:https://github.com/badcel/WCharT.Net/blob/main/license.txt

src/Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<PropertyGroup>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<AnalysisMode>Recommended</AnalysisMode>
8+
</PropertyGroup>
9+
</Project>

src/WCharT.Net.Tests/Tests.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
using FluentAssertions;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace WCharT.Tests;
7+
8+
[TestClass]
9+
public class Tests
10+
{
11+
[TestMethod]
12+
public void TestEncoding()
13+
{
14+
var text = "Test";
15+
var str = new WCharTString(text);
16+
17+
str.GetString().Should().Be(text);
18+
}
19+
20+
[TestMethod]
21+
public void TestUnicode()
22+
{
23+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
24+
Assert.Inconclusive("Unicode is only supported on windows based operating systems");
25+
26+
#pragma warning disable CA1861
27+
var data = new byte[6];
28+
data[0] = 0;
29+
data[1] = 1;
30+
data[2] = 0;
31+
data[3] = 1;
32+
data[4] = 0;
33+
data[5] = 0;
34+
35+
unsafe
36+
{
37+
fixed (byte* p = data)
38+
{
39+
var str = new WCharTString(p);
40+
str.GetString().Should().Be(new string(new[] { '\u0100', '\u0100' }));
41+
}
42+
}
43+
#pragma warning restore CA1861
44+
}
45+
46+
[TestMethod]
47+
public void TestUtf32()
48+
{
49+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
50+
Assert.Inconclusive("Utf32 is only supported on unix based operating systems");
51+
52+
#pragma warning disable CA1861
53+
var data = new byte[12];
54+
data[0] = 0;
55+
data[1] = 1;
56+
data[2] = 0;
57+
data[3] = 0;
58+
data[4] = 0;
59+
data[5] = 1;
60+
data[6] = 0;
61+
data[7] = 0;
62+
data[8] = 0;
63+
data[9] = 0;
64+
data[10] = 0;
65+
data[11] = 0;
66+
67+
unsafe
68+
{
69+
fixed (byte* p = data)
70+
{
71+
var str = new WCharTString(p);
72+
str.GetString().Should().Be(new string(new[] { '\u0100', '\u0100' }));
73+
}
74+
}
75+
#pragma warning restore CA1861
76+
}
77+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<IsPackable>false</IsPackable>
4+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
<RootNamespace>WCHarT.Tests</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="3.2.1" />
12+
<PackageReference Include="MSTest.TestFramework" Version="3.2.1" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\WCharT.Net\WCharT.Net.csproj" />
17+
</ItemGroup>
18+
</Project>

src/WCharT.Net/WCharT.Net.csproj

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<VersionPrefix>0.1.0</VersionPrefix>
4+
5+
<Authors>Marcel Tiede</Authors>
6+
<Copyright>Marcel Tiede</Copyright>
7+
<owners>badcel</owners>
8+
9+
<Description>A modern cross platform package to interop with WCharT data.</Description>
10+
<PackageProjectUrl>https://github.com/badcel/WCharT</PackageProjectUrl>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
13+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
14+
15+
<PackageReadmeFile>readme.md</PackageReadmeFile>
16+
<PackageTags>wchart;native;interop;linux;windows;macos</PackageTags>
17+
</PropertyGroup>
18+
19+
<PropertyGroup>
20+
<RootNamespace>WCharT</RootNamespace>
21+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
22+
23+
<BUILD_FOR Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier.ToUpper())</BUILD_FOR>
24+
<BUILD_FOR Condition="'$(RuntimeIdentifier)' == ''">UNIX</BUILD_FOR>
25+
<DefineConstants>$(DefineConstants);BUILD_FOR_$(BUILD_FOR)</DefineConstants>
26+
27+
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
28+
<IncludeBuildOutput>false</IncludeBuildOutput>
29+
<NoWarn>NU5131</NoWarn>
30+
</PropertyGroup>
31+
32+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
33+
<IsAotCompatible>true</IsAotCompatible>
34+
</PropertyGroup>
35+
36+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
37+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
38+
</PropertyGroup>
39+
40+
<ItemGroup>
41+
<None Include="../../readme.md" Pack="true" PackagePath="/" Visible="false"/>
42+
<None Include="obj/Release/net6.0/ref/WCharT.Net.dll" Pack="true" PackagePath="ref/net6.0" Visible="false"/>
43+
<None Include="bin/Release/net6.0/unix/WCharT.Net.dll" Pack="true" PackagePath="runtimes/unix/lib/net6.0" Visible="false"/>
44+
<None Include="bin/Release/net6.0/windows/WCharT.Net.dll" Pack="true" PackagePath="runtimes/windows/lib/net6.0" Visible="false"/>
45+
<None Include="obj/Release/net8.0/ref/WCharT.Net.dll" Pack="true" PackagePath="ref/net8.0" Visible="false"/>
46+
<None Include="bin/Release/net8.0/unix/WCharT.Net.dll" Pack="true" PackagePath="runtimes/unix/lib/net8.0" Visible="false"/>
47+
<None Include="bin/Release/net8.0/windows/WCharT.Net.dll" Pack="true" PackagePath="runtimes/windows/lib/net8.0" Visible="false"/>
48+
</ItemGroup>
49+
50+
<ItemGroup>
51+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'"/>
52+
</ItemGroup>
53+
</Project>

0 commit comments

Comments
 (0)