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

Add an opt-in AOT regression check to the CI pipeline #40629

Merged
merged 3 commits into from
Dec 11, 2023

Conversation

m-redding
Copy link
Member

@m-redding m-redding commented Dec 7, 2023

This PR adds a new opt-in AOT pipeline that can be enabled in the CI pipeline. This would be paired with documentation along the lines of what I included below, which will most likely live in an internal wiki:


Enable AOT compatibility regression testing in CI pipelines

An increasing number of .NET Azure SDK libraries are committed to making their libraries compatible with native AOT. To help support this work, there is now an opt-in pipeline step called "Check for AOT compatibility regressions in [Package Name]". This pipeline creates a small sample app that uses a project reference to collect the set of trimming warnings reported for the specified library. This approach for collecting warnings is described in this article.

How to enable the pipeline for your package

Collect any expected trimming warnings

You can use any of the approaches described in the articles linked at the bottom of this document to find the warnings reported from your library. In an ideal scenario, this would be zero. However, there are cases where a library needs to baseline an expected set of warnings. Sometimes warnings are not straightforward (or are even impossible) to resolve, but are not expected to impact the majority of customer use cases. In other cases, warnings may be dependent on other work finishing first (for example, adding a net6.0 target, or upgrading a package dependency version).

The text file should be formatted with each warning on its own line. The pipeline uses pattern matching to validate warnings. This means that warnings will need to be edited to avoid using special characters incorrectly. Even though it seems easier to just do simple string matching, the errors are formatted differently depending on the environment, so using correctly formatted pattern matching makes it easier.

Example:

Actual warning:

C:\Users\mredding\source\repos\azure-sdk-for-net\sdk\core\Azure.Core\src\JsonPatchDocument.cs(44): Trim analysis warning IL2026: Azure.JsonPatchDocument.JsonPatchDocument(ReadOnlyMemory`1): Using member 'Azure.Core.Serialization.JsonObjectSerializer.JsonObjectSerializer()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. This class uses reflection-based JSON serialization and deserialization that is not compatible with trimming. [C:\Users\mredding\source\repos\ResolveAOT\ResolveAOT\ResolveAOT.csproj]

Line in the text file:

Azure\.Core.src.JsonPatchDocument\.cs\(\d*\): Trim analysis warning IL2026: Azure\.JsonPatchDocument\.JsonPatchDocument\(ReadOnlyMemory`1\): Using member 'Azure\.Core\.Serialization\.JsonObjectSerializer\.JsonObjectSerializer\(\)' which has 'RequiresUnreferencedCodeAttribute'

Note: In my case, my local environment uses forward slashes in filepaths, while the pipeline uses back slashes, so using a wildcard was the easiest way to reconcile this.

Update ci.yml file

The ci.yml file needs to be updated to include the following information:

extends:
  template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
  parameters:
    ServiceDirectory: [service directory]
    # [... other inputs]
    CheckAOTCompat: true
    AOTTestInputs:
    - ArtifactName: [Name of package]
      ExpectedAOTWarningsFilePath: None [or filepath of errors relative to the service directory]

Example:

extends:
  template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
  parameters:
    ServiceDirectory: core
    # [... other inputs]
    CheckAOTCompat: true
    AOTTestInputs:
    - ArtifactName: Azure.Core
      ExpectedAOTWarningsFilepath: /Azure.Core/tests/aotcompatibility/ExpectedAotWarnings.txt

Example 2:

extends:
  template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
  parameters:
    ServiceDirectory: core
    # [... other inputs]
    CheckAOTCompat: true
    AOTTestInputs:
    - ArtifactName: Azure.Core
      ExpectedAOTWarningsFilepath: /Azure.Core/tests/aotcompatibility/ExpectedAotWarnings.txt
    - ArtifactName: Azure.Core.Experimental # For illustration only
      ExpectedAOTWarningsFilepath: None

How to resolve trimming warnings

The following three articles provide comprehensive guidance for how to resolve trimming warnings and make libraries compatible with AOT:

Learning how to use source generation for serialization/deserialization:


Resolves: #38226 #37761

@m-redding
Copy link
Member Author

/azp run net - core - ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

@m-redding
Copy link
Member Author

/azp run net - core - ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@m-redding m-redding changed the title [Draft 2] Add an opt-in AOT regression pipeline check Add an opt-in AOT regression pipeline check Dec 7, 2023
@m-redding m-redding changed the title Add an opt-in AOT regression pipeline check Add an opt-in AOT regression check to the CI pipeline Dec 7, 2023
@TimothyMothra
Copy link
Contributor

I'm excited to use this!

@m-redding
Copy link
Member Author

cc: @eerhardt @vitek-karas

@eerhardt
Copy link
Member

eerhardt commented Dec 7, 2023

This would be paired with documentation along the lines of what I included below, which will most likely live in an internal wiki:

Why an internal wiki and not a .md file in the repo?

@m-redding
Copy link
Member Author

This would be paired with documentation along the lines of what I included below, which will most likely live in an internal wiki:

Why an internal wiki and not a .md file in the repo?

@eerhardt I should have said "the internal wiki" - all of our pipeline/release/engineering related docs are currently located in an internal wiki that is accessible to the Azure SDK team & any partner teams that utilize our repos to release. I'll get some feedback about if there's a better place for it.

@m-redding
Copy link
Member Author

/azp run net - core - ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@hallipr hallipr left a comment

Choose a reason for hiding this comment

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

All of the yaml looks good

@m-redding m-redding merged commit c47ab4d into Azure:main Dec 11, 2023
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Core] Add CI pipeline to test for AOT compatibility
7 participants