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

Conversation

jonathanpeppers
Copy link
Member

In a NativeAOT context, we don't have libmonodroid.so at all.

This change introduces a new #if NATIVEAOT block in Logger.cs to avoid calling monodroid_get_log_categories() and using Default | Assembly by default.

I also reworked the build, so that the $(AndroidRuntime) property is defined in Configuration.props. Other projects can eventually use it as-needed.

In a future PR, we could consider p/invoke into __system_property_get() and parse values. But we might want to reconsider the names of some of the system properties as they have debug.mono.* prefixes.

Hardcoding a default value is at least better, so it won't crash.

…ories()`

In a NativeAOT context, we don't have `libmonodroid.so` *at all*.

This change introduces a new `#if NATIVEAOT` block in `Logger.cs` to
avoid calling `monodroid_get_log_categories()` and using `Default |
Assembly` by default.

I also reworked the build, so that the `$(AndroidRuntime)` property is
defined in `Configuration.props`. Other projects can eventually use it
as-needed.

In a future PR, we could consider p/invoke into
`__system_property_get()` and parse values. But we might want to
reconsider the *names* of some of the system properties as they have
`debug.mono.*` prefixes.

Hardcoding a default value is at least *better*, so it won't crash.
Comment on lines +16 to +17
<DefineConstants Condition=" '$(AndroidRuntime)' == 'Mono' ">$(DefineConstants);JAVA_INTEROP;MONO</DefineConstants>
<DefineConstants Condition=" '$(AndroidRuntime)' == 'NativeAOT' ">$(DefineConstants);JAVA_INTEROP;NATIVEAOT</DefineConstants>
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…

@jonathanpeppers
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants