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

[Android] Minimal (and quick) set of changes to make CoreCLR host on Android work #112705

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

grendello
Copy link
Contributor

This is a draft set of minimal changes required to make dotnet/android#9572 (the .NET for Android CoreCLR host) work with standard .NET for Android applications.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 19, 2025
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@lewing
Copy link
Member

lewing commented Feb 19, 2025

/azp run runtime

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AaronRobinsonMSFT
Copy link
Member

@grendello I think a bunch of these changes make sense to me, for example, a bunch of the bundling logic. My pushback would be either we are doing something quick and dirty or we are chasing optimizations, not both. For example coreclr_initialize seems to be just fine, but we don't want to have the other side convert to UTF-8, why not? Would that make composition harder in some way? That is the existing API and we should keep that for now to get things up.

I would change the android side to conform, where possible, to existing APIs for now and put a bunch of the cost there.

@jkotas
Copy link
Member

jkotas commented Feb 19, 2025

This change was incorrectly merged with main and a lot of unrelated commits from main are showing up as part of the delta. Could you please rebase against main and force push so that the delta is reviewable?

@grendello
Copy link
Contributor Author

This change was incorrectly merged with main and a lot of unrelated commits from main are showing up as part of the delta. Could you please rebase against main and force push so that the delta is reviewable?

I use git merge, which is the correct way of tracking changes, because it doesn't rewrite history like git rebase does, but sure, I can rebase.

@grendello
Copy link
Contributor Author

@grendello I think a bunch of these changes make sense to me, for example, a bunch of the bundling logic. My pushback would be either we are doing something quick and dirty or we are chasing optimizations, not both. For example coreclr_initialize seems to be just fine, but we don't want to have the other side convert to UTF-8, why not? Would that make composition harder in some way? That is the existing API and we should keep that for now to get things up.

Using UTF-8 strings on the Android side is easy and bears no costs for us, I can make the change without any effort. This is not the only issue with coreclr_initialize, though, and I'm going to push back against using the pointer-to-string-to-pointer conversion (as I did years ago when the same approach was suggested for MonoVM).

I would change the android side to conform, where possible, to existing APIs for now and put a bunch of the cost there.

👍

@grendello grendello force-pushed the dev/grendel/android-clr-host-local branch 2 times, most recently from ff6a948 to b285800 Compare February 20, 2025 10:02

if (m_probe != nullptr)
{
assemblyFound = m_probe(utf8Path, &loc.Offset, &fileSize, &compressedSize);
Copy link
Member

Choose a reason for hiding this comment

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

This is a slight change in the existing behavior. Currently the existing probe is defined as returning bool, but the code ignored it, now it doesn't. Given that we don't really expose this probe as an external API it's probably OK, but we should make it a concious decision.

Copy link
Member

Choose a reason for hiding this comment

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

Made / documented this to be an explicit check - the outs aren't used if the probe returns false.

@@ -51,6 +51,12 @@ struct host_runtime_contract
const void* (HOST_CONTRACT_CALLTYPE* pinvoke_override)(
const char* library_name,
const char* entry_point_name);

// Probe the host for `path`. Sets pointer to data start and its size, if found.
bool(HOST_CONTRACT_CALLTYPE* external_assembly_probe)(
Copy link
Member

Choose a reason for hiding this comment

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

@grendello I moved this to the end of the struct to keep the existing order. I don't think this should require updating your changes in dotnet/android, since they use designators.

Comment on lines 879 to 881
#if defined(TARGET_ANDROID)
m_hFile = GetData(nullptr);
#else
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#if defined(TARGET_ANDROID)
m_hFile = GetData(nullptr);
#else

If the GetFileHandle is still called after the other changes. fix the caller instead of this hack?

@@ -64,6 +65,13 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative)
pathBuffer.SetAndConvertToUTF8(path.GetUnicode());
LPCSTR utf8Path(pathBuffer.GetUTF8());

#if defined(TARGET_ANDROID)
// On Android we always strip away the assembly path, if any
Copy link
Member

Choose a reason for hiding this comment

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

@grendello Thoughts on doing this stripping on the Android host side instead? For the runtime, I think it would make more sense to just pass the raw path to external_assembly_probe.

@@ -383,6 +383,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_LogToConsole, W("LogToConsole"), 0 , "Writes t
CONFIG_DWORD_INFO(INTERNAL_LogToDebugger, W("LogToDebugger"), 0 , "Writes the CLR log to debugger (OutputDebugStringA).")
CONFIG_DWORD_INFO(INTERNAL_LogToFile, W("LogToFile"), 0 , "Writes the CLR log to a file.")
CONFIG_DWORD_INFO(INTERNAL_LogWithPid, W("LogWithPid"), FALSE, "Appends pid to filename for the CLR log.")
CONFIG_DWORD_INFO(INTERNAL_LogToAndroid, W("LogToAndroid"), 0 , "Writes the CLR log to android logcat")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed. Given the conversations about Android, we are really printing to the "console". I'm removing this and Android scenarios should reuse LogToConsole.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants