Skip to content

Commit

Permalink
vNext (#166)
Browse files Browse the repository at this point in the history
* Simplify code

* Move around code

* Move around code

* Cleanup and simplify code

* Upgrade to .NET 9

* Upgrade with unit tests

* Use .NET 9 in GitHub actions

* Fix missing new line in Interop gen

* Use .NET 9 in releases GitHub action

* Remove unused step in GitHub actions

* Fix whitespacing in gen for #region

* Rename for `Interop` namespace

* Fix for `CStringWide`

* Use `InputSantitized` directly

* Add back support for config mapped names
  • Loading branch information
lithiumtoast authored Jan 2, 2025
1 parent b0441c1 commit ddf4296
Show file tree
Hide file tree
Showing 166 changed files with 3,364 additions and 5,963 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ on:
workflow_dispatch:
inputs:
pre-release:
description: 'Is pre-release? (NOTE: Pre-releases are uploaded to MyGet.org instead of NuGet.org.)'
description: 'Is pre-release? (NOTE: Pre-releases are uploaded to MyGet.org instead of NuGet.org.)'
required: true
default: 'true'
version:
description: 'Version (NOTE: If left blank, the current date is used as the version.)'
description: 'Version (NOTE: If left blank, the current date is used as the version.)'
required: false
default: ''

Expand Down Expand Up @@ -43,7 +43,12 @@ jobs:
fi
echo "VERSION=$VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: "Setup .NET"
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.x'

- name: ".NET pack"
run: dotnet pack "./src/cs" --nologo --verbosity minimal --configuration Release -p:PackageVersion="${{ steps.set-version.outputs.VERSION }}" -p:RepositoryBranch="${{ github.head_ref || github.ref_name }}" -p:RepositoryCommit="${{ github.sha }}"
Expand All @@ -60,11 +65,10 @@ jobs:
NUGET_ACCESS_TOKEN: ${{ secrets.NUGET_ACCESS_TOKEN }}
run: dotnet nuget push "./nupkg/**/*.nupkg" --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key $NUGET_ACCESS_TOKEN

- name: "Create tag and GitHub release"
- name: "Create tag and GitHub release"
uses: softprops/action-gh-release@v1
if: github.event_name == 'schedule' || github.event.inputs.pre-release == 'false'
with:
generate_release_notes: true
prerelease: "{{ github.event.inputs.pre-release == 'true' }}"
tag_name: "v${{ steps.set-version.outputs.VERSION }}"

10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: "Setup .NET"
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'
dotnet-version: '9.x'

- name: "Install c2ffi"
shell: bash
Expand All @@ -46,11 +46,3 @@ jobs:
- name: "Test .NET solution"
run: |
dotnet test '${{ github.workspace }}/src/cs' --nologo --verbosity minimal --configuration Release
- name: "Collect generated test files"
uses: actions/upload-artifact@v3
if: github.event_name == 'pull_request'
with:
name: "Test Data ${{ matrix.platform.name }}"
path: |
${{ github.workspace }}/src/cs/tests/*.Tests/Data/Values/**/*.json
File renamed without changes.
8 changes: 8 additions & 0 deletions src/c/tests/enums/enum_uint8/config-generate-cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
File renamed without changes.
8 changes: 8 additions & 0 deletions src/c/tests/enums/enum_week_day/config-generate-cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
30 changes: 30 additions & 0 deletions src/c/tests/functions/function_implicit_enum/config-extract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"inputFilePath": "./main.c",
"userIncludeDirectories": [
"../../../production/ffi_helper/include"
],
"ignoredIncludeFiles": [
"../../../production/ffi_helper/include/ffi_helper.h"
],
"includedNames": [
"enum_implicit"
],
"targetPlatforms": {
"windows": {
"i686-pc-windows-msvc": {},
"x86_64-pc-windows-msvc": {},
"aarch64-pc-windows-msvc": {}
},
"macos": {
"i686-apple-darwin": {},
"aarch64-apple-darwin": {},
"x86_64-apple-darwin": {},
"aarch64-apple-ios": {}
},
"linux": {
"i686-unknown-linux-gnu": {},
"x86_64-unknown-linux-gnu": {},
"aarch64-unknown-linux-gnu": {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
12 changes: 12 additions & 0 deletions src/c/tests/functions/function_implicit_enum/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include "ffi_helper.h"

enum enum_implicit {
ENUM_IMPLICIT_VALUE0 = 0,
ENUM_IMPLICIT_VALUE1 = 255
} enum_implicit;

FFI_API_DECL int function_implicit_enum(int value)
{
return ENUM_IMPLICIT_VALUE1;
}
8 changes: 8 additions & 0 deletions src/c/tests/functions/function_int/config-generate-cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
4 changes: 4 additions & 0 deletions src/c/tests/functions/function_internal/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <stdio.h>
#include "ffi_helper.h"

#define UNKNOWN_CUSTOM_API_DECL
#define BAD_CUSTOM_API_DECL
#define GOOD_CUSTOM_API_DECL FFI_API_DECL

void function_internal_1()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"inputFilePath": "./ffi-x/cross-platform.json",
"outputFileDirectory": "./cs",
"namespaceName": "test_namespace",
"className": "test_class",
"isEnabledFileScopedNamespace": false,
"isEnabledLibraryImport": true
}
13 changes: 0 additions & 13 deletions src/c/tests/functions/function_void/CMakeLists.txt

This file was deleted.

23 changes: 19 additions & 4 deletions src/cs/.globalconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# NOTE: Requires .NET 5 SDK (VS2019 16.8 or later)
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig
is_global = true
global_level = 100

# StyleCop Rules
## Description: StyleCop code analysis rules for C# projects.
# Microsoft
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.IDE0008.severity = none
dotnet_diagnostic.IDE0041.severity = none
dotnet_diagnostic.IDE0046.severity = none
dotnet_diagnostic.IDE0055.severity = none
dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.IDE0161.severity = error
dotnet_diagnostic.IDE0210.severity = none
dotnet_diagnostic.IDE0301.severity = none
dotnet_diagnostic.CA1308.severity = none
dotnet_diagnostic.CA1515.severity = none
dotnet_diagnostic.CA1707.severity = error
dotnet_diagnostic.CA1812.severity = none

# StyleCop
dotnet_diagnostic.SA1300.severity = none
dotnet_diagnostic.SA1401.severity = none
dotnet_diagnostic.SA1402.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1602.severity = none
4 changes: 2 additions & 2 deletions src/cs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bottlenoselabs.Common.Tools" Version="*">
<PackageReference Include="bottlenoselabs.MSBuild.Extensions" Version="*">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="StyleCop.Analyzers.Unstable" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions src/cs/C2CS.sln → src/cs/c2cs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "production", "production",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{65B41709-3C9F-4556-83C8-A4380AC14E56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C2CS.Tests", "tests\C2CS.Tests\C2CS.Tests.csproj", "{1BE51A85-A187-46CC-A307-04A66316CD55}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "c2cs.Tests", "tests\c2cs.Tests\c2cs.Tests.csproj", "{1BE51A85-A187-46CC-A307-04A66316CD55}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{5657F8E9-D2C6-48EA-9556-1A358B2AE333}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helloworld", "helloworld", "{24028D61-CCE1-4893-9BD6-1D7C28563DC8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "helloworld-bindgen", "examples\helloworld\helloworld-bindgen\helloworld-bindgen.csproj", "{841E561C-B3BB-499B-AEB3-0874ACDDB2BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C2CS.Tool", "production\C2CS.Tool\C2CS.Tool.csproj", "{1B67F4A2-24E6-43A6-A031-918DD44CD991}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "c2cs.Tool", "production\c2cs.Tool\c2cs.Tool.csproj", "{1B67F4A2-24E6-43A6-A031-918DD44CD991}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bindgen.Runtime", "production\Bindgen.Runtime\Bindgen.Runtime.csproj", "{DB492E65-25D9-44A0-86F4-ABB07283BEE7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "c2cs.Interop.Runtime", "production\c2cs.Interop.Runtime\c2cs.Interop.Runtime.csproj", "{DB492E65-25D9-44A0-86F4-ABB07283BEE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "helloworld-app", "examples\helloworld\helloworld-app\helloworld-app.csproj", "{EA3E3362-32A5-4395-BF56-39BDBE2B7CC9}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@

// <auto-generated>
// This code was generated by the following tool on 2024-05-07 22:28:44 GMT-04:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
// This code was generated by the following tool on 2025-01-01 22:44:49 GMT-05:00:
// https://github.com/bottlenoselabs/c2cs (v2025-01-01 22:44:49 GMT-05:00)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
// ReSharper disable All

#region Template
#nullable enable
#pragma warning disable CS1591
#pragma warning disable CS8981
using Bindgen.Runtime;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#endregion
using System.Runtime.InteropServices;

#if NET7_0_OR_GREATER
// NOTE: Disabling runtime marshalling is preferred for performance improvements. You can learn more here: https://learn.microsoft.com/en-us/dotnet/standard/native-interop/disabled-marshalling
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@

// To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code.

// <auto-generated>
// This code was generated by the following tool on 2024-05-07 22:28:44 GMT-04:00:
// This code was generated by the following tool on 2025-01-01 22:44:49 GMT-05:00:
// https://github.com/bottlenoselabs/c2cs (v0.0.0.0)
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
// ReSharper disable All

#region Template
#pragma warning disable CS1591
#pragma warning disable CS8981
using Bindgen.Runtime;
// To disable generating this file set `isEnabledGeneratingRuntimeCode` to `false` in the config file for generating C# code.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#endregion

namespace Bindgen.Runtime;
namespace Interop.Runtime;

/// <summary>
/// A boolean value type with the same memory layout as a <see cref="byte" /> in both managed and unmanaged contexts;
Expand Down
Loading

0 comments on commit ddf4296

Please sign in to comment.