diff --git a/Interop/Indexer/build.gradle b/Interop/Indexer/build.gradle index f4b525aab28..7478f6dafdb 100644 --- a/Interop/Indexer/build.gradle +++ b/Interop/Indexer/build.gradle @@ -16,13 +16,6 @@ def javaHome = System.getProperty('java.home') def compilerArgsForJniIncludes = ["", "linux", "darwin"].collect { "-I$javaHome/../include/$it" } as String[] model { - //TODO: it's better to find some way share this configuration - toolChains { - clang(Clang) { - path "${llvmDir}/bin/clang" - } - } - components { clangbridge(NativeLibrarySpec) { sources { diff --git a/Interop/Runtime/build.gradle b/Interop/Runtime/build.gradle index 600a73ea8c0..0c25acce013 100644 --- a/Interop/Runtime/build.gradle +++ b/Interop/Runtime/build.gradle @@ -15,13 +15,6 @@ def javaHome = System.getProperty('java.home') def compilerArgsForJniIncludes = ["", "linux", "darwin"].collect { "-I$javaHome/../include/$it" } as String[] model { - //TODO: it's better to find some way share this configuration - toolChains { - clang(Clang) { - path "${llvmDir}/bin/clang" - } - } - components { callbacks(NativeLibrarySpec) { sources.c.source { diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index bce0c312cbd..48e28e1fb5a 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -12,6 +12,7 @@ abstract class KonanTest extends DefaultTask { def runtimeProject = project.project(":runtime") def llvmLlc = llvmTool("llc") def llvmC = llvmTool("clang") + def llvmCAdditionalArgs = ["--sysroot=$project.sysrootDir"] def runtimeBc = new File("${runtimeProject.buildDir.canonicalPath}/runtime.bc") def mainC = 'main.c' String goldValue = null @@ -88,6 +89,8 @@ class UnitKonanTest extends KonanTest { project.exec { commandLine "${llvmC}", "${testC}", "${runtimeS.absolutePath}", "${sourceS.absolutePath}", "${mainC}", "-o", "${exe.absolutePath}" + + args llvmCAdditionalArgs } } } @@ -97,6 +100,8 @@ class RunKonanTest extends KonanTest { project.exec { commandLine "${llvmC}", "-DRUN_TEST", "${runtimeS.absolutePath}", "${sourceS.absolutePath}", "${mainC}", "-o", "${exe.absolutePath}" + + args llvmCAdditionalArgs } } } diff --git a/build.gradle b/build.gradle index 5dce5d7281f..c20a8f434f0 100644 --- a/build.gradle +++ b/build.gradle @@ -11,16 +11,16 @@ allprojects { evaluationDependsOn(":dependencies") } - afterEvaluate { - if (plugins.hasPlugin('c')) { - model { - toolChains { - clang(Clang) { - path "$llvmDir/bin" + plugins.withType(NativeComponentPlugin) { + model { + toolChains { + clang(Clang) { + path "$llvmDir/bin" - // The system PATH should be appended automatically according to Gradle docs, - // but this doesn't seem to happen - path System.env.PATH.split(File.pathSeparator) + eachPlatform { // TODO: will not work when cross-compiling + [cCompiler, cppCompiler, linker].each { + it.withArguments { it << "--sysroot=$sysrootDir" } + } } } } diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy index d74bdeeb5ef..57d189f5dcc 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/CompileToBitcode.groovy @@ -73,6 +73,8 @@ class CompileCppToBitcode extends DefaultTask { executable "$project.llvmDir/bin/clang++" args '-std=c++11' + args "--sysroot=$project.sysrootDir" + args compilerArgs args "-I$headersDir" diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index 38688fcc90c..f7e10ca6b59 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -174,6 +174,10 @@ class NamedNativeInteropConfig implements Named { args "-linker:" + linker } + String sysrootArg = "--sysroot=$project.sysrootDir" + compilerOpts += sysrootArg + linkerOpts += sysrootArg + args compilerOpts.collect { "-copt:$it" } args linkerOpts.collect { "-lopt:$it" } diff --git a/dependencies/build.gradle b/dependencies/build.gradle index b6892542b73..54e33d36399 100644 --- a/dependencies/build.gradle +++ b/dependencies/build.gradle @@ -85,6 +85,10 @@ task llvm(type: TgzNativeDep) { baseName = "clang+llvm-3.8.0-$target" } +task sysroot(type: TgzNativeDep) { + baseName = "target-sysroot-1-$target" +} + task update { dependsOn tasks.withType(NativeDep)