From 772e7020b1f4d9651ef2cbcc3bbea9610c2b93c8 Mon Sep 17 00:00:00 2001
From: Dan Siegel <me@dansiegel.net>
Date: Mon, 26 Feb 2024 21:49:12 -0600
Subject: [PATCH] feat: adding support for AOT Generation

---
 src/Uno.Sdk/targets/Uno.Common.targets      |  3 +++
 src/Uno.Sdk/targets/Uno.GenerateAot.targets | 22 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 src/Uno.Sdk/targets/Uno.GenerateAot.targets

diff --git a/src/Uno.Sdk/targets/Uno.Common.targets b/src/Uno.Sdk/targets/Uno.Common.targets
index 2609329cd712..db478ced59fa 100644
--- a/src/Uno.Sdk/targets/Uno.Common.targets
+++ b/src/Uno.Sdk/targets/Uno.Common.targets
@@ -77,6 +77,9 @@
 	<Import Project="Uno.Common.Wasm.targets"
 		Condition=" $(_IsStandaloneWasmHead) and $(UsingUnoCommonWasmTargets) == '' " />
 
+	<Import Project="Uno.GenerateAot.targets"
+		Condition=" $(UnoGenerateAotProfile) == 'true' AND $(IsUnoHead) == 'true' " />
+
 	<ItemGroup>
 		<_IgnorePlatformFiles Include="$(AndroidProjectFolder)**"
 			Condition=" $(IsAndroid) != 'true' " />
diff --git a/src/Uno.Sdk/targets/Uno.GenerateAot.targets b/src/Uno.Sdk/targets/Uno.GenerateAot.targets
new file mode 100644
index 000000000000..ab88c35d4df8
--- /dev/null
+++ b/src/Uno.Sdk/targets/Uno.GenerateAot.targets
@@ -0,0 +1,22 @@
+<Project>
+	<PropertyGroup Condition="$(IsBrowser) == 'true'">
+		<WasmShellGenerateAOTProfile>true</WasmShellGenerateAOTProfile>
+		<WasmShellILLinkerEnabled>false</WasmShellILLinkerEnabled>
+		<UnoXamlResourcesTrimming>false</UnoXamlResourcesTrimming>
+		<WasmShellEnableJiterpreter>false</WasmShellEnableJiterpreter>
+	</PropertyGroup>
+
+	<ItemGroup Condition="$(IsBrowser) == 'true'">
+		<WasmShellEnableAotProfile Include="aot.profile" Condition="Exists('aot.profile')" />
+		<WasmShellEnableAotProfile Include="$(WasmProjectFolder)aot.profile" Condition="Exists('$(WasmProjectFolder)aot.profile')" />
+	</ItemGroup>
+
+	<Target Name="ValidateAotConfiguration"
+		BeforeTargets="CoreCompile"
+		Condition="$(IsBrowser) == 'true' OR $(IsAndroid) == 'true'">
+		<Error Condition="$(Optimize) != 'true'"
+			HelpLink="https://aka.platform.uno/UNOB0007"
+			Text="AOT compilation is only supported in Release mode. Please set the 'Optimize' property to 'true' in the project file."
+			ErrorCode="UNOB0007" />
+	</Target>
+</Project>