Platform libs definitions for Android, small interop tweaks. (#804)

This commit is contained in:
Nikolay Igotti
2017-08-23 16:47:19 +03:00
committed by GitHub
parent 9667749b4e
commit 87a4fa9380
16 changed files with 152 additions and 33 deletions
@@ -64,6 +64,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
private sealed class DeclarationID {
data class USR(val usr: String) : DeclarationID()
object VaList : DeclarationID()
object VaListTag : DeclarationID()
object BuiltinVaList : DeclarationID()
}
@@ -105,6 +106,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
val spelling = getCursorSpelling(cursor)
return when (kind to spelling) {
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
else -> error(spelling)
}
@@ -388,7 +390,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
if (canonicalType.kind != CXType_Unexposed) {
convertType(canonicalType)
} else {
throw NotImplementedError()
UnsupportedType
}
}
}
@@ -142,9 +142,10 @@ private fun processCodeSnippet(
val kind = cursor.kind
when {
state == VisitorState.EXPECT_VARIABLE && kind == CXCursorKind.CXCursor_VarDecl -> {
state = VisitorState.EXPECT_VARIABLE_VALUE
val evalResult = clang_Cursor_Evaluate(cursor)
if (evalResult != null) {
state = VisitorState.EXPECT_VARIABLE_VALUE
try {
evalResultKind = clang_EvalResult_getKind(evalResult)
if (evalResultKind == CXEvalResultKind.CXEval_Float) {
@@ -153,6 +154,8 @@ private fun processCodeSnippet(
} finally {
clang_EvalResult_dispose(evalResult)
}
} else {
state = VisitorState.INVALID
}
CXChildVisitResult.CXChildVisit_Recurse
}
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.native.interop.gen
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",
"true", "try", "typealias", "val", "var", "when", "while"
)
@@ -26,22 +26,22 @@ interface DeclarationMapper {
val PrimitiveType.kotlinType: String
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.
is IntegerType -> when (this.size) {
1 -> "Byte"
2 -> "Short"
4 -> "Int"
8 -> "Long"
1 -> "kotlin.Byte"
2 -> "kotlin.Short"
4 -> "kotlin.Int"
8 -> "kotlin.Long"
else -> TODO(this.toString())
}
is FloatingType -> when (this.size) {
4 -> "Float"
8 -> "Double"
4 -> "kotlin.Float"
8 -> "kotlin.Double"
else -> TODO(this.toString())
}
@@ -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.
*/
enum class BridgedType(val kotlinType: String) {
BYTE("Byte"),
SHORT("Short"),
INT("Int"),
LONG("Long"),
FLOAT("Float"),
DOUBLE("Double"),
enum class BridgedType(val kotlinType: String, val convertor: String? = null) {
BYTE("kotlin.Byte", "toByte"),
SHORT("kotlin.Short", "toShort"),
INT("kotlin.Int", "toInt"),
LONG("kotlin.Long", "toLong"),
FLOAT("kotlin.Float", "toFloat"),
DOUBLE("kotlin.Double", "toDouble"),
NATIVE_PTR("NativePtr"),
OBJC_POINTER("NativePtr"),
VOID("Unit")
VOID("kotlin.Unit")
}
data class BridgeTypedKotlinValue(val type: BridgedType, val value: KotlinExpression)
@@ -316,7 +316,7 @@ class StubGenerator(
val signed = field.type.getUnderlyingIntegerType().isSigned
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)}")
@@ -626,10 +626,10 @@ class StubGenerator(
}
val narrowedValue: Number = when (unwrappedType.kotlinType) {
"Byte" -> value.toByte()
"Short" -> value.toShort()
"Int" -> value.toInt()
"Long" -> value
"kotlin.Byte" -> value.toByte()
"kotlin.Short" -> value.toShort()
"kotlin.Int" -> value.toInt()
"kotlin.Long" -> value
else -> return null
}
@@ -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)
if (flags == null) return emptyList()
return flags.replace("<sysrootDir>", targetSysRoot).split(' ')
@@ -263,8 +263,8 @@ private fun loadProperties(file: File?, substitutions: Map<String, String>): Pro
}
private fun Properties.storeProperties(file: File) {
file.outputStream().use {
this.store(it, null)
file.outputStream().use {
this.store(it, null)
}
}
@@ -303,7 +303,7 @@ private fun parseDefFile(file: File?, substitutions: Map<String, String>): Tripl
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() {
println("""
@@ -355,8 +355,8 @@ private fun processLib(konanHome: String,
return
}
val (config, manifestAddendProperties, defHeaderLines)
= parseDefFile(defFile, substitutions)
val (config, manifestAddendProperties, defHeaderLines)
= parseDefFile(defFile, substitutions)
val konanFileName = args["-properties"]?.single() ?:
"${konanHome}/konan/konan.properties"
@@ -369,7 +369,7 @@ private fun processLib(konanHome: String,
val llvmHome = konanProperties.getHostSpecific("llvmHome")!!
val llvmInstallPath = "$dependencies/$llvmHome"
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 generateShims = args["-shims"].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 excludedFunctions = config.getSpaceSeparated("excludedFunctions").toSet()
val fqParts = args["-pkg"]?.atMostOne()?.let {
val fqParts = (args["-pkg"]?.atMostOne() ?: config.getProperty("package"))?.let {
it.split('.')
} ?: defFile!!.name.split('.').reversed().drop(1)
@@ -459,7 +459,7 @@ private fun processLib(konanHome: String,
}
manifestAddend?.parentFile?.mkdirs()
manifestAddend ?.let { manifestAddendProperties.storeProperties(it) }
manifestAddend?.let { manifestAddendProperties.storeProperties(it) }
val workDir = defFile?.absoluteFile?.parentFile ?: File(userDir)
+61
View File
@@ -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;
};
+3
View File
@@ -0,0 +1,3 @@
package = platform.egl
headers = EGL/egl.h EGL/eglext.h EGL/eglplatform.h
linkerOpts = -lEGL
+3
View File
@@ -0,0 +1,3 @@
package = platform.gles
headers = GLES/gl.h GLES/glext.h GLES/glplatform.h
linkerOpts = -lGLESv1_CM
+3
View File
@@ -0,0 +1,3 @@
package = platform.gles2
headers = GLES2/gl2.h GLES2/gl2ext.h GLES2/gl2platform.h
linkerOpts = -lGLESv2
+3
View File
@@ -0,0 +1,3 @@
package = platform.gles3
headers = GLES3/gl3.h GLES3/gl3ext.h GLES3/gl3platform.h
linkerOpts = -lGLESv3
+4
View File
@@ -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
+3
View File
@@ -0,0 +1,3 @@
package = platform.omxal
headers = OMXAL/OpenMAXAL.h OMXAL/OpenMAXAL_Android.h OMXAL/OpenMAXAL_Platform.h
linkerOpts = -lOpenMAXAL
+30
View File
@@ -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;
}
+4
View File
@@ -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