From a856b0d9ceb350484fc6904a9940d0a72affd10c Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Mon, 23 Jan 2017 20:32:24 +0300 Subject: [PATCH] More accurate host- and cross- target separations. --- backend.native/build.gradle | 34 ++++++++-------- .../kotlin/backend/konan/llvm/Runtime.kt | 1 + build.gradle | 4 +- common/build.gradle | 14 ++++--- runtime/build.gradle | 39 ++++++++++--------- 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 297ac48ad09..6ae53526e12 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -143,7 +143,7 @@ kotlinNativeInterop { compilerOpts '-fPIC' linkerOpts '-fPIC' linker 'clang++' - linkOutputs ':common:compileHash' + linkOutputs ':common:hostHash' headers fileTree('../common/src/hash/headers') { include '**/*.h' @@ -191,48 +191,48 @@ task start(dependsOn: 'hostStart') // so we provide custom values for // -runtime, -properties, -library and -Djava.library.path -targetList.each { platformName -> - task("${platformName}Stdlib", type: JavaExec) { +targetList.each { target -> + task("${target}Stdlib", type: JavaExec) { main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt' classpath = project.configurations.cli_bc jvmArgs "-ea", "-Dkonan.home=${project.parent.file('dist')}", "-Djava.library.path=${project.buildDir}/nativelibs" - args('-output', project(':runtime').file("build/${platformName}/stdlib.kt.bc"), + args('-output', project(':runtime').file("build/${target}/stdlib.kt.bc"), '-nolink', '-nostdlib', - '-target', platformName, - '-runtime', project(':runtime').file("build/${platformName}/runtime.bc"), + '-target', target, + '-runtime', project(':runtime').file("build/${target}/runtime.bc"), '-properties', project(':backend.native').file('konan.properties'), project(':runtime').file('src/main/kotlin'), *project.globalArgs) inputs.dir(project(':runtime').file('src/main/kotlin')) - outputs.file(project(':runtime').file("build/${platformName}/stdlib.kt.bc")) + outputs.file(project(':runtime').file("build/${target}/stdlib.kt.bc")) - dependsOn ":runtime:build" + dependsOn ":runtime:${target}Runtime" } } -targetList.each { platformName -> - task("${platformName}Start", type: JavaExec) { +targetList.each { target -> + task("${target}Start", type: JavaExec) { main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt' classpath = project.configurations.cli_bc jvmArgs "-ea", "-Dkonan.home=${project.parent.file('dist')}", "-Djava.library.path=${project.buildDir}/nativelibs" - args('-output', project(':runtime').file("build/${platformName}/start.kt.bc"), + args('-output', project(':runtime').file("build/${target}/start.kt.bc"), '-nolink', '-nostdlib', - '-target', platformName, - '-library', project(':runtime').file("build/${platformName}/stdlib.kt.bc"), - '-runtime', project(':runtime').file("build/${platformName}/runtime.bc"), + '-target', target, + '-library', project(':runtime').file("build/${target}/stdlib.kt.bc"), + '-runtime', project(':runtime').file("build/${target}/runtime.bc"), '-properties', project(':backend.native').file('konan.properties'), project(':runtime').file('src/launcher/kotlin'), *project.globalArgs) inputs.dir(project(':runtime').file('src/launcher/kotlin')) - outputs.file(project(':runtime').file("build/${platformName}/start.kt.bc")) + outputs.file(project(':runtime').file("build/${target}/start.kt.bc")) - dependsOn ":runtime:build", "${platformName}Stdlib" + dependsOn ":runtime:${target}Runtime", "${target}Stdlib" } } @@ -248,7 +248,7 @@ task jars(type: Jar) { 'build/classes/hashInteropStubs', 'build/classes/llvmInteropStubs' - dependsOn 'build', ':runtime:build', 'external_jars' + dependsOn 'build', ':runtime:hostRuntime', 'external_jars' } task external_jars(type: Copy) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/Runtime.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/Runtime.kt index 9bcd2bc4bf6..76c97f54cc2 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/Runtime.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/Runtime.kt @@ -11,6 +11,7 @@ class Runtime(private val bitcodeFile: String) { val bufRef = alloc() val errorRef = allocPointerTo() + val res = LLVMCreateMemoryBufferWithContentsOfFile(bitcodeFile, bufRef.ptr, errorRef.ptr) if (res != 0) { throw Error(errorRef.value?.asCString()?.toString()) diff --git a/build.gradle b/build.gradle index 99ca05a0dc9..d88d10dc60e 100644 --- a/build.gradle +++ b/build.gradle @@ -148,7 +148,7 @@ task list_dist(type: Exec) { } task dist_runtime(type: Copy) { - dependsOn ':runtime:build' + dependsOn ':runtime:hostRuntime' dependsOn ':backend.native:hostStdlib' dependsOn ':backend.native:hostStart' @@ -161,7 +161,7 @@ task dist_runtime(type: Copy) { } task cross_dist_runtime(type: Copy) { - dependsOn ':runtime:build' + dependsOn.addAll(targetList.collect { ":runtime:${it}Runtime" }) dependsOn.addAll(targetList.collect { ":backend.native:${it}Stdlib" }) dependsOn.addAll(targetList.collect { ":backend.native:${it}Start" }) diff --git a/common/build.gradle b/common/build.gradle index a676dfa0c6a..698c7e49608 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,15 +1,17 @@ -import org.jetbrains.kotlin.CompilePerTarget +import org.jetbrains.kotlin.CompileCppToBitcode // TODO: consider using some Gradle plugins to build and test -task compileHash(type: CompilePerTarget) { - name 'hash' - targetList targetList - targetArgs targetArgs +targetList.each { targetName -> + task ("${targetName}Hash", type: CompileCppToBitcode) { + name 'hash' + target targetName + compilerArgs targetArgs[targetName] + } } task build { - dependsOn compileHash + dependsOn hostHash } task clean << { diff --git a/runtime/build.gradle b/runtime/build.gradle index 11baaf62517..37647e082b3 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -1,28 +1,29 @@ -import org.jetbrains.kotlin.CompilePerTarget +import org.jetbrains.kotlin.CompileCppToBitcode // TODO: consider using some Gradle plugins to build and test - -task build(type: CompilePerTarget) { - name 'runtime' - srcRoot file('src/main') - dependsOn ":common:compileHash" - dependsOn "launcher" - targetList targetList - targetArgs targetArgs - compilerArgs '-I' + project.file('../common/src/hash/headers') // TODO: copy-pasted from 'common' - targetLinkerArgs targetList.collectEntries { - [it,[project.file("../common/build/$it/hash.bc")]] +targetList.each { targetName -> + task("${targetName}Runtime", type: CompileCppToBitcode) { + name "runtime" + srcRoot file('src/main') + dependsOn ":common:${targetName}Hash" + dependsOn "${targetName}Launcher" + target targetName + compilerArgs targetArgs[targetName] + compilerArgs '-I' + project.file('../common/src/hash/headers') + linkerArgs project.file("../common/build/$targetName/hash.bc").path } } -task launcher(type: CompilePerTarget) { - name 'launcher' - srcRoot file('src/launcher') - targetList targetList - targetArgs targetArgs - compilerArgs '-I' + project.file('../common/src/hash/headers') // TODO: copy-pasted from 'common' - compilerArgs '-I' + project.file('src/main/cpp') +targetList.each { targetName -> + task("${targetName}Launcher", type: CompileCppToBitcode) { + name "launcher" + srcRoot file('src/launcher') + target targetName + compilerArgs targetArgs[targetName] + compilerArgs '-I' + project.file('../common/src/hash/headers') + compilerArgs '-I' + project.file('src/main/cpp') + } } task clean << {