Remove KonanProperties.defaultCompilerOpts
Use ClangManager instead
This commit is contained in:
committed by
SvyatoslavScherbina
parent
f703877160
commit
e171b99adb
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.native.interop.tool
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
|
||||
// TODO: Half of these calculations are already provided
|
||||
// by ClangHost class of "shared" project.
|
||||
// But there are some discrepancies, in particular the -B claculation.
|
||||
fun KonanProperties.defaultCompilerOpts(): List<String> {
|
||||
|
||||
// TODO: eliminate this. below
|
||||
val targetToolchain = absoluteTargetToolchain
|
||||
val targetSysRoot = absoluteTargetSysRoot
|
||||
val llvmHome = absoluteLlvmHome
|
||||
val llvmVersion = hostString("llvmVersion")!!
|
||||
|
||||
// StubGenerator passes the arguments to libclang which
|
||||
// works not exactly the same way as the clang binary and
|
||||
// (in particular) uses different default header search path.
|
||||
// See e.g. http://lists.llvm.org/pipermail/cfe-dev/2013-November/033680.html
|
||||
// We workaround the problem with -isystem flag below.
|
||||
val isystem = "$llvmHome/lib/clang/$llvmVersion/include"
|
||||
val quadruple = targetString("quadruple")
|
||||
val arch = targetString("arch")
|
||||
val archSelector = if (quadruple != null)
|
||||
listOf("-target", quadruple) else listOf("-arch", arch!!)
|
||||
val commonArgs = listOf("-isystem", isystem, "--sysroot=$targetSysRoot")
|
||||
|
||||
val host = TargetManager.host
|
||||
val hostSpecificArgs = when (host) {
|
||||
MACBOOK -> {
|
||||
val osVersionMinFlag = targetString("osVersionMinFlagClang")
|
||||
val osVersionMinValue = targetString("osVersionMin")
|
||||
listOf("-B$targetToolchain/usr/bin") +
|
||||
(if (osVersionMinFlag != null && osVersionMinValue != null)
|
||||
listOf("$osVersionMinFlag=$osVersionMinValue") else emptyList())
|
||||
}
|
||||
LINUX -> {
|
||||
val libGcc = targetString("libGcc")
|
||||
val binDir = "$targetSysRoot/${libGcc ?: "bin"}"
|
||||
listOf(
|
||||
"-B$binDir", "--gcc-toolchain=$targetToolchain",
|
||||
"-fuse-ld=$targetToolchain/bin/ld")
|
||||
}
|
||||
MINGW -> {
|
||||
listOf("-B$targetSysRoot/bin")
|
||||
}
|
||||
else -> error("Unexpected host: ${host}")
|
||||
}
|
||||
|
||||
return archSelector + commonArgs + hostSpecificArgs
|
||||
}
|
||||
|
||||
+3
-18
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
import kotlin.reflect.KFunction
|
||||
|
||||
class ToolConfig(userProvidedTargetName: String?, userProvidedKonanProperties: String?, runnerProvidedKonanHome: String) {
|
||||
|
||||
@@ -46,26 +45,12 @@ class ToolConfig(userProvidedTargetName: String?, userProvidedKonanProperties: S
|
||||
|
||||
val sysRoot get() = targetProperties.absoluteTargetSysRoot
|
||||
|
||||
val defaultCompilerOpts =
|
||||
targetProperties.defaultCompilerOpts()
|
||||
val defaultCompilerOpts = ClangManager(properties, dependencies.path)
|
||||
.targetLibclangArgs(targetProperties.target).toList()
|
||||
|
||||
|
||||
val libclang = when (host) {
|
||||
KonanTarget.MINGW -> "$llvmHome/bin/libclang.dll"
|
||||
else -> "$llvmHome/lib/${System.mapLibraryName("clang")}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties, dependencies: List<String>) {
|
||||
try {
|
||||
val kClass = Class.forName("org.jetbrains.kotlin.konan.util.Helper0").kotlin
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val ctor = kClass.constructors.single() as KFunction<Runnable>
|
||||
val result = ctor.call(dependenciesRoot, properties, dependencies)
|
||||
result.run()
|
||||
} catch (notFound: ClassNotFoundException) {
|
||||
// Just ignore, no helper.
|
||||
} catch (e: Throwable) {
|
||||
throw IllegalStateException("Cannot download dependencies.", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,18 @@ class ClangManager(val properties: Properties, val baseDir: String) {
|
||||
|
||||
val hostCompilerArgsForJni = hostClang.hostCompilerArgsForJni.toTypedArray()
|
||||
|
||||
fun targetLibclangArgs(target: KonanTarget): List<String> {
|
||||
// libclang works not exactly the same way as the clang binary and
|
||||
// (in particular) uses different default header search path.
|
||||
// See e.g. http://lists.llvm.org/pipermail/cfe-dev/2013-November/033680.html
|
||||
// We workaround the problem with -isystem flag below.
|
||||
val llvmVersion = properties.hostString("llvmVersion")!!
|
||||
val llvmHome = konanProperties[target]!!.absoluteLlvmHome
|
||||
val isystemArgs = listOf("-isystem", "$llvmHome/lib/clang/$llvmVersion/include")
|
||||
|
||||
return isystemArgs + targetClangArgs(target).toList()
|
||||
}
|
||||
|
||||
fun targetClangCmd(target: KonanTarget)
|
||||
= listOf("${hostClang.llvmDir}/bin/clang") + targetClangArgs(target)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user