[src] Use numeric values for the Runtime.Arch field substitution. - #26371
[src] Use numeric values for the Runtime.Arch field substitution.#26371rolfbjarne wants to merge 2 commits into
Conversation
Neither ILLink nor ILC understand enum value names in substitution XML: ILLink's
TryConvertValue only switches on primitive MetadataTypes (an enum-typed field
falls through and produces an IL2015 warning), and ILC's TryCreateSubstitution
resolves the enum's underlying type but only parses numeric values.
This went unnoticed until now because ILLink only warned, but on .NET 11 with
NativeAOT we skip ILLink entirely and let ILC do all the trimming - and ILC
turns IL2015 into an error:
error IL2015: Microsoft.iOS: Invalid value 'DEVICE' for 'ObjCRuntime.Runtime.Arch'.
Use 0 (Arch.DEVICE) and 1 (Arch.SIMULATOR) instead, which also makes the
substitution actually take effect.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aa4f11db-0d12-4600-bac4-06a7ef562c8a
There was a problem hiding this comment.
Pull request overview
This PR updates ILLink/ILC substitution XML to use numeric values for the ObjCRuntime.Runtime.Arch enum field, ensuring substitutions work correctly with ILC (NativeAOT) where enum names are rejected (IL2015).
Changes:
- Replace
value="DEVICE"/value="SIMULATOR"field substitutions withvalue="0"/value="1"forRuntime.Arch. - Add inline comments documenting why numeric values are required.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ILLink.Substitutions.iOS.xml | Switch Runtime.Arch field substitution values from enum names to numeric constants for ILC compatibility. |
| src/ILLink.Substitutions.tvOS.xml | Same substitution update as iOS to ensure trimming substitutions apply under ILC/NativeAOT. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
… ILLink and ILC want.
The previous commit made the iOS and tvOS tests fail to build, because ILLink
and ILC disagree - incompatibly - about how to specify the substitution value
for an enum-typed field:
* ILLink's ProcessLinkerXmlBase.TryConvertValue hits 'MetadataType.ValueType'
for an enum, resolves the enum type, and only matches the value against the
enum's field *names*.
* ILC's BodySubstitutionsParser.TryCreateSubstitution switches on
'type.UnderlyingType.Category' (Int32 for an enum), and only 'int.TryParse's
the value.
So there's no single value that works for both, and each one reports IL2015 for
the other's format:
dotnet publish
-> error IL2015: Microsoft.iOS: Invalid value '0' for 'ObjCRuntime.Runtime.Arch'.
dotnet publish -p:PublishAot=true
-> error IL2015: Microsoft.iOS: Invalid value 'DEVICE' for 'ObjCRuntime.Runtime.Arch'.
Specify both variants, and select between them with a new 'ObjCRuntime.IsILCompiler'
feature switch that we only pass to ILC. The ILLink variant is the default (via
featuredefault="true"), so it's used whenever the feature switch isn't set at all.
Reported upstream as dotnet/runtime#131601.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: aa4f11db-0d12-4600-bac4-06a7ef562c8a
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #b6724ab] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 43 tests failed, 160 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)19 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)19 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ msbuild tests1 tests failed, 1 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests1 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
ILLink and ILC disagree - incompatibly - about how to specify the substitution value for an enum-typed field in
ILLink.Substitutions.xml:ProcessLinkerXmlBase.TryConvertValuehitsMetadataType.ValueType, resolves the enum, and matches the value against the enum's field namesBodySubstitutionsParser.TryCreateSubstitutionswitches ontype.UnderlyingType.Category(Int32for an enum), and onlyint.TryParses the valueSo there's no single value that works for both, and each one reports
IL2015for the other's format:This surfaced now because on .NET 11 with NativeAOT we skip ILLink entirely and let ILC do all the trimming, so ILC parses our substitution XML itself for the first time.
Fix
Specify both variants for the
ObjCRuntime.Runtime.Archfield, in two separate<type>blocks selected by a newObjCRuntime.IsILCompilerfeature switch:The feature switch is passed only to ILC, from
_XamarinComputeIlcCompileInputsinXamarin.Shared.Sdk.targets:The ILLink variant uses
featuredefault="true", so it's the one that applies whenever the feature switch isn't set at all (which is always the case for ILLink).Validation
tests/dotnet/MySimpleApp/{iOS,tvOS}publish cleanly both with and without-p:PublishAot=true, including the configuration where both ILLink and ILC process the XML.Reported upstream as dotnet/runtime#131601.
🤖 Pull request description updated by Copilot