Skip to content

Conversation

natario1
Copy link
Contributor

As discussed in https://youtrack.jetbrains.com/issue/KT-49144 , this PR enables Android Native executable { } binaries to be actual executables. This is especially important for tests.

Context

Android Native executables are currently built as shared libraries with a Konan_main entry point, whose signature is specific to Android NDK types ( https://developer.android.com/ndk/reference/group/native-activity#anativeactivity_createfunc ). It can't be executed from command line of course. This PR preserves the current behavior, but adds:

  • a new BinaryOption, either AndroidProgramType.Standalone (desired long-term default) or AndroidProgramType.NativeActivity (current behavior). When standalone is used, we'll build a real command-line executable.
  • a new Konan_main_standalone function in the Android runtime, to be used for real executables. Ideally this should be called Konan_main and we should rename the NDK-based entry point, but that would be a breaking change.
  • compiler warning encouraging users to be explicit about their choice as the default behavior is going to change.

I have verified that both behaviors (standalone vs. nativeActivity) work as expected.

@sbogolepov sbogolepov self-requested a review October 23, 2021 04:21
@sbogolepov
Copy link
Contributor

Thank you for the PR! Some thoughts:

  1. We need to use proper stderr and stdout in the standalone mode. This can be achieved by adding a so called compiler constant: a constant value that is set during compilation time and used inside C++ runtime code. See CompilerConstants.cpp, CompilerConstants.hpp and how compiler sets them. Places that should check the new constant: 1, 2, and 3.
  2. Standalone executables still use ".so" extension, which is wrong. Probably, it is possible to fix it without breaking anything, but it is not trivial and will make PR much bigger, so let's fix it later.

@natario1 natario1 force-pushed the feature/android_programs branch from 535923b to c05f65d Compare October 25, 2021 09:54
@sbogolepov
Copy link
Contributor

Nice work! 👍

@sbogolepov sbogolepov merged commit c92e34c into JetBrains:master Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants