Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono AOT Validation #427

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/MonoAotValidation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Mono Aot Validation

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

jobs:
build:
strategy:
max-parallel: 1
matrix:
include:
- os: ubuntu-latest
rid: linux-x64

runs-on: ${{ matrix.os }}
env:
AppVeyorBuild: true
steps:
- uses: actions/checkout@v2

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

- name: Install Mono
run: sudo apt install mono-complete

- name: AOT Compile mscorlib
run: sudo mono -O=all --aot=full /usr/lib/mono/4.5/mscorlib.dll

- name: AOT Compile Other Libs
run: for i in /usr/lib/mono/gac/*/*/*.dll; do sudo mono -O=all --aot=full $i; done

- 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/CompileTests/NativeAot/*.fbs) -join ";"
dotnet src/FlatSharp.Compiler/bin/Release/net8.0/FlatSharp.Compiler.dll --nullable-warnings false --normalize-field-names true --input "$fbs" -o src/Tests/CompileTests/NativeAot

- name: Build
working-directory: src/Tests/CompileTests/NativeAot
run: dotnet build -c Release

- name: AOT Exes
working-directory: src/Tests/CompileTests/NativeAot/bin/Release/net472
run: mono -O=all --aot=full *.exe

- name: AOT DLLs
working-directory: src/Tests/CompileTests/NativeAot/bin/Release/net472
run: mono -O=all --aot=full *.dll

- name: Run (No AOT)
working-directory: src/Tests/CompileTests/NativeAot/bin/Release/net472
run: mono NativeAot.exe

- name: Run (AOT)
working-directory: src/Tests/CompileTests/NativeAot/bin/Release/net472
run: mono --full-aot NativeAot.exe

- name: Upload Files
uses: actions/upload-artifact@v3
with:
name: assembly
path: src/Tests/CompileTests/NativeAot/bin/**/*.*
8 changes: 6 additions & 2 deletions src/Tests/CompileTests/NativeAot/NativeAot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<LangVersion>11.0</LangVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' != 'net472' ">
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 10 additions & 4 deletions src/Tests/CompileTests/NativeAot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ private static void RunBenchmark()
}
sw.Stop();

Console.WriteLine($"Serialization complete. Bytes written = {bytesWritten}. TotalTime = {sw.Elapsed.TotalMicroseconds:N0}us");
Console.WriteLine($"Serialization complete. Bytes written = {bytesWritten}. TotalTime = {sw.Elapsed.TotalMilliseconds:N0}ms");
Console.WriteLine();

foreach (var option in Enum.GetValues<FlatBufferDeserializationOption>())
#if NETCOREAPP
FlatBufferDeserializationOption[] options = Enum.GetValues<FlatBufferDeserializationOption>();
#else
FlatBufferDeserializationOption[] options = (FlatBufferDeserializationOption[])Enum.GetValues(typeof(FlatBufferDeserializationOption));
#endif

foreach (FlatBufferDeserializationOption option in options)
{
BenchmarkTraverse<ArrayInputBuffer>(root, new(buffer), option);
BenchmarkTraverse<MemoryInputBuffer>(root, new(buffer), option);
BenchmarkTraverse<ReadOnlyMemoryInputBuffer>(root, new(buffer), option);
BenchmarkTraverse<ArraySegmentInputBuffer>(root, new(buffer), option);
BenchmarkTraverse<ArraySegmentInputBuffer>(root, new(new ArraySegment<byte>(buffer)), option);
BenchmarkTraverse<CustomInputBuffer>(root, new(new ArrayInputBuffer(buffer)), option);
Console.WriteLine();
}
Expand Down Expand Up @@ -264,7 +270,7 @@ public static void BenchmarkTraverse<TInputBuffer>(Root original, TInputBuffer b
}
sw.Stop();

Console.WriteLine($"Parsing [ {option} ][ {typeof(TInputBuffer).Name} ]. TotalTime = {sw.Elapsed.TotalMicroseconds:N0}us");
Console.WriteLine($"Parsing [ {option} ][ {typeof(TInputBuffer).Name} ]. TotalTime = {sw.Elapsed.TotalMilliseconds:N0}ms");

static void ParseAndTraverse(Root original, TInputBuffer buffer, FlatBufferDeserializationOption option)
{
Expand Down
Loading