413f47fda5
Introduced LinkStage in the compiler. Removed the link stage from 'konanc'. Removed duplicate :stdlib and :start targets. Simplified test run task a lot.
219 lines
5.5 KiB
Groovy
219 lines
5.5 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()
|
|
maven {
|
|
url "http://dl.bintray.com/kotlin/kotlin-eap-1.1"
|
|
}
|
|
}
|
|
|
|
|
|
convention.plugins.clangFlags = new ClangFlags(new PlatformInfo(), "$llvmDir")
|
|
ext.clangPath = ["$llvmDir/bin"]
|
|
ext.clangArgs = []
|
|
final String binDir
|
|
if (isLinux()) {
|
|
binDir = "$gccToolchainDir/$gnuTriplet/bin"
|
|
ext.clangArgs.addAll([
|
|
"--sysroot=$gccToolchainDir/$gnuTriplet/sysroot",
|
|
"--gcc-toolchain=$gccToolchainDir",
|
|
"-L$llvmDir/lib"
|
|
])
|
|
} else {
|
|
binDir = "$sysrootDir/usr/bin"
|
|
ext.clangArgs << "--sysroot=$sysrootDir"
|
|
}
|
|
ext.clangArgs << "-B$binDir"
|
|
ext.clangPath << binDir
|
|
ext.jvmArgs = ["-ea"]
|
|
ext.clangLinkArgs = libLink()
|
|
ext.clangOptArgs = optArgs()
|
|
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(clangArgs) }
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class ClangFlags {
|
|
|
|
protected PlatformInfo platform
|
|
protected String llvmDir
|
|
|
|
private List<String> linkCppAbi, linkPlatform, optArgs
|
|
|
|
ClangFlags(platformInfo, llvm) {
|
|
platform = platformInfo
|
|
llvmDir = llvm
|
|
|
|
if (platform.isLinux()) {
|
|
linkCppAbi= ["-Wl,-Bstatic", "-lc++abi", "-Wl,-Bdynamic"]
|
|
linkPlatform= ["-ldl", "-lpthread", "-lm", "-rdynamic"]
|
|
optArgs = ["-O3", "-fuse-ld=gold", "-flto", "-ffunction-sections", "-Wl,--gc-sections"]
|
|
} else if (platform.isMac()) {
|
|
// Life is hard. MacOS linker is harder.
|
|
// This is how we force the linker to link statically.
|
|
linkCppAbi= ["${llvmDir}/lib/libc++abi.a"]
|
|
linkPlatform= []
|
|
optArgs = ["-O3", "-flto", "-Wl,-dead_strip"]
|
|
} else {
|
|
throw unsupportedPlatformException()
|
|
}
|
|
|
|
}
|
|
|
|
public List<String> linkCppAbi() {
|
|
return linkCppAbi
|
|
}
|
|
|
|
public List<String> linkPlatform() {
|
|
return linkPlatform
|
|
}
|
|
|
|
public List<String> optArgs() {
|
|
return optArgs
|
|
}
|
|
|
|
|
|
public List<String> libLink() {
|
|
def libs = []
|
|
libs.addAll(linkPlatform())
|
|
libs.addAll(linkCppAbi())
|
|
return libs
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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', 'dist_runtime'
|
|
|
|
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(':backend.native').file('build/external_jars')) {
|
|
into('konan/lib')
|
|
}
|
|
|
|
from(project(':backend.native').file('build/nativelibs')) {
|
|
into('konan/nativelib')
|
|
}
|
|
|
|
from(file('cmd')) {
|
|
fileMode(0755)
|
|
include('konanc')
|
|
include('kotlinc-native')
|
|
|
|
def allClangArgs = "${clangArgs.join(' ')} ${clangLinkArgs.join(' ')}"
|
|
|
|
filter { line -> line.replaceAll("FILTER_CLANG_PLATFORM_ARGS", allClangArgs) }
|
|
filter { line -> line.replaceAll("FILTER_CLANG_PLATFORM_OPT", "${clangOptArgs.join(' ')}") }
|
|
filter { line -> line.replaceAll("FILTER_CLANG_BIN_PATH", "${project.llvmDir}/bin") }
|
|
|
|
into('bin')
|
|
}
|
|
|
|
from(project(':backend.native').file('konan.properties')) {
|
|
into('konan')
|
|
}
|
|
}
|
|
|
|
task list_dist(type: Exec) {
|
|
commandLine 'find', 'dist'
|
|
}
|
|
|
|
task dist_runtime(type: Copy) {
|
|
dependsOn ':runtime:build', ':backend.native:stdlib', ':backend.native:start'
|
|
|
|
destinationDir file('dist')
|
|
|
|
from(project(':runtime').file('build')) {
|
|
include('*.bc')
|
|
into('lib')
|
|
}
|
|
}
|
|
|
|
task dist {
|
|
dependsOn 'dist_compiler', 'dist_runtime'
|
|
}
|
|
|
|
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'
|
|
}
|
|
}
|
|
|