-
Notifications
You must be signed in to change notification settings - Fork 21
perf: Add NativeAOT Support #554
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c6c700a
feat: enhance ValueJsonConverter for AOT compatibility with manual JS…
askpt bdb394b
feat: refactor EnumExtensions to improve AOT compatibility and remove…
askpt c41cab7
feat: add OpenFeatureJsonSerializerContext for AOT compilation support
askpt 56608c0
feat: add AOT and trimming support for net8.0 and net9.0
askpt ed39652
feat: add NativeAOT compatibility tests and project configuration
askpt 6f5390a
feat: update project structure for AOT compatibility and add MultiPro…
askpt 5c794e4
fix: remove unnecessary Type attribute project in solution file
askpt 5cd179e
feat: add unit tests for EnumExtensions.GetDescription method
askpt 1c54a7f
fix: remove trimming support properties for net8.0 and net9.0
askpt f62a88d
feat: add AOT compatibility workflow with cross-platform testing and …
askpt f8f90fc
fix: simplify AOT compatibility workflow by removing unnecessary prop…
askpt df63171
fix: update AOT compatibility workflow to include runtime in publish …
askpt ea053a3
fix: update AOT compatibility workflow to streamline ARM64 handling a…
askpt 4cc832e
fix: standardize shell usage and update publish command syntax in AOT…
askpt f462b4e
fix: update AOT size comparison report to remove AspNetCore sample co…
askpt 71c2bc4
fix: remove AOT size comparison job and artifact upload steps from wo…
askpt 2895325
fix: update AOT compatibility workflow permissions and enhance docume…
askpt 1086914
fix: streamline AOT compatibility documentation by removing redundant…
askpt f005f9e
fix: update actions/checkout and actions/cache versions in AOT compat…
askpt f36d20f
Apply suggestions from code review
askpt d93dd2d
Update .github/workflows/aot-compatibility.yml
askpt d05fa4e
fix: remove unnecessary properties from AOT project configuration
askpt 5994f99
docs: update README to clarify NativeAOT compatibility for contrib an…
askpt 14a881e
Apply suggestions from code review
askpt 92339a6
fix: add descriptions to ErrorType enum values for better clarity
askpt 67559c9
fix: remove AOT compatibility references and enhance error handling t…
askpt 2cadd2a
fix: update System.Text.Json package reference in project files
askpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: AOT Compatibility | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
merge_group: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
aot-compatibility: | ||
name: AOT Test (${{ matrix.os }}, ${{ matrix.arch }}) | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
# Linux x64 | ||
- os: ubuntu-latest | ||
arch: x64 | ||
runtime: linux-x64 | ||
# Linux ARM64 | ||
- os: ubuntu-24.04-arm | ||
arch: arm64 | ||
runtime: linux-arm64 | ||
# Windows x64 | ||
- os: windows-latest | ||
arch: x64 | ||
runtime: win-x64 | ||
# Windows ARM64 | ||
- os: windows-11-arm | ||
arch: arm64 | ||
runtime: win-arm64 | ||
# macOS x64 | ||
- os: macos-13 | ||
arch: x64 | ||
runtime: osx-x64 | ||
# macOS ARM64 (Apple Silicon) | ||
- os: macos-latest | ||
arch: arm64 | ||
runtime: osx-arm64 | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: recursive | ||
|
||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 | ||
env: | ||
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
global-json-file: global.json | ||
source-url: https://nuget.pkg.github.com/open-feature/index.json | ||
|
||
- name: Cache NuGet packages | ||
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
with: | ||
path: ~/.nuget/packages | ||
key: ${{ runner.os }}-${{ matrix.arch }}-nuget-${{ hashFiles('**/*.csproj') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.arch }}-nuget- | ||
${{ runner.os }}-nuget- | ||
|
||
- name: Restore dependencies | ||
shell: pwsh | ||
run: dotnet restore | ||
|
||
- name: Build solution | ||
shell: pwsh | ||
run: dotnet build -c Release --no-restore | ||
|
||
- name: Test AOT compatibility project build | ||
shell: pwsh | ||
run: dotnet build test/OpenFeature.AotCompatibility/OpenFeature.AotCompatibility.csproj -c Release --no-restore | ||
|
||
- name: Publish AOT compatibility test (cross-platform) | ||
shell: pwsh | ||
run: | | ||
dotnet publish test/OpenFeature.AotCompatibility/OpenFeature.AotCompatibility.csproj ` | ||
-c Release ` | ||
-r ${{ matrix.runtime }} ` | ||
-o ./aot-output | ||
|
||
- name: Run AOT compatibility test | ||
shell: pwsh | ||
run: | | ||
if ("${{ runner.os }}" -eq "Windows") { | ||
./aot-output/OpenFeature.AotCompatibility.exe | ||
} else { | ||
chmod +x ./aot-output/OpenFeature.AotCompatibility | ||
./aot-output/OpenFeature.AotCompatibility | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
using System.ComponentModel; | ||
using OpenFeature.Constant; | ||
|
||
namespace OpenFeature.Extension; | ||
|
||
internal static class EnumExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the description of an enum value without using reflection. | ||
/// This is AOT-compatible and only supports specific known enum types. | ||
/// </summary> | ||
/// <param name="value">The enum value to get the description for</param> | ||
/// <returns>The description string or the enum value as string if no description is available</returns> | ||
public static string GetDescription(this Enum value) | ||
{ | ||
var field = value.GetType().GetField(value.ToString()); | ||
var attribute = field?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute; | ||
return attribute?.Description ?? value.ToString(); | ||
return value switch | ||
{ | ||
// ErrorType descriptions | ||
ErrorType.None => "NONE", | ||
ErrorType.ProviderNotReady => "PROVIDER_NOT_READY", | ||
ErrorType.FlagNotFound => "FLAG_NOT_FOUND", | ||
ErrorType.ParseError => "PARSE_ERROR", | ||
ErrorType.TypeMismatch => "TYPE_MISMATCH", | ||
ErrorType.General => "GENERAL", | ||
ErrorType.InvalidContext => "INVALID_CONTEXT", | ||
ErrorType.TargetingKeyMissing => "TARGETING_KEY_MISSING", | ||
ErrorType.ProviderFatal => "PROVIDER_FATAL", | ||
|
||
// Fallback for any other enum types | ||
_ => value.ToString() | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/OpenFeature/Serialization/OpenFeatureJsonSerializerContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
using OpenFeature.Model; | ||
|
||
namespace OpenFeature.Serialization; | ||
|
||
/// <summary> | ||
/// JSON serializer context for AOT compilation support. | ||
/// This ensures that all necessary types are pre-compiled for JSON serialization | ||
/// when using NativeAOT. | ||
/// </summary> | ||
[JsonSerializable(typeof(Value))] | ||
[JsonSerializable(typeof(Structure))] | ||
[JsonSerializable(typeof(EvaluationContext))] | ||
[JsonSerializable(typeof(Dictionary<string, Value>))] | ||
[JsonSerializable(typeof(ImmutableDictionary<string, Value>))] | ||
[JsonSerializable(typeof(List<Value>))] | ||
[JsonSerializable(typeof(ImmutableList<Value>))] | ||
[JsonSerializable(typeof(bool))] | ||
[JsonSerializable(typeof(string))] | ||
[JsonSerializable(typeof(int))] | ||
[JsonSerializable(typeof(double))] | ||
[JsonSerializable(typeof(DateTime))] | ||
[JsonSourceGenerationOptions( | ||
WriteIndented = false, | ||
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
public partial class OpenFeatureJsonSerializerContext : JsonSerializerContext; |
34 changes: 34 additions & 0 deletions
34
test/OpenFeature.AotCompatibility/OpenFeature.AotCompatibility.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<!-- NativeAOT Configuration --> | ||
<PublishAot>true</PublishAot> | ||
<IsAotCompatible>true</IsAotCompatible> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
<TrimMode>full</TrimMode> | ||
<IlcOptimizationPreference>Size</IlcOptimizationPreference> | ||
askpt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<!-- Suppress vulnerable package warnings for this test project --> | ||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> | ||
<WarningsNotAsErrors>NU1903</WarningsNotAsErrors> | ||
<RootNamespace>OpenFeature.AotCompatibility</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\OpenFeature\OpenFeature.csproj" /> | ||
<ProjectReference Include="..\..\src\OpenFeature.DependencyInjection\OpenFeature.DependencyInjection.csproj" /> | ||
<ProjectReference Include="..\..\src\OpenFeature.Providers.MultiProvider\OpenFeature.Providers.MultiProvider.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" /> | ||
askpt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.