Introduce a proper TargetTriple class.
Target triple (like `arm64-apple-ios-simulator`) is a common way to represent any target platform. One of many useful properties: it allows to explicitly distinguish iOS arm64 simulator target and a real device.
This commit is contained in:
committed by
TeamCityServer
parent
19116e5623
commit
cebf815fed
@@ -33,10 +33,6 @@ internal object Android {
|
||||
|
||||
class ClangArgs(private val configurables: Configurables) : Configurables by configurables {
|
||||
|
||||
private val targetArg = if (configurables is TargetableConfigurables)
|
||||
configurables.targetArg
|
||||
else null
|
||||
|
||||
private val clangArgsSpecificForKonanSources
|
||||
get() = runtimeDefinitions.map { "-D$it" }
|
||||
|
||||
@@ -53,8 +49,8 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
|
||||
if (configurables is GccConfigurables) {
|
||||
add(listOf("--gcc-toolchain=${configurables.absoluteGccToolchain}"))
|
||||
}
|
||||
if (configurables is TargetableConfigurables) {
|
||||
add(listOf("-target", configurables.targetArg!!))
|
||||
if (configurables !is AppleConfigurables) {
|
||||
add(listOf("-target", configurables.targetTriple.toString()))
|
||||
}
|
||||
if (configurables is AppleConfigurables) {
|
||||
val arch = when (target) {
|
||||
@@ -101,7 +97,7 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con
|
||||
|
||||
KonanTarget.ANDROID_ARM32, KonanTarget.ANDROID_ARM64,
|
||||
KonanTarget.ANDROID_X86, KonanTarget.ANDROID_X64 -> {
|
||||
val clangTarget = targetArg!!
|
||||
val clangTarget = targetTriple.toString()
|
||||
val architectureDir = Android.architectureDirForTarget(target)
|
||||
val toolchainSysroot = "$absoluteTargetToolchain/sysroot"
|
||||
listOf(
|
||||
|
||||
+10
-10
@@ -52,6 +52,10 @@ interface LldFlags : TargetableExternalStorage {
|
||||
interface Configurables : TargetableExternalStorage, RelocationModeFlags {
|
||||
|
||||
val target: KonanTarget
|
||||
val targetTriple: TargetTriple
|
||||
get() = targetString("targetTriple")
|
||||
?.let(TargetTriple.Companion::fromString)
|
||||
?: error("quadruple for $target is not set.")
|
||||
|
||||
val llvmHome get() = hostString("llvmHome")
|
||||
val llvmVersion get() = hostString("llvmVersion")
|
||||
@@ -91,12 +95,8 @@ interface ConfigurablesWithEmulator : Configurables {
|
||||
val absoluteEmulatorExecutable get() = absolute(emulatorExecutable)
|
||||
}
|
||||
|
||||
interface TargetableConfigurables : Configurables {
|
||||
val targetArg get() = targetString("quadruple")
|
||||
}
|
||||
|
||||
interface AppleConfigurables : Configurables, ClangFlags {
|
||||
val arch get() = targetString("arch")!!
|
||||
val arch get() = targetTriple.architecture
|
||||
val osVersionMin get() = targetString("osVersionMin")!!
|
||||
val osVersionMinFlagLd get() = targetString("osVersionMinFlagLd")!!
|
||||
val osVersionMinFlagClang get() = targetString("osVersionMinFlagClang")!!
|
||||
@@ -105,9 +105,9 @@ interface AppleConfigurables : Configurables, ClangFlags {
|
||||
val absoluteAdditionalToolsDir get() = absolute(additionalToolsDir)
|
||||
}
|
||||
|
||||
interface MingwConfigurables : TargetableConfigurables, ClangFlags
|
||||
interface MingwConfigurables : Configurables, ClangFlags
|
||||
|
||||
interface GccConfigurables : TargetableConfigurables, ClangFlags {
|
||||
interface GccConfigurables : Configurables, ClangFlags {
|
||||
val gccToolchain get() = targetString("gccToolchain")
|
||||
val absoluteGccToolchain get() = absolute(gccToolchain)
|
||||
|
||||
@@ -123,11 +123,11 @@ interface GccConfigurables : TargetableConfigurables, ClangFlags {
|
||||
val linkerGccFlags get() = targetList("linkerGccFlags")
|
||||
}
|
||||
|
||||
interface AndroidConfigurables : TargetableConfigurables, ClangFlags
|
||||
interface AndroidConfigurables : Configurables, ClangFlags
|
||||
|
||||
interface WasmConfigurables : TargetableConfigurables, ClangFlags, LldFlags
|
||||
interface WasmConfigurables : Configurables, ClangFlags, LldFlags
|
||||
|
||||
interface ZephyrConfigurables : TargetableConfigurables, ClangFlags {
|
||||
interface ZephyrConfigurables : Configurables, ClangFlags {
|
||||
val boardSpecificClangFlags get() = targetList("boardSpecificClangFlags")
|
||||
val targetAbi get() = targetString("targetAbi")
|
||||
}
|
||||
@@ -108,13 +108,13 @@ abstract class LinkerFlags(val configurables: Configurables) {
|
||||
class AndroidLinker(targetProperties: AndroidConfigurables)
|
||||
: LinkerFlags(targetProperties), AndroidConfigurables by targetProperties {
|
||||
|
||||
private val clangQuad = when (targetProperties.targetArg) {
|
||||
"arm-linux-androideabi" -> "armv7a-linux-androideabi"
|
||||
else -> targetProperties.targetArg
|
||||
private val clangTarget = when (val targetString = targetProperties.targetTriple.toString()) {
|
||||
"arm-unknown-linux-androideabi" -> "armv7a-unknown-linux-androideabi"
|
||||
else -> targetString
|
||||
}
|
||||
private val prefix = "$absoluteTargetToolchain/bin/${clangQuad}${Android.API}"
|
||||
private val prefix = "$absoluteTargetToolchain/bin/${clangTarget}${Android.API}"
|
||||
private val clang = if (HostManager.hostIsMingw) "$prefix-clang.cmd" else "$prefix-clang"
|
||||
private val ar = "$absoluteTargetToolchain/${targetProperties.targetArg}/bin/ar"
|
||||
private val ar = "$absoluteTargetToolchain/${targetProperties.targetTriple}/bin/ar"
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = true
|
||||
|
||||
@@ -136,7 +136,7 @@ class AndroidLinker(targetProperties: AndroidConfigurables)
|
||||
val toolchainSysroot = "${absoluteTargetToolchain}/sysroot"
|
||||
val architectureDir = Android.architectureDirForTarget(target)
|
||||
val apiSysroot = "$absoluteTargetSysRoot/$architectureDir"
|
||||
val clangTarget = targetArg!!
|
||||
val clangTarget = targetTriple.toString()
|
||||
val libDirs = listOf(
|
||||
"--sysroot=$apiSysroot",
|
||||
if (target == KonanTarget.ANDROID_X64) "-L$apiSysroot/usr/lib64" else "-L$apiSysroot/usr/lib",
|
||||
@@ -148,7 +148,7 @@ class AndroidLinker(targetProperties: AndroidConfigurables)
|
||||
+"-fPIC"
|
||||
+"-shared"
|
||||
+"-target"
|
||||
+targetArg!!
|
||||
+clangTarget
|
||||
+libDirs
|
||||
+objectFiles
|
||||
if (optimize) +linkerOptimizationFlags
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.konan.target
|
||||
|
||||
/**
|
||||
* Classical way to describe a target platform.
|
||||
* Despite it's name, may contain more or less than 3 components.
|
||||
*
|
||||
* Example: arm64-apple-ios-simulator.
|
||||
* - arm64 - target hardware.
|
||||
* - apple - vendor.
|
||||
* - ios - operating system.
|
||||
* - simulator - environment.
|
||||
*
|
||||
* @see <a href="https://clang.llvm.org/docs/CrossCompilation.html#target-triple">Clang documentation for target triple</a>.
|
||||
*/
|
||||
data class TargetTriple(
|
||||
val architecture: String,
|
||||
val vendor: String,
|
||||
val os: String,
|
||||
val environment: String?
|
||||
) {
|
||||
companion object {
|
||||
/**
|
||||
* Parse <arch>-<vendor>-<os>-<environment?> [tripleString].
|
||||
*
|
||||
* TODO: Support normalization like LLVM's Triple::normalize.
|
||||
*/
|
||||
fun fromString(tripleString: String): TargetTriple {
|
||||
val components = tripleString.split('-')
|
||||
// TODO: There might be other cases (e.g. of size 2 or 5),
|
||||
// but let's support only these for now.
|
||||
require(components.size == 3 || components.size == 4) {
|
||||
"Malformed target triple: $tripleString. Expected format: <arch>-<vendor>-<os>-<environment?>."
|
||||
}
|
||||
return TargetTriple(
|
||||
architecture = components[0],
|
||||
vendor = components[1],
|
||||
os = components[2],
|
||||
environment = components.getOrNull(3)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
val envSuffix = environment?.let { "-$environment" }
|
||||
?: ""
|
||||
return "$architecture-$vendor-$os$envSuffix"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user