diff --git a/.gitignore b/.gitignore index f80f5ac3195..022fcd35a1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store .idea/shelf -dependencies +/dependencies/all dist translator/src/test/kotlin/tests/*/linked out diff --git a/Interop/Indexer/build.gradle b/Interop/Indexer/build.gradle index e5f942750fd..7478f6dafdb 100644 --- a/Interop/Indexer/build.gradle +++ b/Interop/Indexer/build.gradle @@ -24,11 +24,11 @@ model { binaries.all { cCompiler.args compilerArgsForJniIncludes - cCompiler.args "-I$llvmInstallPath/include" + cCompiler.args "-I$llvmDir/include" } binaries.withType(SharedLibraryBinarySpec) { - linker.args "-L$llvmInstallPath/lib", "-lclang" + linker.args "-L$llvmDir/lib", "-lclang" } } } diff --git a/Interop/Runtime/build.gradle b/Interop/Runtime/build.gradle index 06fd98a191d..0c25acce013 100644 --- a/Interop/Runtime/build.gradle +++ b/Interop/Runtime/build.gradle @@ -23,10 +23,9 @@ model { } binaries.all { cCompiler.args compilerArgsForJniIncludes - cCompiler.args "-I$ffiIncludePath" + cCompiler.args "-I$libffiDir/include" - String libffiPicPath = "$ffiLibPath/libffi_pic.a" - linker.args file(libffiPicPath).exists() ? libffiPicPath : "$ffiLibPath/libffi.a" + linker.args "$libffiDir/lib/libffi.a" } } } diff --git a/InteropExample/build.gradle b/InteropExample/build.gradle index 74a6f498b63..4b06b429071 100644 --- a/InteropExample/build.gradle +++ b/InteropExample/build.gradle @@ -19,8 +19,8 @@ repositories { kotlinNativeInterop { llvm { defFile '../backend.native/llvm.def' - compilerOpts "-I$llvmInstallPath/include" - linkerOpts "-L$llvmInstallPath/lib" + compilerOpts "-I$llvmDir/include" + linkerOpts "-L$llvmDir/lib" } } @@ -31,3 +31,7 @@ dependencies { } mainClassName = 'MainKt' + +run { + environment 'LD_LIBRARY_PATH' : "$llvmDir/lib" +} diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 85fd514dfb9..aa1625fe52d 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -36,8 +36,8 @@ sourceSets { kotlinNativeInterop { llvm { defFile 'llvm.def' - compilerOpts "-I$llvmInstallPath/include" - linkerOpts "-L$llvmInstallPath/lib" + compilerOpts "-I$llvmDir/include" + linkerOpts "-L$llvmDir/lib" } hash { // TODO: copy-pasted from ':common:compileHash' @@ -86,6 +86,8 @@ task run(type: JavaExec) { doFirst { args '-runtime', project(':runtime').build.outputs.files.singleFile } + + environment 'LD_LIBRARY_PATH' : "$llvmDir/lib" } diff --git a/build.gradle b/build.gradle index 1a8ef7e6587..d44a0f53fc1 100644 --- a/build.gradle +++ b/build.gradle @@ -4,4 +4,10 @@ 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)} +} + +allprojects { + if (path != ":dependencies") { + evaluationDependsOn(":dependencies") + } } \ No newline at end of file diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy index 2cc4f2ab0c7..d74bdeeb5ef 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy @@ -70,7 +70,7 @@ class CompileCppToBitcode extends DefaultTask { project.exec { workingDir objDir - executable "$project.llvmInstallPath/bin/clang++" + executable "$project.llvmDir/bin/clang++" args '-std=c++11' args compilerArgs @@ -82,7 +82,7 @@ class CompileCppToBitcode extends DefaultTask { } project.exec { - executable "$project.llvmInstallPath/bin/llvm-link" + executable "$project.llvmDir/bin/llvm-link" args project.fileTree(objDir).include('**/*.bc') args linkerArgs diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index 07fc7507828..4d9a0b70307 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -141,10 +141,10 @@ class NamedNativeInteropConfig extends AbstractFileCollection implements Named { new File(project.findProject(":Interop:Indexer").buildDir, "nativelibs"), new File(project.findProject(":Interop:Runtime").buildDir, "nativelibs") ).asPath - systemProperties "llvmInstallPath" : project.llvmInstallPath + systemProperties "llvmInstallPath" : project.llvmDir environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1" - environment "DYLD_LIBRARY_PATH": "${project.llvmInstallPath}/lib" - environment "LD_LIBRARY_PATH": "${project.llvmInstallPath}/lib" + environment "DYLD_LIBRARY_PATH": "${project.llvmDir}/lib" + environment "LD_LIBRARY_PATH": "${project.llvmDir}/lib" outputs.dir generatedSrcDir outputs.dir nativeLibsDir diff --git a/dependencies/build.gradle b/dependencies/build.gradle new file mode 100644 index 00000000000..94be7127d5a --- /dev/null +++ b/dependencies/build.gradle @@ -0,0 +1,93 @@ +abstract class NativeDep extends DefaultTask { + + private static String getCurrentHostTarget() { + String osName = System.properties['os.name'] + String osArch = System.properties['os.arch'] + + // TODO: implement more generally + if (osArch in ['x86_64', 'amd64']) { + if (osName == 'Mac OS X') { + return 'darwin-macos' + } else if (osName == 'Linux') { + return 'linux-x86-64' + } else { + throw new Error("Unsupported OS: $osName") + } + } else { + throw new Error("Unsupported arch: $osArch") + } + } + + protected final String target = getCurrentHostTarget(); + + @Input + abstract String getFileName() + + protected String getUrl() { + return "http://repo.labs.intellij.net/kotlin-native/$fileName" + } + + protected File getBaseOutDir() { + final File res = project.file("all") + res.mkdirs() + return res + } + + protected File download() { + File result = new File(baseOutDir, fileName) + ant.get(src: url, dest: result, usetimestamp: true) + return result + } +} + +class TgzNativeDep extends NativeDep { + String baseName + + @Override + String getFileName() { + return "${baseName}.tar.gz" + } + + @OutputDirectory + File getOutputDir() { + return new File(baseOutDir, baseName) + } + + @TaskAction + public void downloadAndExtract() { + File archived = this.download() + + try { + // Builtin Gradle unpacking tools seem to unable to handle symlinks; + // Use external "tar" executable as workaround: + project.exec { + executable "tar" + workingDir baseOutDir + args "xf", archived + } + } catch (Throwable e) { + project.delete(outputDir) + throw e + } + + // TODO: do not extract if already extracted + } +} + + +task libffi(type: TgzNativeDep) { + baseName = "libffi-3.2.1-2-$target" +} + +task llvm(type: TgzNativeDep) { + baseName = "clang+llvm-3.8.0-$target" +} + + +task update { + dependsOn tasks.withType(NativeDep) +} + +tasks.withType(TgzNativeDep) { + rootProject.ext.set("${name}Dir", outputDir.path) +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 2534c8a0d7c..d09f037bee0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1 @@ kotlin_version=1.0.4 -llvmInstallPath=/opt/local/libexec/llvm-3.8 -ffiIncludePath=/opt/local/lib/libffi-3.2.1/include -ffiLibPath=/opt/local/lib diff --git a/runtime/build.gradle b/runtime/build.gradle index 1cb729defdc..6e5fbc88726 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -17,15 +17,15 @@ task test { doLast { exec { - commandLine "$llvmInstallPath/bin/clang", 'src/test/c/main.c', '-c', '-emit-llvm', '-o', "$buildDir/main.bc" - } + commandLine "$llvmDir/bin/clang", 'src/test/c/main.c', '-c', '-emit-llvm', '-o', "$buildDir/main.bc" + } exec { - commandLine "$llvmInstallPath/bin/clang++", build.outFile, "$buildDir/main.bc", '-o', "$buildDir/main" - } - exec { - workingDir buildDir - commandLine './main' - } + commandLine "$llvmDir/bin/clang++", build.outFile, "$buildDir/main.bc", '-o', "$buildDir/main" + } + exec { + workingDir buildDir + commandLine './main' + } } } diff --git a/settings.gradle b/settings.gradle index 04fc18c90ee..eb5e9b8a330 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ +include ':dependencies' include ':Interop:Indexer' include ':Interop:StubGenerator' include ':Interop:Runtime'