feat: support AOT (Try 3)#389
Conversation
Signed-off-by: SMAH1 <integral22003@yahoo.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR migrates OCI JSON (de)serialization to System.Text.Json source generation for AOT-safety, updating call sites to pass JsonTypeInfo<T> while keeping legacy reflection-based overloads for compatibility.
Changes:
- Added
OciJsonSerializerContextsource-generated context + a configured default instance for OCI types. - Updated
OciJsonSerializerand call sites to useJsonTypeInfo<T>overloads (AOT-safe), retaining legacy overloads with trimming annotations. - Marked the project as AOT-compatible and updated error-response parsing to use a dedicated generated context.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/OrasProject.Oras/Serialization/OciJsonSerializerContext.cs | Introduces source-generated JSON context and default configured instance for OCI types. |
| src/OrasProject.Oras/Serialization/OciJsonSerializer.cs | Adds AOT-safe JsonTypeInfo<T> overloads and keeps legacy reflection-based overloads with warnings. |
| src/OrasProject.Oras/Registry/Remote/Repository.cs | Switches registry JSON parsing/formatting to generated type info. |
| src/OrasProject.Oras/Registry/Remote/Registry.cs | Switches repository list parsing to generated type info. |
| src/OrasProject.Oras/Registry/Remote/ManifestStore.cs | Updates async manifest/index deserialization to pass generated type info. |
| src/OrasProject.Oras/Registry/Remote/Exceptions/ResponseException.cs | Uses a dedicated generated context for error response deserialization. |
| src/OrasProject.Oras/Packer.cs | Uses AOT-safe serializer overload and narrows manifest parameter type. |
| src/OrasProject.Oras/OrasProject.Oras.csproj | Marks library as AOT compatible. |
| src/OrasProject.Oras/Oci/Index.cs | Uses AOT-safe serializer overload for index generation. |
| src/OrasProject.Oras/Content/FetchableExtensions.cs | Uses AOT-safe deserialization for manifest/index traversal. |
| private class ErrorResponse | ||
| { | ||
| [JsonPropertyName("errors")] | ||
| public required IList<Error> Errors { get; set; } | ||
| } | ||
|
|
||
| [JsonSerializable(typeof(ErrorResponse))] | ||
| private partial class ErrorResponseJsonContext : JsonSerializerContext { } |
| var errorResponse = JsonSerializer.Deserialize( | ||
| responseBody, ErrorResponseJsonContext.Default.ErrorResponse); |
| @@ -53,41 +47,93 @@ internal static byte[] SerializeToUtf8Bytes<T>(T value) | |||
| } | |||
| internal static byte[] SerializeToUtf8Bytes<T>(T value) | ||
| { | ||
| var bytes = JsonSerializer.SerializeToUtf8Bytes(value, s_legacyOptions); | ||
| if (bytes.Length > OciLimits.MaxManifestBytes) | ||
| { | ||
| throw new SizeLimitExceededException( | ||
| $"Serialized size {bytes.Length} bytes exceeds" | ||
| + $" limit of {OciLimits.MaxManifestBytes} bytes."); | ||
| } | ||
| return bytes; | ||
| } |
| /// Exception thrown for HTTP responses from registry operations. | ||
| /// </summary> | ||
| public class ResponseException : HttpRequestException | ||
| public partial class ResponseException : HttpRequestException |
| @@ -1,4 +1,4 @@ | |||
| <!-- | |||
| <!-- | |||
| <GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
| <OutputType>Library</OutputType> | ||
| <Nullable>enable</Nullable> | ||
| <IsAotCompatible>true</IsAotCompatible> |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (79.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #389 +/- ##
==========================================
- Coverage 92.03% 91.71% -0.32%
==========================================
Files 67 68 +1
Lines 2938 2970 +32
Branches 380 381 +1
==========================================
+ Hits 2704 2724 +20
- Misses 139 150 +11
- Partials 95 96 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What this PR does / why we need it
Use in AOT project.
Resolve #378 so create another PR.
Which issue(s) this PR resolves / fixes
Please check the following list