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

[Mono.Android] introduce #if NATIVEAOT for monodroid_get_log_categories() #9624

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<AndroidFrameworkVersion Condition=" '$(AndroidFrameworkVersion)' == '' ">$(AndroidLatestStableFrameworkVersion)</AndroidFrameworkVersion>
<AndroidUseLatestPlatformSdk Condition=" '$(AndroidFrameworkVersion)' == '' ">True</AndroidUseLatestPlatformSdk>
<AndroidJavaRuntimeApiLevel Condition="'$(AndroidJavaRuntimeApiLevel)' == ''">$(AndroidLatestStableApiLevel)</AndroidJavaRuntimeApiLevel>
<AndroidRuntime Condition=" '$(AndroidRuntime)' == '' ">Mono</AndroidRuntime>
<DebugType Condition=" '$(DebugType)' == '' ">portable</DebugType>
<Deterministic Condition=" '$(Deterministic)' == '' ">True</Deterministic>
<LangVersion Condition=" '$(LangVersion)' == '' ">latest</LangVersion>
Expand All @@ -60,7 +61,7 @@
<AutoProvisionUsesSudo Condition=" '$(AutoProvisionUsesSudo)' == '' ">False</AutoProvisionUsesSudo>
<_XABinRelativeInstallPrefix>lib\xamarin.android</_XABinRelativeInstallPrefix>
<XAInstallPrefix Condition=" '$(XAInstallPrefix)' == '' ">$(MSBuildThisFileDirectory)bin\$(Configuration)\$(_XABinRelativeInstallPrefix)\</XAInstallPrefix>
<_MonoAndroidNETOutputRoot>$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\</_MonoAndroidNETOutputRoot>
<_MonoAndroidNETOutputRoot>$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android.$(AndroidRuntime)\</_MonoAndroidNETOutputRoot>
<_MonoAndroidNETDefaultOutDir>$(_MonoAndroidNETOutputRoot)$(AndroidApiLevel)\</_MonoAndroidNETDefaultOutDir>
<MicrosoftAndroidRefPackDir>$(BuildOutputDirectory)lib\packs\Microsoft.Android.Ref.$(AndroidApiLevel)\$(AndroidPackVersion)\ref\$(DotNetTargetFramework)\</MicrosoftAndroidRefPackDir>
<MicrosoftAndroidSdkPackDir>$(BuildOutputDirectory)lib\packs\$(MicrosoftAndroidSdkPackName)\$(AndroidPackVersion)\</MicrosoftAndroidSdkPackDir>
Expand Down Expand Up @@ -214,7 +215,8 @@

<Import Project="$(MSBuildThisFileDirectory)build-tools\scripts\Ndk.targets" />
<ItemGroup>
<AndroidAbiAndRuntimeFlavor Include="@(AndroidSupportedTargetJitAbi)" AndroidRuntime="Mono" />
<AndroidAbiAndRuntimeFlavor Include="@(AndroidSupportedTargetJitAbi)" AndroidRuntime="NativeAOT" />
<AndroidRuntimes Include="Mono" />
<AndroidRuntimes Include="NativeAOT" />
<AndroidAbiAndRuntimeFlavor Include="@(AndroidSupportedTargetJitAbi)" AndroidRuntime="%(AndroidRuntimes.Identity)" />
</ItemGroup>
</Project>
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 @@ -11,7 +11,6 @@ projects that use the Microsoft.Android framework in .NET 6+.

<PropertyGroup>
<AndroidRID Condition=" '$(AndroidRID)' == '' ">android-arm64</AndroidRID>
<AndroidRuntime Condition=" '$(AndroidRuntime)' == '' ">Mono</AndroidRuntime>
<PackageId>Microsoft.Android.Runtime.$(AndroidRuntime).$(AndroidApiLevel).$(AndroidRID)</PackageId>
<Description>Microsoft.Android runtime components for API $(AndroidApiLevel). Please do not reference directly.</Description>
<_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\$(DotNetTargetFramework)</_AndroidRuntimePackAssemblyPath>
Expand Down
14 changes: 11 additions & 3 deletions build-tools/scripts/DotNet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@
<MSBuild Projects="$(_Root)build-tools\create-packs\Microsoft.Android.Sdk.proj" Targets="ConfigureLocalWorkload" />
</Target>

<Target Name="BuildOtherRuntimes">
<MSBuild
Condition=" '%(AndroidRuntimes.Identity)' != 'Mono' "
Projects="$(_Root)src\Mono.Android\Mono.Android.csproj"
Properties="AndroidRuntime=%(AndroidRuntimes.Identity)"
/>
</Target>

<!-- Build Mono.Android.dll for additional API levels if necessary -->
<Target Name="BuildExtraApiLevels">
<MSBuild
Condition=" '$(AndroidDefaultTargetDotnetApiLevel)' != '$(AndroidLatestStableApiLevel)' "
Projects="$(_Root)src\Mono.Android\Mono.Android.csproj"
Properties="AndroidApiLevel=$(AndroidDefaultTargetDotnetApiLevel);AndroidPlatformId=$(AndroidDefaultTargetDotnetApiLevel)"
Properties="AndroidApiLevel=$(AndroidDefaultTargetDotnetApiLevel);AndroidPlatformId=$(AndroidDefaultTargetDotnetApiLevel);AndroidRuntime=%(AndroidRuntimes.Identity)"
/>
<MSBuild
Condition=" '$(AndroidLatestUnstableApiLevel)' != '$(AndroidLatestStableApiLevel)' "
Projects="$(_Root)src\Mono.Android\Mono.Android.csproj"
Properties="AndroidApiLevel=$(AndroidLatestUnstableApiLevel);AndroidPlatformId=$(AndroidLatestUnstablePlatformId);AndroidFrameworkVersion=$(AndroidLatestUnstableFrameworkVersion)"
Properties="AndroidApiLevel=$(AndroidLatestUnstableApiLevel);AndroidPlatformId=$(AndroidLatestUnstablePlatformId);AndroidFrameworkVersion=$(AndroidLatestUnstableFrameworkVersion);AndroidRuntime=%(AndroidRuntimes.Identity)"
/>
</Target>

<Target Name="PackDotNet"
DependsOnTargets="BuildExtraApiLevels">
DependsOnTargets="BuildExtraApiLevels;BuildOtherRuntimes">
<MSBuild Projects="$(_Root)build-tools\create-packs\Microsoft.Android.Sdk.proj" Targets="CreateAllPacks" />
<MSBuild Projects="$(_Root)build-tools\create-packs\Microsoft.Android.Sdk.proj" Targets="ExtractWorkloadPacks" />
<!-- Clean up old, previously restored packages -->
Expand Down
7 changes: 7 additions & 0 deletions src/Mono.Android/Android.Runtime/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ public static void Log (LogLevel level, string appname, string? log) {
}
}

#if !NATIVEAOT
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
extern static uint monodroid_get_log_categories ();
#endif

static Logger ()
{
#if NATIVEAOT
// TODO: p/invoke into __system_property_get
Categories = LogCategories.Default | LogCategories.Assembly;
Copy link
Member

Choose a reason for hiding this comment

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

wrt my earlier comment:

I'd really prefer the need for any such changes to Mono.Android.dll, if possible…

Could we instead have LogCategories (or an int variation) be a member of JnienvInitializeArgs, and have both NativeAOT and MonoVM use JniEnvInit.Initialize(JnienvInitializeArgs*)? This would allow removing the need for monodroid_get_log_categories() entirely, and aim for consistent initialization between the two environments.

Copy link
Member

Choose a reason for hiding this comment

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

…especially when logCategories is already a field in JnnenvInitializeArgs (?!):

public uint logCategories;

Why do we have this P/Invoke at all?!

Copy link
Member Author

Choose a reason for hiding this comment

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

I’ll open a new PR to remove the p/invoke. I’ll see if we still need a define later.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems like this will work:

But we'll want to merge #9622 first, or the pinvoke-table will have conflicts.

#else // !NATIVEAOT
Categories = (LogCategories) monodroid_get_log_categories ();
#endif // !NATIVEAOT
}
}
}
7 changes: 4 additions & 3 deletions src/Mono.Android/Mono.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<NoWarn>0618;0809;0108;0114;0465;8609;8610;8614;8617;8613;8764;8765;8766;8767;RS0041</NoWarn>
<WarningsAsErrors>$(WarningsAsErrors);CS2002</WarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);JAVA_INTEROP</DefineConstants>
<DefineConstants Condition=" '$(AndroidRuntime)' == 'Mono' ">$(DefineConstants);JAVA_INTEROP;MONO</DefineConstants>
<DefineConstants Condition=" '$(AndroidRuntime)' == 'NativeAOT' ">$(DefineConstants);JAVA_INTEROP;NATIVEAOT</DefineConstants>
Comment on lines +16 to +17
Copy link
Member Author

Choose a reason for hiding this comment

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

I was debating the names here. Should it be MONO_RUNTIME and NATIVEAOT_RUNTIME?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a RUNTIME_ prefix, vs. a _RUNTIME suffix: RUNTIME_MONOVM, RUNTIME_NATIVEAOT, etc.

I'd really prefer the need for any such changes to Mono.Android.dll, if possible…

<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework)\android-$(AndroidPlatformId)\</IntermediateOutputPath>
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
<JavaCallableWrapperAfterTargets>CoreBuild</JavaCallableWrapperAfterTargets>
Expand Down Expand Up @@ -410,7 +411,7 @@
<_RefExtras Include="$(OutputPath)*.*" Exclude="$(OutputPath)*.dll" />
<_SourceFiles Include="$(OutputPath)Mono.Android.*" />
<_SourceFiles Include="$(OutputPath)Java.Interop.*" />
<_RuntimePackFiles Include="@(_SourceFiles)" AndroidRID="%(AndroidAbiAndRuntimeFlavor.AndroidRID)" AndroidRuntime="%(AndroidAbiAndRuntimeFlavor.AndroidRuntime)" />
<_RuntimePackFiles Include="@(_SourceFiles)" AndroidRID="%(AndroidAbiAndRuntimeFlavor.AndroidRID)" />
</ItemGroup>
<Copy
SourceFiles="@(_RefExtras)"
Expand All @@ -424,7 +425,7 @@
/>
<Copy
SourceFiles="%(_RuntimePackFiles.Identity)"
DestinationFolder="$(BuildOutputDirectory)lib\packs\Microsoft.Android.Runtime.%(_RuntimePackFiles.AndroidRuntime).$(AndroidApiLevel).%(_RuntimePackFiles.AndroidRID)\$(AndroidPackVersion)\runtimes\%(_RuntimePackFiles.AndroidRID)\lib\$(DotNetTargetFramework)"
DestinationFolder="$(BuildOutputDirectory)lib\packs\Microsoft.Android.Runtime.$(AndroidRuntime).$(AndroidApiLevel).%(_RuntimePackFiles.AndroidRID)\$(AndroidPackVersion)\runtimes\%(_RuntimePackFiles.AndroidRID)\lib\$(DotNetTargetFramework)"
SkipUnchangedFiles="true"
/>
<Copy
Expand Down
Loading