[iOS][Android] Fix up library mode build (#90133)
authorSteve Pfister <steveisok@users.noreply.github.com>
Wed, 9 Aug 2023 15:40:05 +0000 (08:40 -0700)
committerGitHub <noreply@github.com>
Wed, 9 Aug 2023 15:40:05 +0000 (11:40 -0400)
This change makes sure the mobile build task assembly is properly imported, corrections on the LLVM path, and other small minor tweaks.

src/mono/msbuild/android/build/AndroidBuild.targets
src/mono/msbuild/apple/build/AppleBuild.targets
src/mono/nuget/Microsoft.NET.Runtime.LibraryBuilder.Sdk/Sdk/Sdk.targets.in
src/tasks/Common/Builders/AppBuilderTask.cs
src/tasks/LibraryBuilder/LibraryBuilder.cs
src/tasks/LibraryBuilder/LibraryBuilder.csproj
src/tasks/MobileBuildTasks/Android/Ndk/NdkVersion.cs
src/tasks/MobileBuildTasks/MobileBuildTasks.csproj

index 92e8c87..99a226a 100644 (file)
       <DirectPInvokes Include="libSystem.Security.Cryptography.Native.Android" />
     </ItemGroup>
 
+    <PropertyGroup>
+      <_CompilerBinaryPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())'))</_CompilerBinaryPath>
+      <_MonoLLVMPath>$(MonoAotCrossDir)</_MonoLLVMPath>
+      <_MonoLLVMPath Condition="'$(_MonoLLVMPath)' == '' and '$(MonoEnableLLVM)' == 'true'">$([System.IO.Path]::GetDirectoryName("$(_CompilerBinaryPath)"))</_MonoLLVMPath>
+    </PropertyGroup>
+
     <MonoAOTCompiler
         AotModulesTablePath="$(_AotModuleTablePath)"
         AsPrefix="$(_AsPrefixPath)"
         Assemblies="@(_AotInputAssemblies)"
-        CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())'))"
+        CompilerBinaryPath="$(_CompilerBinaryPath)"
         DirectPInvokes="@(DirectPInvokes)"
         DirectPInvokeLists="@(DirectPInvokeLists)"
         EnableUnmanagedCallersOnlyMethodsExport="$(_EnableUnmanagedCallersOnlyMethodsExport)"
         IntermediateOutputPath="$(_MobileIntermediateOutputPath)"
         LibraryFormat="$(_AotLibraryFormat)"
-        LLVMPath="$(MonoAotCrossDir)"
+        LLVMPath="$(_MonoLLVMPath)"
         MibcProfilePath="@(ProfiledAOTProfilePaths)"
         Mode="$(_AOTMode)"
         OutputDir="$(_MobileIntermediateOutputPath)"
index 22e6007..a435e8a 100644 (file)
       <RuntimeComponentList Remove="marshal-ilgen" />
     </ItemGroup>
 
-    <PropertyGroup Condition="'$(ForceAllComponents)'!='true'">
+    <PropertyGroup Condition="'$(ForceAllComponents)'!='true' and '@(RuntimeComponentList->Count())' > 0">
       <RuntimeComponents>@(RuntimeComponentList)</RuntimeComponents>
     </PropertyGroup>
   </Target>
       <DirectPInvokes Include="libSystem.Security.Cryptography.Native.Apple" />
     </ItemGroup>
 
+    <PropertyGroup>
+      <_CompilerBinaryPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())'))</_CompilerBinaryPath>
+      <_MonoLLVMPath>$(MonoAotCrossDir)</_MonoLLVMPath>
+      <_MonoLLVMPath Condition="'$(_MonoLLVMPath)' == '' and '$(MonoEnableLLVM)' == 'true'">$([System.IO.Path]::GetDirectoryName("$(_CompilerBinaryPath)"))</_MonoLLVMPath>
+    </PropertyGroup>
+
     <MonoAOTCompiler Condition="'$(RunAOTCompilation)' == 'true'"
         AotModulesTablePath="$(_AotModuleTablePath)"
         AotModulesTableLanguage="ObjC"
         Assemblies="@(_AotInputAssemblies)"
-        CompilerBinaryPath="@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','$(TargetOS.ToLowerInvariant())-$(TargetArchitecture.ToLowerInvariant())'))"
+        CompilerBinaryPath="$(_CompilerBinaryPath)"
         DedupAssembly="$(_iOSLikeDedupAssembly)"
         DirectPInvokes="@(DirectPInvokes)"
         DirectPInvokeLists="@(DirectPInvokeLists)"
         EnableUnmanagedCallersOnlyMethodsExport="$(_EnableUnmanagedCallersOnlyMethodsExport)"
         IntermediateOutputPath="$(_MobileIntermediateOutputPath)"
-        LLVMPath="$(MonoAotCrossDir)"
+        LLVMPath="$(_MonoLLVMPath)"
         Mode="$(_AOTMode)"
         OutputDir="$(_MobileIntermediateOutputPath)"
         OutputType="AsmOnly"
index 5e59415..dbe8e15 100644 (file)
@@ -5,10 +5,11 @@
     <_TasksDir Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETCoreTasks}\</_TasksDir>
     <_TasksDir Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\${TargetFrameworkForNETFrameworkTasks}\</_TasksDir>
 
-    <GenerateAppBundle>false</GenerateAppBundle>
+    <GenerateAppBundle Condition="'$(GenerateAppBundle)' == ''">true</GenerateAppBundle>
     <NativeLib Condition="'$(NativeLib)' == ''">shared</NativeLib>
 
     <LibraryBuilderTasksAssemblyPath>$(_TasksDir)LibraryBuilder.dll</LibraryBuilderTasksAssemblyPath>
+    <MobileBuildTasksAssemblyPath>$(_TasksDir)MobileBuildTasks.dll</MobileBuildTasksAssemblyPath>
   </PropertyGroup>
 
   <Import Project="$(MSBuildThisFileDirectory)\LibraryBuilder.props" />
index 3a970ba..4da682a 100644 (file)
@@ -36,8 +36,7 @@ public class AppBuilderTask : Task
     /// Path to store build artifacts
     /// </summary>
     [Required]
-    [NotNull]
-    public string? OutputDirectory { get; set; }
+    public string OutputDirectory { get; set; } = ""!;
 
     /// <summary>
     /// OS + architecture runtime identifier
@@ -59,7 +58,7 @@ public class AppBuilderTask : Task
     /// <summary>
     /// Diagnostic ports configuration string
     /// </summary>
-    public string? DiagnosticPorts { get; set; } = ""!;
+    public string DiagnosticPorts { get; set; } = ""!;
 
     protected List<CompiledAssembly> CompiledAssemblies { get; set; }
 
index 5371944..d96b5c4 100644 (file)
@@ -28,8 +28,7 @@ public class LibraryBuilderTask : AppBuilderTask
     /// The name of the library being generated
     /// </summary>
     [Required]
-    [NotNull]
-    public string? Name { get; set; }
+    public string? Name { get; set; } = ""!;
 
     /// <summary>
     /// The name of the OS being targeted
index e2b6ed1..e0445fc 100644 (file)
@@ -1,6 +1,6 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFramework>$(TargetFrameworkForNETCoreTasks)</TargetFramework>
+    <TargetFrameworks>$(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks)</TargetFrameworks>
     <OutputType>Library</OutputType>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
     <Compile Include="..\Common\Builders\CompiledAssembly.cs" />
     <Compile Include="..\Common\LogAsErrorException.cs" />
     <Compile Include="..\AppleAppBuilder\TargetOS.cs" />
-    <Compile Include="..\AppleAppBuilder\Xcode.cs" />
   </ItemGroup>
 
   <Target Name="GetFilesToPackage" Returns="@(FilesToPackage)">
     <ItemGroup>
-      <FilesToPackage Include="$(OutputPath)$(MSBuildProjectName)*"
-                      TargetPath="tasks\$(TargetFrameworkForNETCoreTasks)" />
+      <_PublishFramework Remove="@(_PublishFramework)" />
+      <_PublishFramework Include="$(TargetFrameworks)" />
+
+      <!-- Copies every assembly that is in the artifacts/bin/MonoTargetsTasks/ subfolders.  Be careful not to include too much. -->
+      <FilesToPackage Include="$(OutputPath)%(_PublishFramework.Identity)\*.dll" TargetPath="tasks\%(_PublishFramework.Identity)" />
+      <FilesToPackage Include="$(OutputPath)%(_PublishFramework.Identity)\*.pdb" TargetPath="tasks\%(_PublishFramework.Identity)" />
     </ItemGroup>
   </Target>
 
index 2db3715..d45e88d 100644 (file)
@@ -20,7 +20,7 @@ namespace Microsoft.Android.Build.Ndk
                 throw new ArgumentException ("must be a non-empty string", nameof (version));
             }
 
-            int tagIdx = ver.IndexOf('-');
+            int tagIdx = ver!.IndexOf('-');
             if (tagIdx >= 0)
             {
                 Tag = ver.Substring(tagIdx + 1);
index 15398df..f0f24ca 100644 (file)
@@ -2,10 +2,7 @@
   <PropertyGroup>
     <TargetFrameworks>$(TargetFrameworkForNETCoreTasks);$(TargetFrameworkForNETFrameworkTasks)</TargetFrameworks>
     <Nullable>enable</Nullable>
-    <NoWarn>$(NoWarn),CA1050</NoWarn>
-    <!-- Ignore nullable warnings on net4* -->
-    <NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">$(NoWarn),CS8604,CS8602</NoWarn>
-    <NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETFramework'">$(NoWarn),CA1850</NoWarn>
+    <NoWarn>$(NoWarn),CA1050,CA1850</NoWarn>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
     <Compile Include="..\Common\IsExternalInit.cs" />