Skip to content

Commit

Permalink
Add C# 8 Build Step (#362)
Browse files Browse the repository at this point in the history
Validate C#8 compatibility
  • Loading branch information
jamescourtney authored Jan 25, 2023
1 parent 2515d92 commit f5b32f8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/charp8build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: C# 8 Build Verification

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: windows-2019
env:
AppVeyorBuild: true
steps:
- uses: actions/checkout@v2

- name: Setup .NET 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x

- name: Setup .NET 6
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Restore dependencies
working-directory: src
run: dotnet restore

- name: Build FlatSharp.Compiler
working-directory: src/FlatSharp.Compiler
run: dotnet build -c Release

- name: Run FlatSharp.Compiler
# You may pin to the exact commit or the version.
# uses: Amadevus/pwsh-script@97a8b211a5922816aa8a69ced41fa32f23477186
uses: Amadevus/pwsh-script@v2.0.3
with:
# PowerShell script to execute in Actions-hydrated context
script: |
$fbs = (gci -r src/tests/FlatsharpEndToEndTests/*.fbs | where Name -ne "AccessModifiers.fbs") -join ";"
dotnet src/FlatSharp.Compiler/bin/Release/net7.0/FlatSharp.Compiler.dll --nullable-warnings false --normalize-field-names true --input "$fbs" -o src/tests/CompileTests/CSharp8
- name: Build
working-directory: src/tests/CompileTests/CSharp8
run: dotnet build -c Release

- name: Upload Files
uses: actions/upload-artifact@v3
if: failure()
with:
name: generated-csharp
path: src/tests/CompileTests/CSharp8/**/*.*
11 changes: 8 additions & 3 deletions src/FlatSharp.Compiler/SchemaModel/RpcServiceSchemaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void DefineServerBaseClass(CodeWriter writer, Dictionary<string, string>
{
foreach (var method in this.calls)
{
writer.AppendLine($".AddMethod({methodNameMap[method.Name]}, serviceImpl == null ? null : serviceImpl.{method.Name})");
writer.AppendLine($".AddMethod({methodNameMap[method.Name]}, serviceImpl == null ? ({this.GetServerHandlerDelegateType(method)}?)null : serviceImpl.{method.Name})");
}

writer.AppendLine(".Build();");
Expand All @@ -234,7 +234,7 @@ private void DefineServerBaseClass(CodeWriter writer, Dictionary<string, string>
foreach (var method in this.calls)
{
string serverDelegate = GetServerHandlerDelegate(method);
writer.AppendLine($"serviceBinder.AddMethod({methodNameMap[method.Name]}, serviceImpl == null ? null : {serverDelegate});");
writer.AppendLine($"serviceBinder.AddMethod({methodNameMap[method.Name]}, serviceImpl == null ? ({this.GetServerHandlerDelegateType(method)}?)null : {serverDelegate});");
}
writer.AppendLine("#pragma warning restore CS8604");
}
Expand Down Expand Up @@ -568,8 +568,13 @@ private void WriteNoRequestParameterMethod(
}

private string GetServerHandlerDelegate(RpcCallSchemaModel call)
{
return $"new {this.GetServerHandlerDelegateType(call)}(serviceImpl.{call.Name})";
}

private string GetServerHandlerDelegateType(RpcCallSchemaModel call)
{
string methodType = GetGrpcMethodType(call.StreamingType);
return $"new {GrpcCore}.{methodType}ServerMethod<{call.RequestType}, {call.ResponseType}>(serviceImpl.{call.Name})";
return $"{GrpcCore}.{methodType}ServerMethod<{call.RequestType}, {call.ResponseType}>";
}
}
24 changes: 24 additions & 0 deletions src/Tests/CompileTests/CSharp8/CSharp8.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netstandard2.0;netstandard2.1</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyName>CSharp8CompileTest</AssemblyName>
<RootNamespace>CSharp8CompileTest</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>annotations</Nullable>
<NoWarn>CS1591</NoWarn>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Core" Version="2.46.5" />
<PackageReference Include="Grpc.Core.Api" Version="2.49.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\FlatSharp.Runtime\FlatSharp.Runtime.csproj" />
</ItemGroup>
</Project>

0 comments on commit f5b32f8

Please sign in to comment.