Skip to content

Commit

Permalink
Import changes from #9686
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Jan 16, 2025
1 parent 394a016 commit 9ca6c05
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
1 change: 0 additions & 1 deletion build-tools/create-packs/Microsoft.Android.Runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ projects that use the Microsoft.Android framework in .NET 6+.
<_RuntimeFlavorDirName Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">mono</_RuntimeFlavorDirName>
</PropertyGroup>

<Message Text="Create packs: AndroidRuntime == '$(AndroidRuntime)'; _RuntimeFlavorDirName == '$(_RuntimeFlavorDirName)' " Importance="High" />
<ItemGroup>
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Java.Interop.dll" />
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETDefaultOutDir)Mono.Android.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ _ResolveAssemblies MSBuild target.
<!-- Filename without extension -->
<_ExcludedNativeLibraries Condition=" '$(_AndroidIncludeSystemGlobalizationNative)' != 'true' " Include="libSystem.Globalization.Native" />
<_ExcludedNativeLibraries Condition=" '$(_AndroidEnableNativeStackTracing)' != 'true' " Include="libxamarin-native-tracing" />
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.debug" />
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' " Include="libnet-android.release" />
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" />
<_ExcludedNativeLibraries Condition=" '$(AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" />
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.debug" />
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' " Include="libnet-android.release" />
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.debug" />
<_ExcludedNativeLibraries Condition=" '$(_AndroidRuntime)' == 'CoreCLR' " Include="libmono-android.release" />
</ItemGroup>
<ProcessNativeLibraries
InputLibraries="@(_ResolvedNativeLibraries)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16
-->
<_GetChildProjectCopyToPublishDirectoryItems>false</_GetChildProjectCopyToPublishDirectoryItems>
<!-- Define a $(_AndroidNativeAot) property, as the logic detecting NativeAOT may change in the future -->
<_AndroidNativeAot Condition=" '$(PublishAot)' == 'true' ">true</_AndroidNativeAot>
<_AndroidNativeAot Condition=" '$(_AndroidNativeAot)' == '' ">false</_AndroidNativeAot>
<UseMonoRuntime Condition=" '$(_AndroidNativeAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' == '' ">false</UseMonoRuntime>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' ">true</UseMonoRuntime>
<_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and '$(UseMonoRuntime)' != 'true' ">NativeAOT</_AndroidRuntime>
<_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' != 'true' ">CoreCLR</_AndroidRuntime>
<_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">MonoVM</_AndroidRuntime>
<!-- HACK: make dotnet restore include Microsoft.NETCore.App.Runtime.NativeAOT.linux-bionic-arm64 -->
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidNativeAot)' == 'true' ">true</_IsPublishing>
<_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">true</_IsPublishing>

<!-- Use $(AndroidMinimumSupportedApiLevel) for $(SupportedOSPlatformVersion) if unset -->
<SupportedOSPlatformVersion Condition=" '$(SupportedOSPlatformVersion)' == '' ">$(AndroidMinimumSupportedApiLevel)</SupportedOSPlatformVersion>
Expand Down Expand Up @@ -88,7 +88,7 @@
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' and '$(PublishTrimmed)' == 'true' ">SdkOnly</AndroidLinkMode>
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' ">None</AndroidLinkMode>
<!-- For compat with user code not marked trimmable, only trim opt-in by default. -->
<TrimMode Condition=" '$(TrimMode)' == '' and ('$(AndroidLinkMode)' == 'Full' or '$(_AndroidNativeAot)' == 'true') ">full</TrimMode>
<TrimMode Condition=" '$(TrimMode)' == '' and ('$(AndroidLinkMode)' == 'Full' or '$(_AndroidRuntime)' == 'NativeAOT') ">full</TrimMode>
<TrimMode Condition="'$(TrimMode)' == ''">partial</TrimMode>
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' and ('$(TrimMode)' == 'full' or '$(IsAotCompatible)' == 'true') ">false</SuppressTrimAnalysisWarnings>
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' ">true</SuppressTrimAnalysisWarnings>
Expand All @@ -97,7 +97,7 @@
<RuntimeIdentifier Condition=" '$(RuntimeIdentifiers)' != '' And '$(RuntimeIdentifier)' != '' " />
<GenerateApplicationManifest Condition=" '$(GenerateApplicationManifest)' == '' ">true</GenerateApplicationManifest>
<!-- Default to Mono's AOT in Release mode -->
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' and '$(_AndroidNativeAot)' != 'true' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == '' and '$(Configuration)' == 'Release' and '$(_AndroidRuntime)' == 'MonoVM' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' and '$(AotAssemblies)' == 'true' ">true</RunAOTCompilation>
<RunAOTCompilation Condition=" '$(RunAOTCompilation)' == '' ">false</RunAOTCompilation>
<_AndroidXA1029 Condition=" '$(AotAssemblies)' != '' ">true</_AndroidXA1029>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
<Import Project="Microsoft.Android.Sdk.DefaultProperties.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Common.Debugging.props"
Condition="Exists('$(MSBuildThisFileDirectory)..\tools\Xamarin.Android.Common.Debugging.props')"/>
<Import Project="Microsoft.Android.Sdk.NativeAOT.targets" Condition=" '$(_AndroidNativeAot)' == 'true' " />
<Import Project="Microsoft.Android.Sdk.NativeAOT.targets" Condition=" '$(_AndroidRuntime)' == 'NativeAOT' " />

</Project>
11 changes: 6 additions & 5 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public class GenerateJavaStubs : AndroidTask
[Output]
public ITaskItem[] GeneratedBinaryTypeMaps { get; set; }

public bool NativeAot { get; set; }
[Required]
public string AndroidRuntime { get; set; } = "";

internal const string AndroidSkipJavaStubGeneration = "AndroidSkipJavaStubGeneration";

Expand Down Expand Up @@ -296,8 +297,8 @@ Dictionary<string, ITaskItem> MaybeGetArchAssemblies (Dictionary<AndroidTargetAr

void GenerateAdditionalProviderSources (NativeCodeGenState codeGenState, IList<string> additionalProviders)
{
if (NativeAot) {
Log.LogDebugMessage ("Skipping MonoRuntimeProvider generation for NativeAot");
if (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) {
Log.LogDebugMessage ($"Skipping MonoRuntimeProvider generation for {AndroidRuntime}");
return;
}

Expand Down Expand Up @@ -354,7 +355,7 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
Debug = Debug,
MultiDex = MultiDex,
NeedsInternet = NeedsInternet,
NativeAot = NativeAot,
AndroidRuntime = AndroidRuntime,
};
// Only set manifest.VersionCode if there is no existing value in AndroidManifest.xml.
if (manifest.HasVersionCode) {
Expand Down Expand Up @@ -388,7 +389,7 @@ IList<string> MergeManifest (NativeCodeGenState codeGenState, Dictionary<string,
(List<TypeDefinition> allJavaTypes, List<TypeDefinition> javaTypesForJCW) = ScanForJavaTypes (resolver, tdCache, assemblies, userAssemblies, useMarshalMethods);
var jcwContext = new JCWGeneratorContext (arch, resolver, assemblies.Values, javaTypesForJCW, tdCache, useMarshalMethods);
var jcwGenerator = new JCWGenerator (Log, jcwContext) {
NativeAot = NativeAot,
CodeGenerationTarget = string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase) ? JavaPeerStyle.XAJavaInterop1 : JavaPeerStyle.JavaInterop1
};
bool success;

Expand Down
4 changes: 2 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class JCWGenerator
readonly TaskLoggingHelper log;
readonly JCWGeneratorContext context;

public bool NativeAot { get; set; }
public JavaPeerStyle CodeGenerationTarget { get; set; } = JavaPeerStyle.XAJavaInterop1;

public MarshalMethodsClassifier? Classifier { get; private set; }

Expand Down Expand Up @@ -127,7 +127,7 @@ bool GenerateCode (CallableWrapperType generator, TypeDefinition type, string ou
bool ok = true;
using var writer = MemoryStreamPool.Shared.CreateStreamWriter ();
var writer_options = new CallableWrapperWriterOptions {
CodeGenerationTarget = NativeAot ? JavaPeerStyle.JavaInterop1 : JavaPeerStyle.XAJavaInterop1
CodeGenerationTarget = CodeGenerationTarget
};

try {
Expand Down
6 changes: 3 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal class ManifestDocument
public bool ForceDebuggable { get; set; }
public string VersionName { get; set; }
public IVersionResolver VersionResolver { get; set; } = new MonoAndroidHelperVersionResolver ();
public bool NativeAot { get; set; }
public string AndroidRuntime { get; set; } = "MonoVM";

string versionCode;

Expand Down Expand Up @@ -673,8 +673,8 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L

IList<string> AddMonoRuntimeProviders (XElement app)
{
if (NativeAot) {
//TODO: implement NativeAOT provider logic
if (!string.Equals (AndroidRuntime, "MonoVM", StringComparison.OrdinalIgnoreCase)) {
//TODO: implement provider logic for non-Mono runtimes
return [];
}

Expand Down
24 changes: 12 additions & 12 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' And '$(EmbedAssembliesIntoApk)' == 'False' ">True</_AndroidFastDeployEnvironmentFiles>
<_AndroidFastDeployEnvironmentFiles Condition=" '$(_AndroidFastDeployEnvironmentFiles)' == '' ">False</_AndroidFastDeployEnvironmentFiles>

<_AndroidUseCLR Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">True</_AndroidUseCLR>
<_AndroidUseCLR Condition=" '$(AndroidRuntime)' != 'CoreCLR' ">False</_AndroidUseCLR>
<_AndroidUseCLR Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">True</_AndroidUseCLR>
<_AndroidUseCLR Condition=" '$(_AndroidRuntime)' != 'CoreCLR' ">False</_AndroidUseCLR>
</PropertyGroup>

<Choose>
Expand Down Expand Up @@ -331,9 +331,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<AndroidUseAssemblyStore Condition=" '$(AndroidUseAssemblyStore)' == '' ">true</AndroidUseAssemblyStore>
<AndroidAotEnableLazyLoad Condition=" '$(AndroidAotEnableLazyLoad)' == '' And '$(AotAssemblies)' == 'true' And '$(AndroidIncludeDebugSymbols)' != 'true' ">True</AndroidAotEnableLazyLoad>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and ('$(UsingMicrosoftNETSdkRazor)' == 'true') ">False</AndroidEnableMarshalMethods>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidNativeAot)' != 'true' ">True</AndroidEnableMarshalMethods>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">True</AndroidEnableMarshalMethods>
<!-- NOTE: temporarily disable for NativeAOT for now, to get build passing -->
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidNativeAot)' == 'true' ">False</AndroidEnableMarshalMethods>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and '$(_AndroidRuntime)' == 'NativeAOT' ">False</AndroidEnableMarshalMethods>
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' == 'True' ">False</_AndroidUseMarshalMethods>
<_AndroidUseMarshalMethods Condition=" '$(AndroidIncludeDebugSymbols)' != 'True' ">$(AndroidEnableMarshalMethods)</_AndroidUseMarshalMethods>
</PropertyGroup>
Expand Down Expand Up @@ -1359,12 +1359,12 @@ because xbuild doesn't support framework reference assemblies.
</Target>

<Target Name="_CollectRuntimeJarFilenames">
<PropertyGroup Condition=" '$(AndroidRuntime)' == 'Mono' Or '$(AndroidRuntime)' == '' ">
<PropertyGroup Condition=" '$(_AndroidRuntime)' == 'Mono' Or '$(_AndroidRuntime)' == '' ">
<_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_net6.jar</_RuntimeJar>
<_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_net6.dex</_RuntimeDex>
</PropertyGroup>

<PropertyGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
<PropertyGroup Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">
<_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime_clr.jar</_RuntimeJar>
<_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime_clr.dex</_RuntimeDex>
</PropertyGroup>
Expand All @@ -1386,7 +1386,7 @@ because xbuild doesn't support framework reference assemblies.
DependsOnTargets="_CollectRuntimeJarFilenames;$(_BeforeAddStaticResources);_GetMonoPlatformJarPath">
<CopyResource ResourceName="machine.config" OutputPath="$(MonoAndroidIntermediateAssemblyDir)machine.config" />
<CopyResource
Condition=" '$(_AndroidNativeAot)' != 'true' "
Condition=" '$(_AndroidRuntime)' == 'MonoVM' "
ResourceName="MonoRuntimeProvider.Bundled.java"
OutputPath="$(_AndroidIntermediateJavaSourceDirectory)mono\MonoRuntimeProvider.java"
/>
Expand Down Expand Up @@ -1505,7 +1505,7 @@ because xbuild doesn't support framework reference assemblies.
</ItemGroup>

<GenerateJavaStubs
NativeAot="$(_AndroidNativeAot)"
AndroidRuntime="$(_AndroidRuntime)"
ResolvedAssemblies="@(_ResolvedAssemblies)"
ResolvedUserAssemblies="@(_ResolvedUserMonoAndroidAssemblies)"
ErrorOnCustomJavaObject="$(AndroidErrorOnCustomJavaObject)"
Expand Down Expand Up @@ -1735,7 +1735,7 @@ because xbuild doesn't support framework reference assemblies.
</Target>

<Target Name="_GeneratePackageManagerJava"
Condition=" '$(_AndroidNativeAot)' != 'true' "
Condition=" '$(_AndroidRuntime)' != 'NativeAOT' "
DependsOnTargets="$(_GeneratePackageManagerJavaDependsOn)"
Inputs="@(_GeneratePackageManagerJavaInputs)"
Outputs="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp">
Expand Down Expand Up @@ -1955,7 +1955,7 @@ because xbuild doesn't support framework reference assemblies.

<!-- Shrink Mono.Android.dll by removing attribute only needed for GenerateJavaStubs -->
<RemoveRegisterAttribute
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidNativeAot)' != 'true' "
Condition="'$(AndroidLinkMode)' != 'None' and '$(AndroidIncludeDebugSymbols)' != 'true' and '$(AndroidStripILAfterAOT)' != 'true' and '$(_AndroidRuntime)' != 'NativeAOT' "
ShrunkFrameworkAssemblies="@(_ShrunkAssemblies)" />

<MakeDir Directories="$(MonoAndroidIntermediateAssemblyDir)shrunk" />
Expand Down Expand Up @@ -2032,13 +2032,13 @@ because xbuild doesn't support framework reference assemblies.
</Target>

<Target Name="_PrepareApplicationSharedLibraryItems">
<ItemGroup Condition=" '$(AndroidRuntime)' != 'CoreCLR' ">
<ItemGroup Condition=" '$(_AndroidRuntime)' != 'CoreCLR' ">
<_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app.so">
<abi>%(_BuildTargetAbis.Identity)</abi>
</_ApplicationSharedLibrary>
</ItemGroup>

<ItemGroup Condition=" '$(AndroidRuntime)' == 'CoreCLR' ">
<ItemGroup Condition=" '$(_AndroidRuntime)' == 'CoreCLR' ">
<_ApplicationSharedLibrary Include="$(_AndroidApplicationSharedLibraryPath)%(_BuildTargetAbis.Identity)\libxamarin-app-clr.so">
<abi>%(_BuildTargetAbis.Identity)</abi>
</_ApplicationSharedLibrary>
Expand Down

0 comments on commit 9ca6c05

Please sign in to comment.