Skip to content

feat(build): add comprehensive AOT compatibility support#267

Merged
j-d-ha merged 14 commits into
mainfrom
feature/#255-ensure-proper-AOT-compatibility
Dec 21, 2025
Merged

feat(build): add comprehensive AOT compatibility support#267
j-d-ha merged 14 commits into
mainfrom
feature/#255-ensure-proper-AOT-compatibility

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 21, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR adds comprehensive support for Ahead-of-Time (AOT) compilation compatibility across the MinimalLambda codebase. It includes AOT validation in the CI pipeline, proper configuration for enabling AOT analyzers, suppression of AOT warnings where appropriate with detailed justifications, and a dedicated test project to validate AOT compatibility.

Key Changes:

  • CI Integration: Added AOT validation task to both PR and main build workflows
  • Project Configuration: Enabled IsAotCompatible, EnableAotAnalyzer, and EnableTrimAnalyzer for .NET 8.0+ targets
  • Code Annotations: Added UnconditionalSuppressMessage attributes for AOT warnings (IL2026, IL3050) in envelope classes with clear justifications
  • Test Infrastructure: Created AotCompatibility.TestApp project that validates all packages can be trimmed/AOT compiled
  • Using Directives: Migrated from GlobalUsings.cs files to project-level <Using> directives for better AOT compatibility
  • Build Improvements: Set TreatWarningsAsErrors=true globally and added specific suppressions where needed (e.g., AD0001 for .NET 9.0)

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #255


💬 Notes for Reviewers

AOT Warning Suppressions

All UnconditionalSuppressMessage attributes in envelope classes follow the same pattern and include detailed justifications. These suppressions are safe when users provide source-generated JSON serialization contexts (which is the recommended practice for Lambda functions).

Build Configuration

The AOT analyzers are only enabled for .NET 8.0+ targets to avoid compatibility issues with older frameworks. The source generators project explicitly sets IsAotCompatible=false since analyzers/source generators don't run in AOT scenarios.

CI Pipeline

The AOT validation runs after the SonarQube analysis and tests complete, ensuring we catch AOT compatibility issues before merging.

- Created `AotCompatibility.TestApp` to validate ahead-of-time compatibility.
- Added `IsAotCompatible` property to project files for managing AOT compatibility.
- Updated solution file to include the new testing project.
- Configured .NET 10.0 and enabled required settings in the new project.
- Explicitly disabled AOT compatibility for `MinimalLambda.SourceGenerators` in the project file.
- Enabled additional analyzers for trimming and single-file publish.
- Set `TreatWarningsAsErrors` to ensure stricter build processes.
- Added project references for various envelopes and abstractions.
- Introduced `aot-check` task to validate AOT compatibility of libraries.
- Updated `Directory.Build.props` with conditional analyzers for net8.0 compatibility.
- Refined warnings treated as errors for improved build strictness.
- Updated AOT test project to better align with compatibility requirements.
…ct settings

- Added `UnconditionalSuppressMessage` attributes to suppress AOT-related warnings in envelopes.
- Justifications provided to ensure safety when using source-generated `JsonSerializer` context.
- Marked test projects with `<IsTestProject>` for better build system handling.
- Updated `MinimalLambda.Envelopes.UnitTests` with appropriate AOT and warning configuration.
- Added `max_line_length` to XML formatting in `.editorconfig`.
- Refactored `Directory.Build.props` to simplify AOT-related property configurations.
- Consolidated `IsAotCompatible`, `EnableAotAnalyzer`, and `EnableTrimAnalyzer` under a single group.
…ructors check

- Added `[DynamicallyAccessedMembers]` attribute to `TContext` in `AddLambdaSerializerWithContext<TContext>()`.
- Ensures public constructors are preserved for AOT compatibility.
…OT warnings

- Replaced `Services.Configure` with `AddOptions<>().BindConfiguration` for better AOT compatibility.
- Added `UnconditionalSuppressMessage` to suppress AOT-related warnings in `TryAddLambdaHostDefaultServices`.
- Enabled `EnableConfigurationBindingGenerator` in the project file to support source-generated binding.
- Added `<NoWarn>` to suppress AOT-related warnings in testing projects.
- Moved `<IsAotCompatible>` to a consistent position in the main project file.
- Ensured alignment with existing AOT settings across related project files.
- Added `<NoWarn>` for `AD0001` to unblock builds affected by analyzer errors in .NET 9.0.
- Updated project files across multiple modules to ensure consistent suppression of the issue.
…rectives in project files

- Removed `GlobalUsings.cs` files across all projects to simplify and streamline dependency management.
- Added `<Using>` directives directly in `.csproj` files to explicitly manage and organize global usings.
- Ensured all necessary usings are integrated for each project's build and functionality needs.
…r AOT scenarios

- Updated `ServiceCollectionExtensions` to conditionally register `ILambdaSerializer` only if
  `RuntimeFeature.IsDynamicCodeSupported`, improving AOT support.
- Refactored `AotCompatibility.TestApp` project definitions by introducing `EnvelopeRootAssembly`
  and `CoreRootAssembly` items.
- Added `TrimmerRootAssembly` configuration to streamline project references in AOT scenarios.
- Modified `DefaultEventFeature<T>` to provide better error messaging and default parameter handling
  for `ILambdaSerializer`.
- Introduced `Validate AOT Compatibility` step in PR and main build workflows.
- Separated SonarQube start and stop actions for better task modularity.
- Improved overall CI process by ensuring AOT compatibility validation.
@github-actions github-actions Bot added the type: feat New feature label Dec 21, 2025
- Replaced InvalidOperationException with ArgumentNullException in DefaultEventFeature.
- Enhanced exception messaging for clarity when lambdaSerializer is not registered.
@sonarqubecloud

sonarqubecloud Bot commented Dec 21, 2025

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Dec 21, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #267      +/-   ##
==========================================
+ Coverage   88.87%   88.89%   +0.02%     
==========================================
  Files         132      132              
  Lines        3263     3270       +7     
  Branches      322      324       +2     
==========================================
+ Hits         2900     2907       +7     
  Misses        247      247              
  Partials      116      116              
Files with missing lines Coverage Δ
.../MinimalLambda.Envelopes.Alb/AlbRequestEnvelope.cs 100.00% <ø> (ø)
...MinimalLambda.Envelopes.Alb/AlbResponseEnvelope.cs 100.00% <ø> (ø)
....Envelopes.ApiGateway/ApiGatewayRequestEnvelope.cs 100.00% <ø> (ø)
...Envelopes.ApiGateway/ApiGatewayResponseEnvelope.cs 100.00% <ø> (ø)
...nvelopes.ApiGateway/ApiGatewayV2RequestEnvelope.cs 100.00% <ø> (ø)
...velopes.ApiGateway/ApiGatewayV2ResponseEnvelope.cs 100.00% <ø> (ø)
...lopes.CloudWatchLogs/CloudWatchLogsEnvelopeBase.cs 89.47% <ø> (ø)
...nvelopes.CloudWatchLogs/CloudWatchLogsEnvelopeT.cs 100.00% <ø> (ø)
...pes/MinimalLambda.Envelopes.Kafka/KafkaEnvelope.cs 100.00% <ø> (ø)
...MinimalLambda.Envelopes.Kinesis/KinesisEnvelope.cs 100.00% <ø> (ø)
... and 9 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c82817...aa2d9c8. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j-d-ha
j-d-ha merged commit 6529e7e into main Dec 21, 2025
8 checks passed
@j-d-ha
j-d-ha deleted the feature/#255-ensure-proper-AOT-compatibility branch December 21, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(build): ensure proper AOT compatibility validation and configuration

1 participant