build: Use konan.properties values for some building constants.

This patch uses values provided by konan.properties to specify
build dependencies (libffi and sysroots) and the "target" parameter
for LLVM.
This commit is contained in:
Ilya Matveev
2017-05-24 18:36:37 +07:00
committed by ilmat192
parent 070ea929f0
commit f1256edb02
3 changed files with 199 additions and 165 deletions
+1 -1
View File
@@ -239,7 +239,7 @@ targetList.each { target ->
'-target', target, '-target', target,
'-library', project(':runtime').file("build/${target}Stdlib"), '-library', project(':runtime').file("build/${target}Stdlib"),
'-runtime', project(':runtime').file("build/${target}/runtime.bc"), '-runtime', project(':runtime').file("build/${target}/runtime.bc"),
'-properties', project(':backend.native').file('konan.properties'), '-properties', rootProject.konanPropertiesFile.canonicalPath,
project(':runtime').file('src/launcher/kotlin'), project(':runtime').file('src/launcher/kotlin'),
*project.globalBuildArgs) *project.globalBuildArgs)
+15 -8
View File
@@ -60,6 +60,14 @@ void setupClang(Project project) {
} }
} }
String getTargetArg(String target) {
def result = konanProperties.getProperty("quadruple.$target")
if (result == null) {
throw IllegalArgumentException("konan.properties has no LLVM target args for target: $target")
}
return result
}
void setupCompilationFlags() { void setupCompilationFlags() {
ext.clangPath = ["$llvmDir/bin"] ext.clangPath = ["$llvmDir/bin"]
ext.clangArgs = [] ext.clangArgs = []
@@ -73,13 +81,13 @@ void setupCompilationFlags() {
["--sysroot=${gccToolchainDir}/${gnuTriplet}/sysroot", ["--sysroot=${gccToolchainDir}/${gnuTriplet}/sysroot",
"-DUSE_GCC_UNWIND=1", "-DELFSIZE=64"], "-DUSE_GCC_UNWIND=1", "-DELFSIZE=64"],
"raspberrypi": "raspberrypi":
["-target", "armv6-unknown-linux-gnueabihf", ["-target", getTargetArg("raspberrypi"),
"-mfpu=vfp", "-mfloat-abi=hard", "-mfpu=vfp", "-mfloat-abi=hard",
"-DUSE_GCC_UNWIND=1", "-DELFSIZE=32", "-DUSE_GCC_UNWIND=1", "-DELFSIZE=32",
"--sysroot=$raspberryPiSysrootDir", "--sysroot=$raspberrypiSysrootDir",
// TODO: those two are hacks. // TODO: those two are hacks.
"-I$raspberryPiSysrootDir/usr/include/c++/4.8.3", "-I$raspberrypiSysrootDir/usr/include/c++/4.8.3",
"-I$raspberryPiSysrootDir/usr/include/c++/4.8.3/arm-linux-gnueabihf"] "-I$raspberrypiSysrootDir/usr/include/c++/4.8.3/arm-linux-gnueabihf"]
] ]
} else { } else {
ext.host = "macbook" ext.host = "macbook"
@@ -96,13 +104,12 @@ void setupCompilationFlags() {
} }
ext.targetArgs << [ ext.targetArgs << [
"android_arm32": "android_arm32":
["-target", "arm-linux-androideabi", ["-target", getTargetArg("android_arm32"),
"--sysroot=$android_arm32SysrootDir", "--sysroot=$android_arm32SysrootDir",
"-D__ANDROID__", "-DUSE_GCC_UNWIND=1", "-DELFSIZE=32", "-D__ANDROID__", "-DUSE_GCC_UNWIND=1", "-DELFSIZE=32",
// HACKS! // HACKS!
"-I$android_arm32SysrootDir/usr/include/c++/4.9.x", "-I$android_arm32SysrootDir/usr/include/c++/4.9.x",
"-I$android_arm32SysrootDir/usr/include/c++/4.9.x/arm-linux-androideabi" "-I$android_arm32SysrootDir/usr/include/c++/4.9.x/arm-linux-androideabi"]
]
] ]
ext.targetList = ext.targetArgs.keySet() as List ext.targetList = ext.targetArgs.keySet() as List
@@ -229,7 +236,7 @@ task distCompiler(type: Copy) {
fileMode(0755) fileMode(0755)
into('bin') into('bin')
} }
from(project(':backend.native').file('konan.properties')) { from(konanPropertiesFile) {
into('konan') into('konan')
} }
+60 -33
View File
@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import static DependencyTaskKind.*
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
@@ -28,6 +30,10 @@ buildscript {
apply plugin: 'com.jfrog.bintray' apply plugin: 'com.jfrog.bintray'
rootProject.ext.konanPropertiesFile = project(':backend.native').file('konan.properties')
rootProject.ext.konanProperties = new Properties()
rootProject.konanProperties.load(new FileInputStream(rootProject.konanPropertiesFile))
configurations { configurations {
kotlin_compiler_jar kotlin_compiler_jar
kotlin_compiler_pom kotlin_compiler_pom
@@ -184,50 +190,71 @@ class HelperNativeDep extends TgzNativeDep {
} }
} }
static String substituteName(String name) {
switch (name) {
case "macbook": return "osx"
case "iphone": return "ios"
case "iphoneSim": return "ios_sim"
}
return name
}
enum DependencyTaskKind {
LIBFFI("Libffi"), SYSROOT("Sysroot")
DependencyTaskKind(String name) {
this.name = name
}
String name = ""
String toString() { return name }
}
void dependencyTask(String target, DependencyTaskKind kind) {
String dependencyBaseName
def properties = rootProject.konanProperties
switch (kind) {
case LIBFFI:
dependencyBaseName = properties.getProperty("libffiDir.${substituteName(target)}")
break
case SYSROOT:
dependencyBaseName = properties.getProperty("targetSysRoot.${substituteName(target)}")
break
}
if (dependencyBaseName == null) {
throw project.unsupportedPlatformException()
}
task "${target}${kind}"(type: HelperNativeDep) {
baseName = dependencyBaseName
}
}
task llvm(type: HelperNativeDep) { task llvm(type: HelperNativeDep) {
baseName = "clang-llvm-$llvmVersion-$host" baseName = "clang-llvm-$llvmVersion-$host"
} }
if (isLinux()) { if (isLinux()) {
task linuxLibffi(type: HelperNativeDep) { // The gcc toolchain contains the sysroot for linux platform.
baseName = "libffi-3.2.1-2-$host"
}
task gccToolchain(type: HelperNativeDep) { task gccToolchain(type: HelperNativeDep) {
baseName = "target-gcc-toolchain-3-$host" baseName = "target-gcc-toolchain-3-$host"
} }
task raspberryPiSysroot(type: HelperNativeDep) {
baseName = "target-sysroot-1-raspberrypi" dependencyTask("linux", LIBFFI)
} dependencyTask("raspberrypi", SYSROOT)
task raspberrypiLibffi(type: HelperNativeDep) { dependencyTask("raspberrypi", LIBFFI)
baseName = "libffi-3.2.1-2-raspberrypi"
}
} else { } else {
task macbookLibffi(type: HelperNativeDep) { dependencyTask("macbook", SYSROOT)
baseName = "libffi-3.2.1-2-$host" dependencyTask("macbook", LIBFFI)
} dependencyTask("iphone", SYSROOT)
task macbookSysroot(type: HelperNativeDep) { dependencyTask("iphone", LIBFFI)
baseName = "target-sysroot-1-$host"
} // TODO: re-enable when we known how to bring the simulator sysroot to dependencies.
task iphoneSysroot(type: HelperNativeDep) { // dependencyTask("iphoneSim", SYSROOT)
baseName = "target-sysroot-2-darwin-ios"
}
task iphoneLibffi(type: HelperNativeDep) {
baseName = "libffi-3.2.1-2-darwin-ios"
}
// TODO: re-enable when we known how to bring the simulator
// sysroot to dependencies.
// task iphoneSimSysroot(type: TgzNativeDep) {
// baseName = "target-sysroot-1-darwin-ios-sim"
// }
} }
task android_arm32Sysroot(type: HelperNativeDep) { dependencyTask("android_arm32", SYSROOT)
baseName = "target-sysroot-21-android_arm32" dependencyTask("android_arm32", LIBFFI)
}
task android_arm32Libffi(type: HelperNativeDep) {
baseName = "libffi-3.2.1-2-android_arm32"
}
task update(type: Copy) { task update(type: Copy) {
dependsOn tasks.withType(NativeDep) dependsOn tasks.withType(NativeDep)