Skip to content

Commit 899b608

Browse files
m-reddingjsquire
andauthored
Add AOT compatibility checks documentation (Azure#40762)
* docs * add link * Update AotRegressionChecks.md * Update doc/dev/AotRegressionChecks.md Co-authored-by: Jesse Squire <[email protected]> * Update doc/dev/AotRegressionChecks.md Co-authored-by: Jesse Squire <[email protected]> * Update doc/dev/Using-Mock-Test-Generation.md Co-authored-by: Jesse Squire <[email protected]> * feedback --------- Co-authored-by: Jesse Squire <[email protected]>
1 parent a396f21 commit 899b608

5 files changed

+86
-6
lines changed

doc/dev/AotRegressionChecks.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Enable AOT compatibility regression testing in CI pipelines
2+
3+
An increasing number of .NET Azure SDK libraries are committed to being compatible with native AOT. For more information about native AOT deployment see [this article](https://learn.microsoft.com/dotnet/core/deploying/native-aot/). To 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](https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0#show-all-warnings-with-test-app).
4+
5+
## How to enable the pipeline for your package
6+
7+
### Collect any expected trimming warnings
8+
9+
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).
10+
11+
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.
12+
13+
**Example**:
14+
15+
Actual warning:
16+
> 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<Byte>): 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]
17+
18+
Line in the text file:
19+
> Azure\\.Core.src.JsonPatchDocument\\.cs\\(\\d*\\): Trim analysis warning IL2026: Azure\\.JsonPatchDocument\\.JsonPatchDocument\\(ReadOnlyMemory`1<Byte>\\): Using member 'Azure\\.Core\\.Serialization\\.JsonObjectSerializer\\.JsonObjectSerializer\\(\\)' which has 'RequiresUnreferencedCodeAttribute'
20+
21+
**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.
22+
23+
### Update ci.yml file
24+
25+
The ci.yml file needs to be updated to include the following information:
26+
```yml
27+
extends:
28+
template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
29+
parameters:
30+
ServiceDirectory: [service directory]
31+
# [... other inputs]
32+
CheckAOTCompat: true
33+
AOTTestInputs:
34+
- ArtifactName: [Name of package]
35+
ExpectedAOTWarningsFilePath: None [or filepath of errors relative to the service directory]
36+
```
37+
38+
**Example**:
39+
```yml
40+
extends:
41+
template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
42+
parameters:
43+
ServiceDirectory: core
44+
# [... other inputs]
45+
CheckAOTCompat: true
46+
AOTTestInputs:
47+
- ArtifactName: Azure.Core
48+
ExpectedAOTWarningsFilepath: /Azure.Core/tests/aotcompatibility/ExpectedAotWarnings.txt
49+
```
50+
**Example 2**:
51+
```yml
52+
extends:
53+
template: /eng/pipelines/templates/stages/archetype-sdk-client.yml
54+
parameters:
55+
ServiceDirectory: core
56+
# [... other inputs]
57+
CheckAOTCompat: true
58+
AOTTestInputs:
59+
- ArtifactName: Azure.Core
60+
ExpectedAOTWarningsFilepath: /Azure.Core/tests/aotcompatibility/ExpectedAotWarnings.txt
61+
- ArtifactName: Azure.Core.Experimental # For illustration only
62+
ExpectedAOTWarningsFilepath: None
63+
```
64+
65+
## How to resolve trimming warnings
66+
67+
The following three articles provide comprehensive guidance for how to resolve trimming warnings and make libraries compatible with AOT:
68+
- ["How to make libraries compatible with native AOT"](https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/) by Eric Erhardt on November 30th, 2023
69+
- ["Prepare .NET libraries for trimming"](https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming)
70+
- ["Introduction to trim warnings"](https://learn.microsoft.com/dotnet/core/deploying/trimming/fixing-warnings)
71+
72+
Learning how to use source generation for serialization/deserialization:
73+
- [Introduction of C# source generation in .NET 6](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/)
74+
- [How to use source generation](https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/source-generation)

doc/dev/Building.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Similar to how all projects require minimal authoring, various [Azure Pipelines]
4949

5050
These pipeline definitions typically contain the necessary triggers, paths to watch, and package information. See existing SDKs' files for examples to avoid duplicating information that may change here. _tests.yml_ might also contain additional [matrix generation](https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/matrix_generator.md) options to change or add testing environments particular to a service directory.
5151

52-
If your working on engineering system changes for the .NET repo, it's from one of these files you can follow the `template` directives therein. Currently, for example, a _ci.yml_ would include a chain of templates like so:
52+
If you're working on engineering system changes for the .NET repo within one of the files above, you can follow the `template` directives. Currently, for example, a _ci.yml_ would include a chain of templates like so:
5353

5454
* _sdk/keyvault/ci.yml_
5555
* _eng/pipelines/templates/stages/archetype-sdk-client.yml_
@@ -62,4 +62,4 @@ If your working on engineering system changes for the .NET repo, it's from one o
6262

6363
Same as above: common pipelines get included and passed various objects here too.
6464

65-
Any changes to the _eng_ directory outside of the _common_ subdirectory are owned by the Azure SDK for .NET team but you should talk with the central Engineering Systems team to coordinate how your changes will work, any problems they might think of, and whether the changes should actually be common. Any changes within the _eng/common_ subdirectory should be discussed with the central EngSys team and should be made in the <https://github.com/Azure/azure-sdk-tools/tree/main/eng/common> directory. See [here](https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md) for more information.
65+
Any changes to the _eng_ directory outside of the _common_ subdirectory are owned by the Azure SDK for .NET team, but you should still coordinate with the central Engineering Systems team to discuss how your changes will work, go over any problems they might think of, and determine whether the changes should actually be common. Any changes within the _eng/common_ subdirectory should be discussed with the central EngSys team and should be made in the <https://github.com/Azure/azure-sdk-tools/tree/main/eng/common> directory. See [here](https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md) for more information.

doc/dev/Using-Azure-TestFramework.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In order to Record/Playback a test, you need to setup a connection string that c
2727

2828
> TEST_CSM_ORGID_AUTHENTICATION
2929
30-
Value of the env. variable is the connection string that determines how to connect to Azure. This includes authentiation and the Azure environment to connect to.
30+
Value of the env. variable is the connection string that determines how to connect to Azure. This includes authentication and the Azure environment to connect to.
3131

3232
> AZURE_TEST_MODE
3333

doc/dev/Using-Mock-Test-Generation.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
This article demonstrate how to generate and execute mock test for .Net SDK.
1010

1111
Writing and executing live tests for SDKs are difficult for some RPs:
12-
+ Various Azure resources need to be created as prerequistes before testing the APIs in the RP itself.
12+
+ Various Azure resources need to be created as prerequisites before testing the APIs in the RP itself.
1313
+ Need to understand executing orders of APIs inside the RP.
1414
+ Some APIs take long time to execute which make writing/debugging tests is time consuming.
1515

16-
In case we focused only on SDK behaviour instead of service behaviour, the mock test can be used to validate the SDK quality efficiently. The mock test can be generated and executed under the [mock-service-host](https://github.com/Azure/azure-sdk-tools/tree/main/tools/mock-service-host) to save developer's efforts.
16+
In case we focused only on SDK behavior instead of service behavior, the mock test can be used to validate the SDK quality efficiently. The mock test can be generated and executed under the [mock-service-host](https://github.com/Azure/azure-sdk-tools/tree/main/tools/mock-service-host) to save developer's efforts.
1717

1818
Below is a sample for mock testcase:
1919

@@ -136,8 +136,9 @@ Listening https on port: 8445
136136
<div id="execute-mock-test"/>
137137
138138
# Execute Mock Test
139+
139140
## Trust the mock-service-host certificate '.ssh/localhost-ca.crt'
140-
> **_NOTE:_** Don't need this step if once launched mock-service-host with Launch-MockServiceHost.ps1 in Adminstrator Mode.
141+
> **_NOTE:_** Don't need this step if once launched mock-service-host with Launch-MockServiceHost.ps1 in Administrator Mode.
141142
142143
The mock-service-host use a self-signed certificate to enable HTTPs channel, so need to trust the certificate before execute any mock test.
143144
Once the mock-service-host is launched, the certificate will be created as 'mock-service-host/.ssh/localhost-ca.crt'. Double click the crt file and follow below to install it.

eng/scripts/compatibility/Check-AOT-Compatibility.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if ($LASTEXITCODE -ne 0)
7272
Set-Location -Path ..
7373
Remove-Item -Path "./$folderPath" -Recurse -Force
7474

75+
Write-Host "\nFor help with this check, please see https://github.com/Azure/azure-sdk-for-net/tree/main/doc/dev/AotRegressionChecks.md"
7576
Exit 2
7677
}
7778

@@ -111,6 +112,8 @@ if (Test-Path $expectedWarningsFullPath -PathType Leaf) {
111112
Set-Location -Path ..
112113
Remove-Item -Path "./$folderPath" -Recurse -Force
113114

115+
Write-Host "\nFor help with this check, please see https://github.com/Azure/azure-sdk-for-net/tree/main/doc/dev/AotRegressionChecks.md"
116+
114117
exit $warnings.Count
115118
}
116119

@@ -135,7 +138,9 @@ Remove-Item -Path "./$folderPath" -Recurse -Force
135138

136139
if ($numExpectedWarnings -ne $actualWarningCount) {
137140
Write-Host "The number of expected warnings ($numExpectedWarnings) was different than the actual warning count ($actualWarningCount)."
141+
Write-Host "\nFor help with this check, please see https://github.com/Azure/azure-sdk-for-net/tree/main/doc/dev/AotRegressionChecks.md"
138142
exit 2
139143
}
140144

145+
Write-Host "\nFor help with this check, please see https://github.com/Azure/azure-sdk-for-net/tree/main/doc/dev/AotRegressionChecks.md"
141146
exit $warnings.Count

0 commit comments

Comments
 (0)