Skip to content

feat: support AOT (Try 3)#389

Open
SMAH1 wants to merge 1 commit into
oras-project:mainfrom
SMAH1:origin/AotCompatible3
Open

feat: support AOT (Try 3)#389
SMAH1 wants to merge 1 commit into
oras-project:mainfrom
SMAH1:origin/AotCompatible3

Conversation

@SMAH1

@SMAH1 SMAH1 commented May 29, 2026

Copy link
Copy Markdown

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

  • Use in AOT projects
  • Better performance

Please check the following list

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Signed-off-by: SMAH1 <integral22003@yahoo.com>
Copilot AI review requested due to automatic review settings May 29, 2026 09:51
@SMAH1 SMAH1 mentioned this pull request May 29, 2026
4 tasks

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OciJsonSerializerContext source-generated context + a configured default instance for OCI types.
  • Updated OciJsonSerializer and call sites to use JsonTypeInfo<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.

Comment on lines 31 to +38
private class ErrorResponse
{
[JsonPropertyName("errors")]
public required IList<Error> Errors { get; set; }
}

[JsonSerializable(typeof(ErrorResponse))]
private partial class ErrorResponseJsonContext : JsonSerializerContext { }
Comment on lines +88 to +89
var errorResponse = JsonSerializer.Deserialize(
responseBody, ErrorResponseJsonContext.Default.ErrorResponse);
Comment on lines 37 to 47
@@ -53,41 +47,93 @@ internal static byte[] SerializeToUtf8Bytes<T>(T value)
}
Comment on lines +97 to +107
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>
@akashsinghal akashsinghal changed the title Support AOT (Try 3) feat: support AOT (Try 3) May 29, 2026
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.66102% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.71%. Comparing base (b08920c) to head (90cbd0a).

Files with missing lines Patch % Lines
src/OrasProject.Oras/Registry/Remote/Repository.cs 36.36% 5 Missing and 2 partials ⚠️
...rasProject.Oras/Serialization/OciJsonSerializer.cs 88.88% 3 Missing ⚠️
...rc/OrasProject.Oras/Content/FetchableExtensions.cs 50.00% 0 Missing and 2 partials ⚠️

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants