[build][native support] intoduced new native support.

This commit is contained in:
Vasily Levchenko
2020-12-25 11:55:10 +01:00
parent e031da6e70
commit 65dd798818
20 changed files with 778 additions and 469 deletions
@@ -1,88 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'kotlin'
apply plugin: 'c'
buildscript {
ext.rootBuildDirectory = file('../..')
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
dependencies {
classpath "org.jetbrains.kotlin:kotlin-stdlib:${project.bootstrapKotlinVersion}"
}
}
import org.jetbrains.kotlin.konan.target.ClangArgs
model {
tasks.compileCallbacksSharedLibraryCallbacksC {
dependsOn ":kotlin-native:dependencies:update"
}
components {
callbacks(NativeLibrarySpec) {
sources.c.source {
srcDir 'src/callbacks/c'
include '**/*.c'
}
binaries.all {
def host = rootProject.project(":kotlin-native").ext.hostName
def hostLibffiDir = rootProject.project(":kotlin-native").ext.get("${host}LibffiDir")
cCompiler.args hostPlatform.clang.hostCompilerArgsForJni
cCompiler.args "-I$hostLibffiDir/include"
linker.args "$hostLibffiDir/lib/libffi.a"
}
}
}
toolChains {
clang(Clang) {
eachPlatform {
cCompiler.withArguments(ClangArgs.&filterGradleNativeSoftwareFlags)
}
}
}
}
dependencies {
compile project(":kotlin-native:utilities:basic-utils")
compile project(":kotlin-stdlib")
compile project(":kotlin-reflect")
}
sourceSets.main.kotlin.srcDirs += "src/jvm/kotlin"
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xuse-experimental=kotlin.ExperimentalUnsignedTypes', '-Xuse-experimental=kotlin.Experimental',
'-Xopt-in=kotlin.RequiresOptIn', "-XXLanguage:+InlineClasses", "-Xskip-prerelease-check"]
allWarningsAsErrors=true
}
}
task nativelibs(type: Copy) {
dependsOn 'callbacksSharedLibrary'
from "$buildDir/libs/callbacks/shared/"
into "$buildDir/nativelibs/"
}
classes.dependsOn nativelibs
@@ -0,0 +1,93 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.gradle.plugins.tools.lib
import org.jetbrains.gradle.plugins.tools.solib
import org.jetbrains.kotlin.*
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.ByteArrayOutputStream
val kotlinVersion = project.bootstrapKotlinVersion
plugins {
`native`
`kotlin`
}
//apply plugin: 'c'
native {
val isWindows = PlatformInfo.isWindows()
val obj = if (isWindows) "obj" else "o"
val host = rootProject.project(":kotlin-native").extra["hostName"]
val hostLibffiDir = rootProject.project(":kotlin-native").extra["${host}LibffiDir"]
val cflags = mutableListOf("-I$hostLibffiDir/include",
*platformManager.hostPlatform.clang.hostCompilerArgsForJni)
if (!HostManager.hostIsMingw) {
cflags += "-fPIC"
}
suffixes {
(".c" to ".$obj") {
tool(*platformManager.hostPlatform.clang.clangC("").toTypedArray())
flags( *cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
}
}
sourceSet {
"callbacks" {
dir("src/callbacks/c")
}
}
val objSet = sourceSets["callbacks"]!!.transform(".c" to ".$obj")
target(solib("callbacks"), objSet) {
tool(*platformManager.hostPlatform.clang.clangCXX("").toTypedArray())
flags("-shared",
"-o",ruleOut(), *ruleInAll(),
"-L${project(":kotlin-native:libclangext").buildDir}",
"$hostLibffiDir/lib/libffi.a",
"-lclangext")
}
tasks.named(solib("callbacks")).configure {
dependsOn(":kotlin-native:libclangext:${lib("clangext")}")
}
}
dependencies {
implementation(project(":kotlin-native:utilities:basic-utils"))
implementation(project(":kotlin-stdlib"))
implementation(project(":kotlin-reflect"))
}
sourceSets.main.get().java.srcDir("src/jvm/kotlin")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = listOf("-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
"-Xuse-experimental=kotlin.Experimental",
"-Xopt-in=kotlin.RequiresOptIn",
"-XXLanguage:+InlineClasses",
"-Xskip-prerelease-check")
allWarningsAsErrors = true
}
}
val nativelibs = project.tasks.create<Copy>("nativelibs") {
dependsOn(solib("callbacks"))
from("$buildDir/")
into("$buildDir/nativelibs/")
}