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)
+137 -130
View File
@@ -23,11 +23,11 @@ convention.plugins.platformInfo = new PlatformInfo()
allprojects { allprojects {
if (path != ":dependencies") { if (path != ":dependencies") {
evaluationDependsOn(":dependencies") evaluationDependsOn(":dependencies")
} }
repositories { repositories {
mavenCentral() mavenCentral()
} }
loadCommandLineProperties() loadCommandLineProperties()
@@ -41,25 +41,33 @@ void setupClang(Project project) {
project.convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project) project.convention.plugins.execClang = new org.jetbrains.kotlin.ExecClang(project)
project.plugins.withType(NativeComponentPlugin) { project.plugins.withType(NativeComponentPlugin) {
project.model { project.model {
toolChains { toolChains {
clang(Clang) { clang(Clang) {
clangPath.each { clangPath.each {
path it path it
} }
eachPlatform { // TODO: will not work when cross-compiling eachPlatform { // TODO: will not work when cross-compiling
[cCompiler, cppCompiler, linker].each { [cCompiler, cppCompiler, linker].each {
it.withArguments { it.addAll(hostClangArgs) } it.withArguments { it.addAll(hostClangArgs) }
} }
} }
} }
} }
} }
} }
} }
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 = []
@@ -67,52 +75,51 @@ void setupCompilationFlags() {
final String binDir final String binDir
if (isLinux()) { if (isLinux()) {
ext.host = "linux" ext.host = "linux"
ext.targetArgs << ext.targetArgs <<
[(ext.host): [(ext.host):
["--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"
ext.targetArgs << ext.targetArgs <<
[(ext.host): [(ext.host):
["--sysroot=$macbookSysrootDir", "-mmacosx-version-min=$minMacOsVersion"], ["--sysroot=$macbookSysrootDir", "-mmacosx-version-min=$minMacOsVersion"],
"iphone": "iphone":
["-stdlib=libc++", "-arch", "arm64", "-isysroot", "$iphoneSysrootDir", ["-stdlib=libc++", "-arch", "arm64", "-isysroot", "$iphoneSysrootDir",
"-miphoneos-version-min=8.0.0"] "-miphoneos-version-min=8.0.0"]
// TODO: re-enable after simulator sysroot is available in the dependencies // TODO: re-enable after simulator sysroot is available in the dependencies
// "iphone_sim": // "iphone_sim":
// ["-stdlib=libc++", "-isysroot", "$iphoneSimSysrootDir", "-miphoneos-version-min=8.0.0"], // ["-stdlib=libc++", "-isysroot", "$iphoneSimSysrootDir", "-miphoneos-version-min=8.0.0"],
] ]
} }
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
if (isLinux()) { if (isLinux()) {
binDir = "$gccToolchainDir/$gnuTriplet/bin" binDir = "$gccToolchainDir/$gnuTriplet/bin"
ext.clangArgs.addAll([ ext.clangArgs.addAll([
"--gcc-toolchain=$gccToolchainDir" "--gcc-toolchain=$gccToolchainDir"
]) ])
} else { } else {
binDir = "$macbookSysrootDir/usr/bin" binDir = "$macbookSysrootDir/usr/bin"
} }
ext.clangArgs << "-B$binDir" ext.clangArgs << "-B$binDir"
ext.hostClangArgs = ext.clangArgs.clone() ext.hostClangArgs = ext.clangArgs.clone()
@@ -124,22 +131,22 @@ void setupCompilationFlags() {
void loadLocalProperties() { void loadLocalProperties() {
if (new File("$project.rootDir/local.properties").exists()) { if (new File("$project.rootDir/local.properties").exists()) {
Properties props = new Properties() Properties props = new Properties()
props.load(new FileInputStream("$project.rootDir/local.properties")) props.load(new FileInputStream("$project.rootDir/local.properties"))
props.each {prop -> project.ext.set(prop.key, prop.value)} props.each {prop -> project.ext.set(prop.key, prop.value)}
} }
} }
void loadCommandLineProperties() { void loadCommandLineProperties() {
if (project.hasProperty("konanc_flags")) { if (project.hasProperty("konanc_flags")) {
throw new Error("Specify either -Ptest_flags or -Pbuild_flags.") throw new Error("Specify either -Ptest_flags or -Pbuild_flags.")
} }
ext.globalBuildArgs = project.hasProperty("build_flags") ext.globalBuildArgs = project.hasProperty("build_flags")
? ext.build_flags.split(' ') : [] ? ext.build_flags.split(' ') : []
ext.globalTestArgs = project.hasProperty("test_flags") ext.globalTestArgs = project.hasProperty("test_flags")
? ext.test_flags.split(' ') : [] ? ext.test_flags.split(' ') : []
ext.testTarget = project.hasProperty("test_target") ext.testTarget = project.hasProperty("test_target")
? ext.test_target : null ? ext.test_target : null
} }
class PlatformInfo { class PlatformInfo {
@@ -147,33 +154,33 @@ class PlatformInfo {
private final String osArch = System.properties['os.arch'] private final String osArch = System.properties['os.arch']
boolean isMac() { boolean isMac() {
return osName == 'Mac OS X' return osName == 'Mac OS X'
} }
boolean isLinux() { boolean isLinux() {
return osName == 'Linux' return osName == 'Linux'
} }
boolean isAmd64() { boolean isAmd64() {
return osArch in ['x86_64', 'amd64'] return osArch in ['x86_64', 'amd64']
} }
String getGnuTriplet() { String getGnuTriplet() {
if (isLinux() && isAmd64()) { if (isLinux() && isAmd64()) {
return "x86_64-unknown-linux-gnu" return "x86_64-unknown-linux-gnu"
} else { } else {
throw unsupportedPlatformException() throw unsupportedPlatformException()
} }
} }
String simpleOsName() { String simpleOsName() {
if (isMac()) return 'macos' if (isMac()) return 'macos'
if (isLinux()) return 'linux' if (isLinux()) return 'linux'
throw unsupportedPlatformException() throw unsupportedPlatformException()
} }
Throwable unsupportedPlatformException() { Throwable unsupportedPlatformException() {
return new Error("unsupported platform: $osName/$osArch") return new Error("unsupported platform: $osName/$osArch")
} }
} }
@@ -189,53 +196,53 @@ task distCompiler(type: Copy) {
destinationDir file('dist') destinationDir file('dist')
from(project(':backend.native').file('build/libs')) { from(project(':backend.native').file('build/libs')) {
into('konan/lib') into('konan/lib')
} }
from(project('Interop').file('Runtime/build/libs')) { from(project('Interop').file('Runtime/build/libs')) {
into('konan/lib') into('konan/lib')
} }
from(project('Interop').file('Indexer/build/libs')) { from(project('Interop').file('Indexer/build/libs')) {
into('konan/lib') into('konan/lib')
} }
from(project('Interop').file('StubGenerator/build/libs')) { from(project('Interop').file('StubGenerator/build/libs')) {
into('konan/lib') into('konan/lib')
} }
from(project(':backend.native').file('build/external_jars')) { from(project(':backend.native').file('build/external_jars')) {
into('konan/lib') into('konan/lib')
} }
from(project(':backend.native').file('build/nativelibs')) { from(project(':backend.native').file('build/nativelibs')) {
into('konan/nativelib') into('konan/nativelib')
} }
from(project(':Interop').file('Indexer/build/nativelibs')) { from(project(':Interop').file('Indexer/build/nativelibs')) {
into('konan/nativelib') into('konan/nativelib')
} }
from(project(':Interop').file('Runtime/build/nativelibs')) { from(project(':Interop').file('Runtime/build/nativelibs')) {
into('konan/nativelib') into('konan/nativelib')
} }
from(project(':llvmDebugInfoC').file('build/libs/debugInfo/shared')) { from(project(':llvmDebugInfoC').file('build/libs/debugInfo/shared')) {
into('konan/nativelib') into('konan/nativelib')
} }
from(file('cmd')) { from(file('cmd')) {
fileMode(0755) fileMode(0755)
into('bin') into('bin')
} }
from(project(':backend.native').file('konan.properties')) { from(konanPropertiesFile) {
into('konan') into('konan')
} }
// TODO: check if we use native libraries copied to dist (see above) or not. // TODO: check if we use native libraries copied to dist (see above) or not.
from(project(':tools:helpers').file('build/libs')) { from(project(':tools:helpers').file('build/libs')) {
into('konan/lib') into('konan/lib')
} }
} }
@@ -253,8 +260,8 @@ task commonDistRuntime(type: Copy) {
// Target independant common part. // Target independant common part.
from(project(':runtime').file("build/${host}Stdlib")) { from(project(':runtime').file("build/${host}Stdlib")) {
include('**') include('**')
into('klib/stdlib') into('klib/stdlib')
} }
} }
@@ -265,25 +272,25 @@ task crossDistRuntime(type: Copy) {
targetList.each { target -> targetList.each { target ->
task("${target}CrossDistRuntime", type: Copy) { task("${target}CrossDistRuntime", type: Copy) {
dependsOn ":runtime:${target}Runtime" dependsOn ":runtime:${target}Runtime"
dependsOn ":backend.native:${target}Stdlib" dependsOn ":backend.native:${target}Stdlib"
dependsOn ":backend.native:${target}Start" dependsOn ":backend.native:${target}Start"
destinationDir file('dist') destinationDir file('dist')
from(project(':runtime').file("build/$target")) { from(project(':runtime').file("build/$target")) {
include("*.bc") include("*.bc")
into("klib/stdlib/$target/native") into("klib/stdlib/$target/native")
} }
from(project(':runtime').file("build/${target}Stdlib")) { from(project(':runtime').file("build/${target}Stdlib")) {
include('**') include('**')
into('klib/stdlib') into('klib/stdlib')
} }
from(project(':runtime').file("build/${target}Start/$target/kotlin")) { from(project(':runtime').file("build/${target}Start/$target/kotlin")) {
include("program.kt.bc") include("program.kt.bc")
rename('program.kt.bc', 'start.kt.bc') rename('program.kt.bc', 'start.kt.bc')
into("klib/stdlib/$target/native") into("klib/stdlib/$target/native")
} }
} }
} }
@@ -299,33 +306,33 @@ task bundle(type: Tar) {
dependsOn('crossDist') dependsOn('crossDist')
baseName = "kotlin-native-${simpleOsName()}-${project.konanVersion}" baseName = "kotlin-native-${simpleOsName()}-${project.konanVersion}"
from("$project.rootDir/dist") { from("$project.rootDir/dist") {
include '**' include '**'
exclude 'dependencies' exclude 'dependencies'
into baseName into baseName
} }
from(project.rootDir) { from(project.rootDir) {
include 'DISTRO_README.md' include 'DISTRO_README.md'
rename { rename {
return "README.md" return "README.md"
} }
into baseName into baseName
} }
from(project.rootDir) { from(project.rootDir) {
include 'samples/**' include 'samples/**'
include 'INTEROP.md' include 'INTEROP.md'
include 'RELEASE_NOTES.md' include 'RELEASE_NOTES.md'
include 'GRADLE_PLUGIN.md' include 'GRADLE_PLUGIN.md'
exclude '**/gradle.properties' exclude '**/gradle.properties'
exclude '**/build' exclude '**/build'
exclude '**/.gradle' exclude '**/.gradle'
rename { String fileName -> rename { String fileName ->
if (fileName == "gradle.properties.for_bundle") { if (fileName == "gradle.properties.for_bundle") {
return "gradle.properties" return "gradle.properties"
} else { } else {
return fileName return fileName
} }
} }
into baseName into baseName
} }
destinationDir = file('.') destinationDir = file('.')
extension = 'tar.gz' extension = 'tar.gz'
@@ -340,9 +347,9 @@ task demo(type: Exec) {
task clean { task clean {
doLast { doLast {
file('dist').traverse(type: FileType.ANY, excludeNameFilter: "dependencies", maxDepth: 0) { file('dist').traverse(type: FileType.ANY, excludeNameFilter: "dependencies", maxDepth: 0) {
delete it delete it
} }
delete bundle.outputs.files delete bundle.outputs.files
} }
} }
+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)