Platform libs definitions for Android, small interop tweaks. (#804)
This commit is contained in:
+3
-1
@@ -64,6 +64,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
|
|
||||||
private sealed class DeclarationID {
|
private sealed class DeclarationID {
|
||||||
data class USR(val usr: String) : DeclarationID()
|
data class USR(val usr: String) : DeclarationID()
|
||||||
|
object VaList : DeclarationID()
|
||||||
object VaListTag : DeclarationID()
|
object VaListTag : DeclarationID()
|
||||||
object BuiltinVaList : DeclarationID()
|
object BuiltinVaList : DeclarationID()
|
||||||
}
|
}
|
||||||
@@ -105,6 +106,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
val spelling = getCursorSpelling(cursor)
|
val spelling = getCursorSpelling(cursor)
|
||||||
return when (kind to spelling) {
|
return when (kind to spelling) {
|
||||||
CXCursorKind.CXCursor_StructDecl to "__va_list_tag" -> DeclarationID.VaListTag
|
CXCursorKind.CXCursor_StructDecl to "__va_list_tag" -> DeclarationID.VaListTag
|
||||||
|
CXCursorKind.CXCursor_StructDecl to "__va_list" -> DeclarationID.VaList
|
||||||
CXCursorKind.CXCursor_TypedefDecl to "__builtin_va_list" -> DeclarationID.BuiltinVaList
|
CXCursorKind.CXCursor_TypedefDecl to "__builtin_va_list" -> DeclarationID.BuiltinVaList
|
||||||
else -> error(spelling)
|
else -> error(spelling)
|
||||||
}
|
}
|
||||||
@@ -388,7 +390,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
if (canonicalType.kind != CXType_Unexposed) {
|
if (canonicalType.kind != CXType_Unexposed) {
|
||||||
convertType(canonicalType)
|
convertType(canonicalType)
|
||||||
} else {
|
} else {
|
||||||
throw NotImplementedError()
|
UnsupportedType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -142,9 +142,10 @@ private fun processCodeSnippet(
|
|||||||
val kind = cursor.kind
|
val kind = cursor.kind
|
||||||
when {
|
when {
|
||||||
state == VisitorState.EXPECT_VARIABLE && kind == CXCursorKind.CXCursor_VarDecl -> {
|
state == VisitorState.EXPECT_VARIABLE && kind == CXCursorKind.CXCursor_VarDecl -> {
|
||||||
state = VisitorState.EXPECT_VARIABLE_VALUE
|
|
||||||
val evalResult = clang_Cursor_Evaluate(cursor)
|
val evalResult = clang_Cursor_Evaluate(cursor)
|
||||||
if (evalResult != null) {
|
if (evalResult != null) {
|
||||||
|
state = VisitorState.EXPECT_VARIABLE_VALUE
|
||||||
try {
|
try {
|
||||||
evalResultKind = clang_EvalResult_getKind(evalResult)
|
evalResultKind = clang_EvalResult_getKind(evalResult)
|
||||||
if (evalResultKind == CXEvalResultKind.CXEval_Float) {
|
if (evalResultKind == CXEvalResultKind.CXEval_Float) {
|
||||||
@@ -153,6 +154,8 @@ private fun processCodeSnippet(
|
|||||||
} finally {
|
} finally {
|
||||||
clang_EvalResult_dispose(evalResult)
|
clang_EvalResult_dispose(evalResult)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
state = VisitorState.INVALID
|
||||||
}
|
}
|
||||||
CXChildVisitResult.CXChildVisit_Recurse
|
CXChildVisitResult.CXChildVisit_Recurse
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.native.interop.gen
|
package org.jetbrains.kotlin.native.interop.gen
|
||||||
|
|
||||||
val kotlinKeywords = setOf(
|
val kotlinKeywords = setOf(
|
||||||
"as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in",
|
"as", "break", "class", "continue", "do", "dynamic", "else", "false", "for", "fun", "if", "in",
|
||||||
"interface", "is", "null", "object", "package", "return", "super", "this", "throw",
|
"interface", "is", "null", "object", "package", "return", "super", "this", "throw",
|
||||||
"true", "try", "typealias", "val", "var", "when", "while"
|
"true", "try", "typealias", "val", "var", "when", "while"
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-8
@@ -26,22 +26,22 @@ interface DeclarationMapper {
|
|||||||
|
|
||||||
val PrimitiveType.kotlinType: String
|
val PrimitiveType.kotlinType: String
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
is CharType -> "Byte"
|
is CharType -> "kotlin.Byte"
|
||||||
|
|
||||||
is BoolType -> "Boolean"
|
is BoolType -> "kotlin.Boolean"
|
||||||
|
|
||||||
// TODO: C primitive types should probably be generated as type aliases for Kotlin types.
|
// TODO: C primitive types should probably be generated as type aliases for Kotlin types.
|
||||||
is IntegerType -> when (this.size) {
|
is IntegerType -> when (this.size) {
|
||||||
1 -> "Byte"
|
1 -> "kotlin.Byte"
|
||||||
2 -> "Short"
|
2 -> "kotlin.Short"
|
||||||
4 -> "Int"
|
4 -> "kotlin.Int"
|
||||||
8 -> "Long"
|
8 -> "kotlin.Long"
|
||||||
else -> TODO(this.toString())
|
else -> TODO(this.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
is FloatingType -> when (this.size) {
|
is FloatingType -> when (this.size) {
|
||||||
4 -> "Float"
|
4 -> "kotlin.Float"
|
||||||
8 -> "Double"
|
8 -> "kotlin.Double"
|
||||||
else -> TODO(this.toString())
|
else -> TODO(this.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -19,16 +19,16 @@ package org.jetbrains.kotlin.native.interop.gen
|
|||||||
/**
|
/**
|
||||||
* The type which has exact counterparts on both Kotlin and native side and can be directly passed through bridges.
|
* The type which has exact counterparts on both Kotlin and native side and can be directly passed through bridges.
|
||||||
*/
|
*/
|
||||||
enum class BridgedType(val kotlinType: String) {
|
enum class BridgedType(val kotlinType: String, val convertor: String? = null) {
|
||||||
BYTE("Byte"),
|
BYTE("kotlin.Byte", "toByte"),
|
||||||
SHORT("Short"),
|
SHORT("kotlin.Short", "toShort"),
|
||||||
INT("Int"),
|
INT("kotlin.Int", "toInt"),
|
||||||
LONG("Long"),
|
LONG("kotlin.Long", "toLong"),
|
||||||
FLOAT("Float"),
|
FLOAT("kotlin.Float", "toFloat"),
|
||||||
DOUBLE("Double"),
|
DOUBLE("kotlin.Double", "toDouble"),
|
||||||
NATIVE_PTR("NativePtr"),
|
NATIVE_PTR("NativePtr"),
|
||||||
OBJC_POINTER("NativePtr"),
|
OBJC_POINTER("NativePtr"),
|
||||||
VOID("Unit")
|
VOID("kotlin.Unit")
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BridgeTypedKotlinValue(val type: BridgedType, val value: KotlinExpression)
|
data class BridgeTypedKotlinValue(val type: BridgedType, val value: KotlinExpression)
|
||||||
|
|||||||
+5
-5
@@ -316,7 +316,7 @@ class StubGenerator(
|
|||||||
val signed = field.type.getUnderlyingIntegerType().isSigned
|
val signed = field.type.getUnderlyingIntegerType().isSigned
|
||||||
|
|
||||||
val readBitsExpr =
|
val readBitsExpr =
|
||||||
"readBits(this.rawPtr, ${field.offset}, ${field.size}, $signed).to${rawType.kotlinType}()"
|
"readBits(this.rawPtr, ${field.offset}, ${field.size}, $signed).${rawType.convertor!!}()"
|
||||||
|
|
||||||
out(" get() = ${typeInfo.argFromBridged(readBitsExpr)}")
|
out(" get() = ${typeInfo.argFromBridged(readBitsExpr)}")
|
||||||
|
|
||||||
@@ -626,10 +626,10 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val narrowedValue: Number = when (unwrappedType.kotlinType) {
|
val narrowedValue: Number = when (unwrappedType.kotlinType) {
|
||||||
"Byte" -> value.toByte()
|
"kotlin.Byte" -> value.toByte()
|
||||||
"Short" -> value.toShort()
|
"kotlin.Short" -> value.toShort()
|
||||||
"Int" -> value.toInt()
|
"kotlin.Int" -> value.toInt()
|
||||||
"Long" -> value
|
"kotlin.Long" -> value
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -199,7 +199,7 @@ private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Properties.getClangFlags(target: String, targetSysRoot: String) : List<String> {
|
private fun Properties.getClangFlags(target: String, targetSysRoot: String): List<String> {
|
||||||
val flags = getTargetSpecific("clangFlags", target)
|
val flags = getTargetSpecific("clangFlags", target)
|
||||||
if (flags == null) return emptyList()
|
if (flags == null) return emptyList()
|
||||||
return flags.replace("<sysrootDir>", targetSysRoot).split(' ')
|
return flags.replace("<sysrootDir>", targetSysRoot).split(' ')
|
||||||
@@ -303,7 +303,7 @@ private fun parseDefFile(file: File?, substitutions: Map<String, String>): Tripl
|
|||||||
return Triple(properties, manifestAddendProperties, headerLines)
|
return Triple(properties, manifestAddendProperties, headerLines)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Properties.duplicate() = Properties().apply{ putAll(this@duplicate) }
|
private fun Properties.duplicate() = Properties().apply { putAll(this@duplicate) }
|
||||||
|
|
||||||
private fun usage() {
|
private fun usage() {
|
||||||
println("""
|
println("""
|
||||||
@@ -356,7 +356,7 @@ private fun processLib(konanHome: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val (config, manifestAddendProperties, defHeaderLines)
|
val (config, manifestAddendProperties, defHeaderLines)
|
||||||
= parseDefFile(defFile, substitutions)
|
= parseDefFile(defFile, substitutions)
|
||||||
|
|
||||||
val konanFileName = args["-properties"]?.single() ?:
|
val konanFileName = args["-properties"]?.single() ?:
|
||||||
"${konanHome}/konan/konan.properties"
|
"${konanHome}/konan/konan.properties"
|
||||||
@@ -369,7 +369,7 @@ private fun processLib(konanHome: String,
|
|||||||
val llvmHome = konanProperties.getHostSpecific("llvmHome")!!
|
val llvmHome = konanProperties.getHostSpecific("llvmHome")!!
|
||||||
val llvmInstallPath = "$dependencies/$llvmHome"
|
val llvmInstallPath = "$dependencies/$llvmHome"
|
||||||
val additionalHeaders = args["-h"].orEmpty()
|
val additionalHeaders = args["-h"].orEmpty()
|
||||||
val additionalCompilerOpts = args["-copt"].orEmpty()+ args["-compilerOpts"].orEmpty()
|
val additionalCompilerOpts = args["-copt"].orEmpty() + args["-compilerOpts"].orEmpty()
|
||||||
val additionalLinkerOpts = args["-lopt"].orEmpty() + args["-linkerOpts"].orEmpty()
|
val additionalLinkerOpts = args["-lopt"].orEmpty() + args["-linkerOpts"].orEmpty()
|
||||||
val generateShims = args["-shims"].isTrue()
|
val generateShims = args["-shims"].isTrue()
|
||||||
val verbose = args["-verbose"].isTrue()
|
val verbose = args["-verbose"].isTrue()
|
||||||
@@ -403,7 +403,7 @@ private fun processLib(konanHome: String,
|
|||||||
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
|
val linker = args["-linker"]?.atMostOne() ?: config.getProperty("linker") ?: "clang"
|
||||||
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
|
val excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
|
||||||
|
|
||||||
val fqParts = args["-pkg"]?.atMostOne()?.let {
|
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
|
||||||
it.split('.')
|
it.split('.')
|
||||||
} ?: defFile!!.name.split('.').reversed().drop(1)
|
} ?: defFile!!.name.split('.').reversed().drop(1)
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ private fun processLib(konanHome: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
manifestAddend?.parentFile?.mkdirs()
|
manifestAddend?.parentFile?.mkdirs()
|
||||||
manifestAddend ?.let { manifestAddendProperties.storeProperties(it) }
|
manifestAddend?.let { manifestAddendProperties.storeProperties(it) }
|
||||||
|
|
||||||
val workDir = defFile?.absoluteFile?.parentFile ?: File(userDir)
|
val workDir = defFile?.absoluteFile?.parentFile ?: File(userDir)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package = platform.android
|
||||||
|
headers = android/api-level.h android/asset_manager.h android/asset_manager_jni.h android/bitmap.h \
|
||||||
|
android/configuration.h android/dlext.h android/input.h android/keycodes.h android/log.h \
|
||||||
|
android/looper.h android/native_activity.h android/native_window.h android/native_window_jni.h \
|
||||||
|
android/obb.h android/rect.h android/sensor.h android/storage_manager.h android/tts.h \
|
||||||
|
android/window.h
|
||||||
|
|
||||||
|
linkerOpts = -landroid -llog -ljnigraphics
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
struct NativeActivityState {
|
||||||
|
struct ANativeActivity* activity;
|
||||||
|
void* savedState;
|
||||||
|
size_t savedStateSize;
|
||||||
|
struct ALooper* looper;
|
||||||
|
};
|
||||||
|
|
||||||
|
void getNativeActivityState(struct NativeActivityState* state);
|
||||||
|
|
||||||
|
void notifySysEventProcessed();
|
||||||
|
|
||||||
|
#define LOOPER_ID_SYS 1
|
||||||
|
|
||||||
|
typedef enum NativeActivityEventKind {
|
||||||
|
UNKNOWN,
|
||||||
|
DESTROY,
|
||||||
|
START,
|
||||||
|
RESUME,
|
||||||
|
SAVE_INSTANCE_STATE,
|
||||||
|
PAUSE,
|
||||||
|
STOP,
|
||||||
|
CONFIGURATION_CHANGED,
|
||||||
|
LOW_MEMORY,
|
||||||
|
WINDOW_GAINED_FOCUS,
|
||||||
|
WINDOW_LOST_FOCUS,
|
||||||
|
NATIVE_WINDOW_CREATED,
|
||||||
|
NATIVE_WINDOW_DESTROYED,
|
||||||
|
INPUT_QUEUE_CREATED,
|
||||||
|
INPUT_QUEUE_DESTROYED
|
||||||
|
} NativeActivityEventKind;
|
||||||
|
|
||||||
|
struct NativeActivityEvent {
|
||||||
|
NativeActivityEventKind eventKind;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NativeActivitySaveStateEvent {
|
||||||
|
NativeActivityEventKind eventKind;
|
||||||
|
void* savedState;
|
||||||
|
size_t savedStateSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NativeActivityWindowEvent {
|
||||||
|
NativeActivityEventKind eventKind;
|
||||||
|
struct ANativeWindow* window;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NativeActivityQueueEvent {
|
||||||
|
NativeActivityEventKind eventKind;
|
||||||
|
struct AInputQueue* queue;
|
||||||
|
};
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package = platform.egl
|
||||||
|
headers = EGL/egl.h EGL/eglext.h EGL/eglplatform.h
|
||||||
|
linkerOpts = -lEGL
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package = platform.gles
|
||||||
|
headers = GLES/gl.h GLES/glext.h GLES/glplatform.h
|
||||||
|
linkerOpts = -lGLESv1_CM
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package = platform.gles2
|
||||||
|
headers = GLES2/gl2.h GLES2/gl2ext.h GLES2/gl2platform.h
|
||||||
|
linkerOpts = -lGLESv2
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package = platform.gles3
|
||||||
|
headers = GLES3/gl3.h GLES3/gl3ext.h GLES3/gl3platform.h
|
||||||
|
linkerOpts = -lGLESv3
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package = platform.media
|
||||||
|
headers = media/NdkMediaCodec.h media/NdkMediaCrypto.h media/NdkMediaDrm.h media/NdkMediaError.h \
|
||||||
|
media/NdkMediaExtractor.h media/NdkMediaFormat.h media/NdkMediaMuxer.h
|
||||||
|
linkerOpts = -lmediandk
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package = platform.omxal
|
||||||
|
headers = OMXAL/OpenMAXAL.h OMXAL/OpenMAXAL_Android.h OMXAL/OpenMAXAL_Platform.h
|
||||||
|
linkerOpts = -lOpenMAXAL
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package = platform.posix
|
||||||
|
headers = alloca.h ar.h assert.h byteswap.h complex.h dirent.h dlfcn.h elf.h endian.h err.h errno.h fcntl.h \
|
||||||
|
features.h fenv.h fnmatch.h fts.h ftw.h getopt.h grp.h inttypes.h jni.h lastlog.h libgen.h limits.h \
|
||||||
|
link.h locale.h malloc.h math.h memory.h mntent.h netdb.h nsswitch.h pathconf.h paths.h poll.h \
|
||||||
|
pthread.h pwd.h regex.h resolv.h sched.h search.h semaphore.h setjmp.h sgtty.h signal.h \
|
||||||
|
stdatomic.h stdint.h stdio.h stdlib.h string.h strings.h syslog.h termio.h termios.h thread_db.h \
|
||||||
|
time.h time64.h uchar.h ucontext.h unistd.h util.h utime.h utmp.h wchar.h wctype.h xlocale.h \
|
||||||
|
zconf.h zlib.h \
|
||||||
|
sys/epoll.h sys/inotify.h sys/ioctl.h sys/ipc.h sys/klog.h sys/mman.h sys/poll.h sys/ptrace.h \
|
||||||
|
sys/queue.h sys/select.h sys/sendfile.h sys/shm.h sys/stat.h sys/sysconf.h sys/sysinfo.h \
|
||||||
|
sys/syslimits.h sys/time.h sys/times.h sys/utime.h sys/wait.h \
|
||||||
|
net/ethernet.h net/if.h net/if_arp.h net/if_ether.h net/if_packet.h net/if_types.h net/route.h \
|
||||||
|
netinet/ether.h netinet/icmp6.h netinet/if_ether.h netinet/in.h netinet/in6.h netinet/in_systm.h \
|
||||||
|
netinet/ip.h netinet/ip6.h netinet/ip_icmp.h netinet/tcp.h netinet/udp.h \
|
||||||
|
netpacket/packet.h
|
||||||
|
|
||||||
|
linkerOpts = -ldl -lz
|
||||||
|
|
||||||
|
---
|
||||||
|
// cinterop -target android_arm32 -def klib/src/platform/android/posix.def -o platform.posix.klib
|
||||||
|
|
||||||
|
// Wrapper to access errno variable.
|
||||||
|
static int posix_errno() {
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper to access h_errno variable.
|
||||||
|
static int posix_h_errno() {
|
||||||
|
return h_errno;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package = platform.sles
|
||||||
|
headers = SLES//OpenSLES.h SLES/OpenSLES_Android.h SLES/OpenSLES_AndroidConfiguration.h \
|
||||||
|
SLES/OpenSLES_AndroidMetadata.h SLES/OpenSLES_Platform.h
|
||||||
|
linkerOpts = -lOpenSLES
|
||||||
Reference in New Issue
Block a user