Add basic support for Windows with mingw-w64
This commit is contained in:
committed by
SvyatoslavScherbina
parent
ed60732058
commit
d6b8b4fb0f
@@ -29,9 +29,6 @@ apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
|
||||
|
||||
apply plugin: 'c'
|
||||
|
||||
def javaHome = System.getProperty('java.home')
|
||||
def compilerArgsForJniIncludes = ["", "linux", "darwin"].collect { "-I$javaHome/../include/$it" } as String[]
|
||||
|
||||
model {
|
||||
components {
|
||||
clangstubs(NativeLibrarySpec) {
|
||||
@@ -40,12 +37,18 @@ model {
|
||||
}
|
||||
|
||||
binaries.all {
|
||||
cCompiler.args compilerArgsForJniIncludes
|
||||
cCompiler.args hostCompilerArgsForJni
|
||||
cCompiler.args "-I$llvmDir/include"
|
||||
}
|
||||
|
||||
binaries.withType(SharedLibraryBinarySpec) {
|
||||
linker.args "$llvmDir/lib/${System.mapLibraryName("clang")}"
|
||||
final String libclang
|
||||
if (isWindows()) {
|
||||
libclang = "bin/libclang.dll"
|
||||
} else {
|
||||
libclang = "lib/${System.mapLibraryName("clang")}"
|
||||
}
|
||||
linker.args "$llvmDir/$libclang"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,6 @@ buildscript {
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'c'
|
||||
|
||||
def javaHome = System.getProperty('java.home')
|
||||
def compilerArgsForJniIncludes = ["", "linux", "darwin"].collect { "-I$javaHome/../include/$it" } as String[]
|
||||
|
||||
model {
|
||||
components {
|
||||
callbacks(NativeLibrarySpec) {
|
||||
@@ -41,7 +38,7 @@ model {
|
||||
def host = rootProject.ext.host
|
||||
def hostLibffiDir = rootProject.ext.get("${host}LibffiDir")
|
||||
|
||||
cCompiler.args compilerArgsForJniIncludes
|
||||
cCompiler.args hostCompilerArgsForJni
|
||||
cCompiler.args "-I$hostLibffiDir/include"
|
||||
|
||||
linker.args "$hostLibffiDir/lib/libffi.a"
|
||||
|
||||
@@ -147,7 +147,7 @@ static JNIEnv* getCurrentEnv() {
|
||||
return env;
|
||||
}
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm_, void *reserved) {
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm_, void *reserved) {
|
||||
vm = vm_;
|
||||
return JNI_VERSION_1_1;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1277,7 +1277,7 @@ class StubGenerator(
|
||||
},
|
||||
|
||||
compilerArgs = configuration.library.compilerArgs + when (platform) {
|
||||
KotlinPlatform.JVM -> listOf("", "linux", "darwin").map {
|
||||
KotlinPlatform.JVM -> listOf("", "linux", "darwin", "win32").map {
|
||||
val javaHome = System.getProperty("java.home")
|
||||
"-I$javaHome/../include/$it"
|
||||
}
|
||||
|
||||
+16
-8
@@ -61,11 +61,11 @@ private fun parseArgs(args: Array<String>): Map<String, List<String>> {
|
||||
|
||||
private val host: String by lazy {
|
||||
val os = System.getProperty("os.name")
|
||||
when (os) {
|
||||
"Linux" -> "linux"
|
||||
"Windows" -> "win"
|
||||
"Mac OS X" -> "osx"
|
||||
"FreeBSD" -> "freebsd"
|
||||
when {
|
||||
os == "Linux" -> "linux"
|
||||
os.startsWith("Windows") -> "mingw"
|
||||
os == "Mac OS X" -> "osx"
|
||||
os == "FreeBSD" -> "freebsd"
|
||||
else -> {
|
||||
throw IllegalArgumentException("we don't know ${os} value")
|
||||
}
|
||||
@@ -87,7 +87,8 @@ private val knownTargets = mapOf(
|
||||
"iphone_sim" to "ios_sim",
|
||||
"ios_sim" to "ios_sim",
|
||||
"raspberrypi" to "raspberrypi",
|
||||
"android_arm32" to "android_arm32"
|
||||
"android_arm32" to "android_arm32",
|
||||
"mingw" to "mingw"
|
||||
)
|
||||
|
||||
|
||||
@@ -205,9 +206,13 @@ private fun Properties.defaultCompilerOpts(target: String, dependencies: String)
|
||||
val llvmHomeDir = getHostSpecific("llvmHome")!!
|
||||
val llvmHome = "$dependencies/$llvmHomeDir"
|
||||
|
||||
System.load("$llvmHome/lib/${System.mapLibraryName("clang")}")
|
||||
val libclang = when (host) {
|
||||
"mingw" -> "$llvmHome/bin/libclang.dll"
|
||||
else -> "$llvmHome/lib/${System.mapLibraryName("clang")}"
|
||||
}
|
||||
System.load(libclang)
|
||||
|
||||
val llvmVersion = getProperty("llvmVersion")!!
|
||||
val llvmVersion = getHostSpecific("llvmVersion")!!
|
||||
|
||||
// StubGenerator passes the arguments to libclang which
|
||||
// works not exactly the same way as the clang binary and
|
||||
@@ -234,6 +239,9 @@ private fun Properties.defaultCompilerOpts(target: String, dependencies: String)
|
||||
return archSelector + commonArgs + listOf(
|
||||
"-B$binDir", "--gcc-toolchain=$targetToolchain")
|
||||
}
|
||||
"mingw" -> {
|
||||
return archSelector + commonArgs + listOf("-B$targetSysRoot/bin")
|
||||
}
|
||||
else -> error("Unexpected target: ${target}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user