xamarin-macios/msbuild
Filip Navara d89b6390f1
Update AOTCompile task to handle cycles in up-to-date check (#20103)
#### Background

While cyclic assembly references are unusual they are supported by the runtime and encountered in practice. In our project we use a version of Xamarin.Forms retargeted for a modern .NET (as a stopgap solution before an update to full MAUI stack). Xamarin.Forms historically come with such an assembly cycle: `Xamarin.Forms.Core.dll` -> `Xamarin.Forms.Platform.dll` -> `Xamarin.Forms.Platform.iOS.dll` -> `Xamarin.Forms.Core.dll`. This is produced by first compiling `Xamarin.Forms.Core.dll` against a dummy `Xamarin.Forms.Platform.dll` (`netstandard2.0` assembly). Then the Platform assemblies are built, and finally forwarder versions of `Xamarin.Forms.Platform.dll` are created for each platform. This is all packaged into NuGets in such a way that each TFM gets the same `Xamarin.Forms.Core.dll` but a different set of `Xamarin.Forms.Platform.dll` and `Xamarin.Forms.Platform.<platform>.dll` assemblies.

#### Problem

With current workloads each incremental rebuild fails with:

```
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.4.7125/targets/Xamarin.Shared.Sdk.targets(1047,3): error : Encountered an assembly reference cycle related to the assembly obj/Debug/net7.0-ios/iossimulator-arm64/linked/Xamarin.Forms.Core.dll
```

#### Solution

The PR updates the algorithm in `AOTCompile` to detect cycles using [Tarjan's algorithm](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm) for finding [strongly connected components](https://en.wikipedia.org/wiki/Strongly_connected_component) in a graph. When a cycle is detect any assembly in the cycle is considered up-to-date only if all the assemblies in the cycle are up-to-date.

With this change the project does incremental rebuilds correctly. I verified in the build output that the assembly cycle is considered up-to-date, and that any changes to the application assemblies still return `false` from the up-to-date check and get rebuilt.

---------

Co-authored-by: Filip Navara <filip.navara@gmail.com>
2024-02-15 17:29:18 +01:00
..
Messaging/Xamarin.Messaging.Build [msbuild] Remove usage of GitInfo in Xamarin.Messaging.Build. (#19935) 2024-01-29 18:50:16 +01:00
Xamarin.HotRestart.PreBuilt [msbuild] Explicitly exclude any GitInfo package references we've pulled in. (#19937) 2024-01-29 18:49:50 +01:00
Xamarin.Localization.MSBuild Update AOTCompile task to handle cycles in up-to-date check (#20103) 2024-02-15 17:29:18 +01:00
Xamarin.Mac.Tasks [msbuild] Rename numerous files to match their task name. (#20013) 2024-02-07 09:50:48 +01:00
Xamarin.MacDev.Tasks Update AOTCompile task to handle cycles in up-to-date check (#20103) 2024-02-15 17:29:18 +01:00
Xamarin.ObjcBinding.Tasks [msbuild] Remove support for XI/Classic. (#976) 2016-10-13 10:47:46 +02:00
Xamarin.Shared [msbuild] Use MetadataLoadContext in the UnpackLibraryResources task. (#20017) 2024-02-13 16:40:58 +01:00
Xamarin.iOS.Tasks [msbuild] Rename numerous files to match their task name. (#20013) 2024-02-07 09:50:48 +01:00
Xamarin.iOS.Tasks.Windows [msbuild] Explicitly exclude any GitInfo package references we've pulled in. (#19937) 2024-01-29 18:49:50 +01:00
.gitignore [msbuild] Use a single generated versions file for all platforms. (#19593) 2023-12-13 12:52:47 +01:00
Directory.Build.props [msbuild] Use exact version of XVS' packages. (#20043) 2024-02-07 09:48:29 +01:00
ILMerge.targets [msbuild] Use MetadataLoadContext in the UnpackLibraryResources task. (#20017) 2024-02-13 16:40:58 +01:00
Makefile [msbuild] Don't try to bundle the BouncyCastle.Crypto library anymore. (#20044) 2024-02-06 14:42:39 +01:00
Xamarin.MacDev.Tasks.sln [msbuild] Remove the Xamarin.*.Task.Core assemblies. (#15768) 2022-08-29 11:59:28 +02:00