2882e6fab7
* Update build to Kotlin 1.1.0 * Add heuristics and options for selecting C enum interop binding style Also do some refactoring. * Add ':Interop:Indexer:updatePrebuilt' Gradle task * Update Interop/Indexer/prebuilt
233 lines
5.9 KiB
Groovy
233 lines
5.9 KiB
Groovy
//ant.importBuild 'backend.native/kotlin-ir/build.xml'
|
|
|
|
defaultTasks 'clean', 'demo'
|
|
|
|
if (new File("$project.rootDir/local.properties").exists()) {
|
|
Properties props = new Properties()
|
|
props.load(new FileInputStream("$project.rootDir/local.properties"))
|
|
props.each {prop -> project.ext.set(prop.key, prop.value)}
|
|
}
|
|
|
|
convention.plugins.platformInfo = new PlatformInfo()
|
|
|
|
allprojects {
|
|
if (path != ":dependencies") {
|
|
evaluationDependsOn(":dependencies")
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
ext.clangPath = ["$llvmDir/bin"]
|
|
ext.clangArgs = []
|
|
ext.targetArgs = [:]
|
|
final String binDir
|
|
|
|
if (isLinux()) {
|
|
ext.targetArgs <<
|
|
["host": ["--sysroot=${gccToolchainDir}/${gnuTriplet}/sysroot"]]
|
|
} else {
|
|
ext.targetArgs <<
|
|
["host":
|
|
["--sysroot=$hostSysrootDir", "-mmacosx-version-min=$minMacOsVersion"],
|
|
"iphone":
|
|
["-stdlib=libc++", "-arch", "arm64", "-isysroot", "$iphoneSysrootDir"],
|
|
// TODO: re-enable after simulator sysroot is available in the dependencies
|
|
// "iphone_sim":
|
|
// ["-stdlib=libc++", "-isysroot", "$iphoneSimSysrootDir"],
|
|
]
|
|
}
|
|
ext.targetList = ext.targetArgs.keySet() as List
|
|
|
|
if (isLinux()) {
|
|
binDir = "$gccToolchainDir/$gnuTriplet/bin"
|
|
ext.clangArgs.addAll([
|
|
"--gcc-toolchain=$gccToolchainDir",
|
|
"-L$llvmDir/lib"
|
|
])
|
|
} else {
|
|
binDir = "$hostSysrootDir/usr/bin"
|
|
}
|
|
ext.clangArgs << "-B$binDir"
|
|
ext.hostClangArgs = ext.clangArgs.clone()
|
|
ext.hostClangArgs.addAll(ext.targetArgs['host'])
|
|
|
|
ext.clangPath << binDir
|
|
ext.jvmArgs = ["-ea"]
|
|
ext.globalArgs = project.hasProperty("konanc_flags") ? ext.konanc_flags.split(' ') : []
|
|
|
|
convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project)
|
|
|
|
plugins.withType(NativeComponentPlugin) {
|
|
model {
|
|
toolChains {
|
|
clang(Clang) {
|
|
clangPath.each {
|
|
path it
|
|
}
|
|
|
|
eachPlatform { // TODO: will not work when cross-compiling
|
|
[cCompiler, cppCompiler, linker].each {
|
|
it.withArguments { it.addAll(hostClangArgs) }
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class PlatformInfo {
|
|
private final String osName = System.properties['os.name']
|
|
private final String osArch = System.properties['os.arch']
|
|
|
|
boolean isMac() {
|
|
return osName == 'Mac OS X'
|
|
}
|
|
|
|
boolean isLinux() {
|
|
return osName == 'Linux'
|
|
}
|
|
|
|
boolean isAmd64() {
|
|
return osArch in ['x86_64', 'amd64']
|
|
}
|
|
|
|
String getGnuTriplet() {
|
|
if (isLinux() && isAmd64()) {
|
|
return "x86_64-unknown-linux-gnu"
|
|
} else {
|
|
throw unsupportedPlatformException()
|
|
}
|
|
}
|
|
|
|
Throwable unsupportedPlatformException() {
|
|
return new Error("unsupported platform: $osName/$osArch")
|
|
}
|
|
}
|
|
|
|
task dist_compiler(type: Copy) {
|
|
dependsOn ':backend.native:jars'
|
|
|
|
destinationDir file('dist')
|
|
|
|
from(project(':backend.native').file('build/libs')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project('Interop').file('Runtime/build/libs')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project('Interop').file('Indexer/build/libs')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project('Interop').file('StubGenerator/build/libs')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project(':backend.native').file('build/external_jars')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project(':backend.native').file('build/nativelibs')) {
|
|
into('konan/nativelib')
|
|
}
|
|
|
|
from(project(':Interop').file('Indexer/build/nativelibs')) {
|
|
into('konan/nativelib')
|
|
}
|
|
|
|
from(project(':Interop').file('Runtime/build/nativelibs')) {
|
|
into('konan/nativelib')
|
|
}
|
|
|
|
from(file('cmd')) {
|
|
fileMode(0755)
|
|
include('konanc')
|
|
include('kotlinc-native')
|
|
include('interop')
|
|
into('bin')
|
|
}
|
|
|
|
from(project(':backend.native').file('konan.properties')) {
|
|
into('konan')
|
|
}
|
|
|
|
from("$llvmDir/lib") {
|
|
into('konan/nativelib')
|
|
include '**/libclang.*'
|
|
includeEmptyDirs = false
|
|
}
|
|
|
|
doLast {
|
|
// MacOS System Integrity Protection strips DYLD_LIBRARY_PATH from
|
|
// environment of all the binaries residing in /bin /usr/bin etc.
|
|
// That means /usr/bin/java can't use DYLD_LIBRARY_PATH to pick up
|
|
// rpath'ed libraries.
|
|
// See dyld(1), install_name_tool(1) for rpath details.
|
|
|
|
if (isMac()) {
|
|
exec {
|
|
commandLine "install_name_tool"
|
|
args '-add_rpath', '@loader_path/',
|
|
'dist/konan/nativelib/libclangstubs.dylib'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
task list_dist(type: Exec) {
|
|
commandLine 'find', 'dist'
|
|
}
|
|
|
|
task dist_runtime(type: Copy) {
|
|
dependsOn ':runtime:hostRuntime'
|
|
dependsOn ':backend.native:hostStdlib'
|
|
dependsOn ':backend.native:hostStart'
|
|
|
|
destinationDir file('dist')
|
|
|
|
from(project(':runtime').file('build')) {
|
|
include('*/*.bc')
|
|
into('lib')
|
|
}
|
|
}
|
|
|
|
task cross_dist_runtime(type: Copy) {
|
|
dependsOn.addAll(targetList.collect { ":runtime:${it}Runtime" })
|
|
dependsOn.addAll(targetList.collect { ":backend.native:${it}Stdlib" })
|
|
dependsOn.addAll(targetList.collect { ":backend.native:${it}Start" })
|
|
|
|
destinationDir file('dist')
|
|
|
|
from(project(':runtime').file('build')) {
|
|
include('*/*.bc')
|
|
into('lib')
|
|
}
|
|
}
|
|
|
|
task dist {
|
|
dependsOn 'dist_compiler', 'dist_runtime'
|
|
}
|
|
|
|
task cross_dist {
|
|
dependsOn 'cross_dist_runtime', 'dist_compiler'
|
|
}
|
|
|
|
task demo(type: Exec) {
|
|
dependsOn 'dist'
|
|
|
|
commandLine './dist/bin/konanc', 'backend.native/tests/runtime/collections/moderately_large_array.kt', '-o', 'build/demo.kexe'
|
|
}
|
|
|
|
task clean {
|
|
doLast {
|
|
delete 'dist'
|
|
}
|
|
}
|
|
|