Introduced -target and -list_targets flags.

Use it like

    $ konanc hello.kt -target iphone
This commit is contained in:
Alexander Gorshenev
2017-01-13 16:38:40 +03:00
committed by alexander-gorshenev
parent d31b44135a
commit afaa50ce34
21 changed files with 458 additions and 250 deletions
@@ -1,16 +1,65 @@
package org.jetbrains.kotlin
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.*
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
class CompilePerTarget extends CompileCppToBitcode {
private List<String> targetList = []
private Map<String, List<String>> targetArgs = null
private Map<String, List<String>> targetLinkerArgs = null
void targetList(List<String> list) {
targetList.addAll(list)
}
void targetArgs(Map<String, List<String>> map) {
targetArgs = map
}
private Map<String, List<String>> getTargetArgs() {
return targetArgs
}
void targetLinkerArgs(Map<String, List<String>> map) {
targetLinkerArgs = map
}
private Map<String, List<String>> getTargetLinkerArgs() {
return targetLinkerArgs
}
@TaskAction
void compile() {
def targetList = this.targetList
def targetArgs = getTargetArgs()
def targetLinkerArgs = getTargetLinkerArgs()
def commonCompilerArgs = getCompilerArgs().clone()
def commonLinkerArgs = getLinkerArgs().clone()
targetList.each {
this.compilerArgs = []
this.linkerArgs = []
target(it)
compilerArgs(commonCompilerArgs)
if (targetArgs != null)
compilerArgs(targetArgs[it])
linkerArgs(commonLinkerArgs)
if (targetLinkerArgs != null)
linkerArgs(targetLinkerArgs[it])
super.compile()
}
}
}
class CompileCppToBitcode extends DefaultTask {
private String name = "main"
private String target = "host"
private File srcRoot;
private List<String> compilerArgs = []
private List<String> linkerArgs = []
protected List<String> compilerArgs = []
protected List<String> linkerArgs = []
@InputDirectory
File getSrcRoot() {
@@ -19,7 +68,7 @@ class CompileCppToBitcode extends DefaultTask {
@OutputFile
File getOutFile() {
return new File(project.buildDir, "${name}.bc")
return new File(getTargetDir(), "${name}.bc")
}
private File getSrcDir() {
@@ -30,23 +79,31 @@ class CompileCppToBitcode extends DefaultTask {
return new File(this.getSrcRoot(), "headers")
}
private File getTargetDir() {
return new File(project.buildDir, target)
}
private File getObjDir() {
return new File(project.buildDir, name)
return new File(getTargetDir(), name)
}
void name(String value) {
name = value
}
void target(String value) {
target = value
}
void srcRoot(File value) {
srcRoot = value
}
private List<String> getCompilerArgs() {
protected List<String> getCompilerArgs() {
return compilerArgs
}
private List<String> getLinkerArgs() {
protected List<String> getLinkerArgs() {
return linkerArgs
}
@@ -54,10 +111,18 @@ class CompileCppToBitcode extends DefaultTask {
compilerArgs.addAll(args)
}
void compilerArgs(List<String> args) {
compilerArgs.addAll(args)
}
void linkerArgs(String... args) {
linkerArgs.addAll(args)
}
void linkerArgs(List<String> args) {
linkerArgs.addAll(args)
}
@TaskAction
void compile() {
// the strange code below seems to be required due to some Gradle (Groovy?) behaviour
@@ -34,7 +34,7 @@ class ExecClang {
if (executable in ['clang', 'clang++']) {
executable = "${project.llvmDir}/bin/$executable"
} else {
throw new GradleException("unsupport clang executable: $executable")
throw new GradleException("unsupported clang executable: $executable")
}
environment["PATH"] = project.files(project.clangPath).asPath +
@@ -47,4 +47,4 @@ class ExecClang {
}
return project.exec(extendedAction)
}
}
}
@@ -12,7 +12,6 @@ abstract class KonanTest extends DefaultTask {
def backendNative = project.project(":backend.native")
def runtimeProject = project.project(":runtime")
def dist = project.rootProject.file("dist")
def llvmLlc = llvmTool("llc")
def runtimeBc = new File("${dist.canonicalPath}/lib/runtime.bc").absolutePath
def launcherBc = new File("${dist.canonicalPath}/lib/launcher.bc").absolutePath
def startKtBc = new File("${dist.canonicalPath}/lib/start.kt.bc").absolutePath
@@ -100,14 +99,6 @@ abstract class KonanTest extends DefaultTask {
if (goldValue != null && goldValue != out.toString())
throw new RuntimeException("test failed.")
}
private String llvmTool(String tool) {
return "${project.llvmDir}/bin/${tool}"
}
protected List<String> clangLinkArgs() {
return project.clangLinkArgs
}
}
class RunKonanTest extends KonanTest {
@@ -182,8 +182,8 @@ class NamedNativeInteropConfig implements Named {
environment['PATH'] = project.files(project.clangPath).asPath +
File.pathSeparator + environment['PATH']
compilerOpts += project.clangArgs
linkerOpts += project.clangArgs
compilerOpts += project.hostClangArgs
linkerOpts += project.hostClangArgs
args compilerOpts.collect { "-copt:$it" }
args linkerOpts.collect { "-lopt:$it" }