Repository navigation
[build] Enable C# memory-safety rules v2 for repository builds - #13734
simonrozsival wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
The new compiler defaults need maintainer validation in the legacy McwGen fixture and Arcade internal tools because unavailable targets and private packages prevented normal-build validation.
No open issues 🎉
What changed in this PR
Centralizes C# memory-safety rules v2 and preview language mode across .NET for Android, completing the move from project-specific opt-ins to shared repository defaults.
Changes:
- Removes redundant compiler settings and C# 13 overrides from libraries, tools, tests, and samples.
- Adds explicit settings for standalone templates and Arcade internal tools, and imports shared defaults into the legacy binding fixture.
- Updates
TestEnvironmentnative-buffer operations for v2 and documents the shared configuration.
| File | Description |
|---|---|
| tests/Xamarin.SourceWriter-Tests/Xamarin.SourceWriter-Tests.csproj | Removes C# 13 override. |
| tests/Xamarin.Android.Tools.Bytecode-Tests/Xamarin.Android.Tools.Bytecode-Tests.csproj | Removes C# 13 override. |
| tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests.csproj | Removes C# 13 override. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj | Uses shared compiler defaults. |
| tests/Mono.Android-Tests/Java.Interop-Tests/Java.Interop-Tests.NET.csproj | Uses shared compiler defaults. |
| tests/Java.Interop.Tools.Maven-Tests/Java.Interop.Tools.Maven-Tests.csproj | Removes C# 13 override. |
| tests/Java.Interop.Tools.JavaTypeSystem-Tests/Java.Interop.Tools.JavaTypeSystem-Tests.csproj | Removes C# 13 override. |
| tests/Java.Interop.Tools.JavaSource-Tests/Java.Interop.Tools.JavaSource-Tests.csproj | Removes C# 13 override. |
| tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers-Tests.csproj | Removes C# 13 override. |
| tests/Java.Interop.Tools.Generator-Tests/Java.Interop.Tools.Generator-Tests.csproj | Removes C# 13 override. |
| tests/generator-Tests/generator-Tests.csproj | Uses shared compiler defaults for the test host. |
| tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Xamarin.Android.McwGen-Tests.csproj | Imports repository build properties. |
| tests/CodeGen-Binding/Xamarin.Android.LibraryProjectZip-LibBinding/Xamarin.Android.LibraryProjectZip-LibBinding.csproj | Uses shared compiler defaults. |
| tests/CodeGen-Binding/Xamarin.Android.LegacyThresholdBinding/Xamarin.Android.LegacyThresholdBinding.csproj | Uses shared compiler defaults. |
| tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj | Uses shared compiler defaults. |
| tests/Android.Benchmarks/Android.Benchmarks.csproj | Uses shared compiler defaults. |
| src/Xamarin.SourceWriter/Xamarin.SourceWriter.csproj | Removes redundant compiler settings. |
| src/Xamarin.Installer.Build.Tasks/Xamarin.Installer.Build.Tasks.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Tools.Bytecode/Xamarin.Android.Tools.Bytecode.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Tools.ApiXmlAdjuster/Xamarin.Android.Tools.ApiXmlAdjuster.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Tools.AnnotationSupport/Xamarin.Android.Tools.AnnotationSupport.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Tools.Aidl/Xamarin.Android.Tools.Aidl.csproj | Removes redundant compiler settings. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj | Uses shared settings and satellite-compilation rationale. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj | Enables required unsafe contexts. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/TestEnvironment.cs | Adds explicit unsafe contexts and native-buffer safety documentation. |
| src/Xamarin.Android.Build.Debugging.Tasks/Xamarin.Android.Build.Debugging.Tasks.csproj | Removes redundant compiler settings. |
| src/Mono.Android/Mono.Android.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.TypeMaps.Ref/Microsoft.Android.TypeMaps.Ref.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.Templates/Microsoft.Android.Templates.csproj | Uses shared defaults for template packaging. |
| src/Microsoft.Android.Templates/androidtest/AndroidTest1.csproj | Explicitly enables v2 and preview in generated tests. |
| src/Microsoft.Android.Templates/androidlib/AndroidLib1.csproj | Explicitly enables v2 and preview in generated libraries. |
| src/Microsoft.Android.Templates/android/AndroidApp1.csproj | Explicitly enables v2 and preview in generated apps. |
| src/Microsoft.Android.Templates/android-wear/AndroidApp1.csproj | Explicitly enables v2 and preview in generated Wear apps. |
| src/Microsoft.Android.Templates/android-bindinglib/AndroidBinding1.csproj | Explicitly enables v2 and preview in generated bindings. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Microsoft.Android.Sdk.TrimmableTypeMap.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.Sdk.Analysis/Microsoft.Android.Sdk.Analysis.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.Runtime.NativeAOT/Microsoft.Android.Runtime.NativeAOT.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.Run/Microsoft.Android.Run.csproj | Removes redundant compiler settings. |
| src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj | Uses shared settings and satellite-compilation rationale. |
| src/Microsoft.Android.Build.BaseTasks/Microsoft.Android.Build.BaseTasks.csproj | Removes redundant compiler settings. |
| src/Java.Interop/Java.Interop.csproj | Replaces local opt-ins with shared defaults. |
| src/Java.Interop.Tools.Maven/Java.Interop.Tools.Maven.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.JavaTypeSystem/Java.Interop.Tools.JavaTypeSystem.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.Generator/Java.Interop.Tools.Generator.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil.csproj | Removes redundant compiler settings. |
| src/Java.Interop.Localization/Java.Interop.Localization.csproj | Removes redundant compiler settings. |
| src/generator/generator.csproj | Removes redundant compiler settings. |
| src/class-parse/class-parse.csproj | Removes redundant compiler settings. |
| src/AndroidBuildConfig/AndroidBuildConfig.csproj | Removes redundant compiler settings. |
| samples/NativeAOT/NativeAOT.csproj | Uses shared compiler defaults. |
| samples/HelloWorld/HelloWorld/HelloWorld.DotNet.csproj | Uses shared compiler defaults. |
| samples/HelloWorld/HelloLibrary/HelloLibrary.DotNet.csproj | Uses shared compiler defaults. |
| eng/InternalTools.props | Enables v2 and preview through Arcade’s repository hook. |
| Documentation/Java.Interop/BuildConfiguration.md | Documents defaults, compiler requirements, and isolated opt-ins. |
| Directory.Build.props | Defines shared v2 and preview defaults with satellite-compilation rationale. |
| build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj | Removes redundant compiler settings. |
| build-tools/xa-prep-tasks/xa-prep-tasks.csproj | Removes redundant compiler settings. |
| build-tools/manifest-attribute-codegen/manifest-attribute-codegen.csproj | Removes redundant compiler settings. |
| build-tools/jnienv-gen/jnienv-gen.csproj | Removes redundant compiler settings. |
| build-tools/java-interop-jnienv-gen/java-interop-jnienv-gen.csproj | Removes redundant compiler settings. |
| build-tools/api-xml-adjuster/api-xml-adjuster.csproj | Removes redundant compiler settings. |
| build-tools/api-merge/api-merge.csproj | Removes redundant compiler settings. |
Review effort: Balanced
b19f656 to
9726ab8
Compare
9726ab8 to
775b540
Compare
775b540 to
60c5506
Compare
<!-- Follow the title and description guidance: https://github.com/dotnet/android/blob/main/Documentation/workflow/commit-messages.md Explain the problem, why the change is needed, and how it fixes the problem. Link to issues fixed, if applicable. State what you tested and the results. If tests were not run, say why. Keep the description concise. Do not copy these instructions into the visible description or add a checklist that repeats them. --> Make memory-safety rules v2 and the required preview language mode repository defaults after the three scoped test-suite opt-ins. Remove redundant project declarations and old C# 13 overrides, including the temporary opt-ins from the lower layers. Keep explicit settings in standalone customer templates and intentionally isolated tooling. Use Arcade's repository hook rather than modifying shared eng/common files, import root props in the legacy binding fixture, and retain the satellite-compilation rationale beside the shared default. The only remaining C# change is the small TestEnvironment native-buffer fix required when the test infrastructure first adopts v2. The larger Java.Interop, runtime-test and binding-test changes are in the preceding PRs. Validation: * `make prepare CONFIGURATION=Debug MSBUILD_ARGS='-m:2 -nr:false -p:UseSharedCompilation=false'` - passed. * `make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:2 -nr:false -p:UseSharedCompilation=false'` - passed, including extra API levels and local workload setup. * `./dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter 'FullyQualifiedName~XASdkTests.DotNetNewFramework|(FullyQualifiedName~CodeBehindTests.SuccessfulBuildFew&Name~CoreCLR&Name!~DTB)'` - 16 passed, 0 failed, 0 skipped. * Refreshed all 99 tracked project records: 77 managed projects have successful actual v2/preview compiler tasks, 15 NoTargets normal builds passed, and all five standalone templates built for both net11.0-android and net12.0-android. Normal-build coverage is 97/99. Known local gaps: * Arcade's internal Tools.csproj cannot restore the private Microsoft.ManifestTool.CrossPlatform package. * The historical McwGen fixture requires unavailable Xamarin.Android.Bindings.targets. * The optional AndroidSdk modern multi-target configuration still lacks net12.0 API inventory files; its normal netstandard2.0 build passes. No diagnostics or API checks were disabled. One build-tests invocation observed missing restore intermediates; its ordinary restore/build retry passed unchanged, with both receipts retained. No on-device execution or full Windows/Release matrix is claimed. Co-authored-by: Copilot App <[email protected]>
60c5506 to
71dc5a1
Compare
Leave generated customer projects on the SDK compiler defaults rather than opting them into preview language mode and memory-safety rules v2. Remove both declarations from all five template payloads and document the distinction from the internal template-packaging project. Validation: rebuilt the local template package and inspected all five packaged csproj files. Generated all five templates outside the repository in an isolated template hive for net11.0-android and net12.0-android: all ten evaluate without v2/preview overrides or repository props inheritance and build successfully. The internal packaging project still evaluates as v2/preview. Co-authored-by: Copilot App <[email protected]>
Tools.csproj is shared Arcade package-restore infrastructure with no owned C# source. Forcing memory-safety rules onto that container adds an unnecessary repository hook without improving coverage of Android implementation or tests. Remove eng/InternalTools.props, leave eng/common untouched, and document the bootstrap exclusion. Repository defaults and the isolated owned workload tool keep their opt-ins. Validation: Tools.csproj evaluates with no MemorySafetyRulesVersion override, its normal C# 7.3 default, and zero Compile items. The template-packaging project and workload tool still evaluate as v2/preview. Co-authored-by: Copilot App <[email protected]>
Context: #13085 Point the shared compiler-setting comment at the existing tracking issue for removing the temporary preview language override. No compiler properties change. Co-authored-by: Copilot App <[email protected]>
|
@dalexsoto review |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
Code assessment: no blocking findings. 0 ❌ errors, 0
Reviewed all 60 changed files in full and traced the shared props imports, generated test-project isolation, template payloads, and Roslyn consumer compilations. Centralizing the existing opt-ins removes duplication without putting these compiler settings into shipped template payloads. The TestEnvironment annotations preserve the existing allocation lifetime and cleanup order.
CI verification is limited: all 38 GitHub check runs report success, including the aggregate dotnet-android check for Azure build 1699161. Independent Azure build/timeline verification could not complete because the Azure CLI requires authentication; I therefore cannot independently certify the pipeline result beyond the successful GitHub checks. No local build or test run was performed for this review.
Generated by Android PR Reviewer for #13734 · copilot · gpt61 · 47.9 AIC · ⌖ 7.9 AIC · ⊞ 20.3K
Comment /review to run again
| The isolated workload-dependency tool opts in separately because it does not | ||
| import the root props. The shared Arcade package-restore bootstrap keeps its own | ||
| defaults. The template packaging project also uses the repository defaults, but | ||
| generated Android projects leave compiler settings at the SDK defaults. |
There was a problem hiding this comment.
🤖 💡 Testing — Consider preserving this customer-project boundary in the existing XASdkTests.DotNetNewFramework test: assert that all five generated project payloads omit MemorySafetyRulesVersion and LangVersion. That test currently checks only TargetFramework, so it would not catch a future accidental compiler opt-in in a shipped template. The outside-repository builds reported in the PR are useful validation; these small assertions would make the payload check persistent.
{Rule: Test assertions must be specific; preserve consumer language modes}
Make memory-safety rules v2 and the required preview language mode defaults for owned repository code and tests. Remove redundant project declarations and old C# 13 overrides, including the temporary opt-ins from the scoped test-suite PRs.
Generated customer projects remain on the SDK compiler defaults: none of the five template payloads sets MemorySafetyRulesVersion or LangVersion. The template-packaging project still inherits the internal v2/preview defaults. The isolated owned workload-dependency tool keeps its explicit opt-in because it bypasses root props.
Leave shared Arcade bootstrap infrastructure unchanged. eng/common/internal/Tools.csproj is a dependency-restore container with no owned C# source, so it is outside this rollout and no eng/InternalTools.props override is added. Private-feed restoration of that scaffold is not a compiler-activation validation requirement.
The only remaining C# change is the small TestEnvironment native-buffer fix required when the test infrastructure first adopts v2. The larger test-suite adaptations were handled in the preceding, now-merged PRs.
Initial rollout validation:
make prepare CONFIGURATION=Debug MSBUILD_ARGS='-m:2 -nr:false -p:UseSharedCompilation=false'- passed.make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:2 -nr:false -p:UseSharedCompilation=false'- passed, including extra API levels and local workload setup../dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter 'FullyQualifiedName~XASdkTests.DotNetNewFramework|(FullyQualifiedName~CodeBehindTests.SuccessfulBuildFew&Name~CoreCLR&Name!~DTB)'- 16 passed, 0 failed, 0 skipped.Scope follow-up validation:
./dotnet-local.sh build build-tools/create-packs/Microsoft.Android.Sdk.proj '-t:_CreateLocalFrameworkLists;PackLocalTemplates' -c Debug -m:2 -nr:false -p:UseSharedCompilation=false -v:minimal- passed; actual NUPKG contents were checked to confirm both compiler settings are absent from all five payloads.Remaining initial validation gaps, not rechecked by these scope-only follow-ups:
No diagnostics or API checks were disabled. No on-device execution or full Windows/Release matrix is claimed.