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

Fix non-NativeAOT builds with PublishAot=true in the project file #18727

Merged
merged 3 commits into from
Aug 16, 2023

Conversation

filipnavara
Copy link
Contributor

@filipnavara filipnavara commented Aug 14, 2023

The gist is:

  • If you enable <PublishAot>true</PublishAot> then the NativeAOT build targets get included.
  • Unless NativeCompilationDuringPublish is disabled, the NativeAOT targets are chained through BeforeTargets attribute to some publish targets (computing the resolved publish paths). Xamarin runs those publish targets even for non-publish builds, so it brings the whole ILC compilation along. That's undesirable.
  • The RunILLink property is set unconditionally by the NativeAOT build integration. If we don't fix it then ILLink never runs, and neither do all the custom steps to generate registrars and main().

Update: Apparently, we still need to fix runtime pack resolution for iOS-like platforms with PublishAotUsingRuntimePack=true.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +467 to +487
<!--
Workaround for SDK issue where setting PublishAot=true during build cannot resolve correct
runtime pack and IL compiler pack.

Setting PublishAotUsingRuntimePack=true unconditionally results in the runtime pack label to
be updated to "NativeAOT" instead of "Mono" and trying to build against NativeAOT runtime
pack instead of the Mono one.

Setting PublishAotUsingRuntimePack=false causes the NuGet resolution to check for known
ILCompiler packs and these don't exist for iOS-like platforms.

The workaround ensure that PublishAotUsingRuntimePack is false when SDK updates the runtime
pack labels, and thus the "Mono" label is used. We then set it to true right before
ProcessFrameworkReferences target to skip downloading the target ILCompiler pack.
-->
<Target Name="_WorkaroundAotRuntimePackResolution" BeforeTargets="ProcessFrameworkReferences" Condition="'$(PublishAot)' == 'true' And '$(_UseNativeAot)' != 'true'">
<PropertyGroup>
<PublishAotUsingRuntimePack>true</PublishAotUsingRuntimePack>
</PropertyGroup>
</Target>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct fix here: dotnet/sdk#34640

If it's accepted and ingested then we should remove this workaround and unconditionally set <PublishAotUsingRuntimePack>true</PublishAotUsingRuntimePack> when PublishAot=true in dotnet/targets/Xamarin.Shared.Sdk.props.

Copy link
Member

Choose a reason for hiding this comment

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

Filed to #18741 to not forget to remove the workaround.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • tvOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • watchOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • tvOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • MacCatalyst: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • Microsoft.iOS vs Microsoft.MacCatalyst: vsdrops gist
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 84a0aa634cf55a99b523120a3780a381c900b3cd [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Ventura (13.0) passed 💻

All tests on macOS M1 - Mac Ventura (13.0) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build] Windows Integration Tests passed 💻

All Windows Integration Tests passed.

Pipeline on Agent
Hash: 84a0aa634cf55a99b523120a3780a381c900b3cd [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Contributor

@haritha-mohan haritha-mohan left a comment

Choose a reason for hiding this comment

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

Just trying to follow, but I believe ILC is referring to the intermediate language? So in the case of when we are not publishing but still using aot mode there is no need to go through the hassle of linking the IL since its not actively getting distributed anywhere?

@filipnavara
Copy link
Contributor Author

Just trying to follow, but I believe ILC is referring to the intermediate language?

ILC refers to IL Compiler here, which is the NativeAOT compiler that translates intermediate language into native code.

So in the case of when we are not publishing but still using aot mode...

We only do NativeAOT compilation for dotnet publish (as opposed to dotnet build) and only when PublishAot property is set to true. The distinction between the dotnet build and dotnet publish command is detected using the _IsPublishing property.

This PR tries to repair the case of dotnet build with PublishAot=true and _IsPublishing=false. In this case we want to do regular build with MonoVM, whether it is using AOT, interpreter or JIT (eg. x64 simulator). However, the mere presence of the PublishAot property brings in part of the NativeAOT build pipeline. This is done intentionally, to enable analyzers that warn users about code that uses pattern that are unsafe for trimming/NativeAOT even if they are not publishing yet. Unfortunately it has some unintentional interaction with the Xamarin build process that this PR is trying to resolve.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 232 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 6 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 38 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 84a0aa634cf55a99b523120a3780a381c900b3cd [PR build]

@rolfbjarne rolfbjarne merged commit b4975e2 into xamarin:net8.0 Aug 16, 2023
@filipnavara filipnavara deleted the fix-publishaot-in-csproj branch August 16, 2023 09:10
@rolfbjarne rolfbjarne added the community Community contribution ❤ label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution ❤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants