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

Allow for Custom Runtime Identifiers #97776

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

atlasapplications
Copy link

The C# export process assigns a runtime identifier based off predefined options depending on the exporting platform and architecture. This makes sense almost all the time but I found a case where this creates a limitation. NativeAOT for android requires the linux-bionic-arm64 runtime identifier which is not what Godot assigns (it uses android-arm64). This can be solved by simply creating an override in the export settings for advanced users that want to try a custom runtime identifier. The default functionality is untouched if the option is left blank.

Resolves #97775

The C# export process assigns a runtime identifier based off predefined options depending on the exporting platform and architecture. This makes sense almost all the time but I found a case where this creates a limitation. NativeAOT for android requires the linux-bionic-arm64 runtime identifier which is not what Godot assigns (it uses android-arm64). This can be solved by simply creating an override in the export settings for advanced users that want to try a custom runtime identifier. The default functionality is untouched if the option is left blank.
@atlasapplications
Copy link
Author

For those interested in getting NativeAOT up and going for Android I've done the work of testing and here are the modifications you'll need to make to get it working. (This is using windows) Become familiar with the build system for Android as you will need to set environment variables such as ANDROID_HOME to the default android sdk path and ANDROID_NDK_HOME to the specified ndk that Godot supports. (Don't worry, that's about it)

With that, here's what should be added to your Godot's .csproj file

<PropertyGroup>
    <PublishAOT Condition=" '$(GodotTargetPlatform)' == 'android' ">true</PublishAOT>
    <DisableUnsupportedError Condition=" '$(GodotTargetPlatform)' == 'android' ">true</DisableUnsupportedError
    <PublishAotUsingRuntimePack Condition=" '$(GodotTargetPlatform)' == 'android' ">true</PublishAotUsingRuntimePack>
</PropertyGroup>
<ItemGroup>
    <TrimmerRootAssembly Include="GodotSharp" />
    <TrimmerRootAssembly Include="$(TargetName)" />
</ItemGroup>

Of course, this is in addition to setting the target framework to net8.0 since that is a requirement for NativeAOT.

Then, in the export settings for android (this is what this PR adds) go to the bottom under dotnet where it says runtime identifier and put linux-bionic-arm64.

And if you set up the ndk paths correctly, it should just work! (Please note that the NativeAOT feature itself is experimental within the dotnet runtime)

@raulsntos
Copy link
Member

I don't think you should be able to override the runtime identifier. When exporting, Godot will use the template for the target platform and architectures, if you override the runtime identifier you may not match the template. For example, if you are exporting to Android but override the runtime identifier with win-x64.

And specifically about Android, since the runtime identifier also contains the architecture, if you override it with linux-bionic-arm64 as you mentioned. What if you had other ABIs enabled? Like x86_32 and arm32. Godot will include those in the APK but they will not work, because you are building the C# project with the runtime identifier linux-bionic-arm64 for all the ABIs.

I would prefer a boolean option only available to Android exports to enable AOT which would automatically pick the correct runtime identifier (i.e.: pick linux-bionic when true, and android when false which should be the default).

@atlasapplications
Copy link
Author

I don't think you should be able to override the runtime identifier. When exporting, Godot will use the template for the target platform and architectures, if you override the runtime identifier you may not match the template. For example, if you are exporting to Android but override the runtime identifier with win-x64.

And specifically about Android, since the runtime identifier also contains the architecture, if you override it with linux-bionic-arm64 as you mentioned. What if you had other ABIs enabled? Like x86_32 and arm32. Godot will include those in the APK but they will not work, because you are building the C# project with the runtime identifier linux-bionic-arm64 for all the ABIs.

I would prefer a boolean option only available to Android exports to enable AOT which would automatically pick the correct runtime identifier (i.e.: pick linux-bionic when true, and android when false which should be the default).

I see what you mean, overriding the runtime identifier can open up the possibility of incompatible export settings. One reason I approached it this way is because it seemed unclear if in a future .NET version the appropriate RID would be different. So, I thought this would provide more flexibility with setting the right RID as .NET changes. I agree it's an advanced use case.

For your approach, since NativeAOT only supports x64 and arm64 on Android, would you recommend a boolean that only becomes checkable when those architectures are the only ones selected, or a boolean for each supported architecture under the Architectures category?

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

Successfully merging this pull request may close these issues.

Unable to Export for NativeAOT on Android
3 participants