Fix clang usage in backend.native:tests
For Apple Silicon targets we need to call Clang 1. From toolchain because the one from our distro is too old. 2. With appropriate flags for setting the sysroot.
This commit is contained in:
committed by
TeamCityServer
parent
437a0aa450
commit
7b06249e7f
@@ -4214,7 +4214,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/smoke.m"
|
args "$projectDir/interop/objc/smoke.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcsmoke.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcsmoke.dylib"
|
||||||
@@ -4240,7 +4240,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args fileTree("$projectDir/interop/objc/tests/") { include '**/*.m' }
|
args fileTree("$projectDir/interop/objc/tests/") { include '**/*.m' }
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjctests.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjctests.dylib"
|
||||||
@@ -4260,7 +4260,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc_with_initializer/objc_misc.m"
|
args "$projectDir/interop/objc_with_initializer/objc_misc.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcmisc.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcmisc.dylib"
|
||||||
@@ -4277,7 +4277,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/msg_send/messaging.m"
|
args "$projectDir/interop/objc/msg_send/messaging.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcmessaging.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcmessaging.dylib"
|
||||||
@@ -4295,7 +4295,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
||||||
@@ -4314,7 +4314,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
||||||
@@ -4333,7 +4333,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
args "$projectDir/interop/objc/foreignException/objc_wrap.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjcexception.dylib"
|
||||||
@@ -4372,7 +4372,7 @@ if (PlatformInfo.isAppleTarget(project)) {
|
|||||||
|
|
||||||
doBeforeBuild {
|
doBeforeBuild {
|
||||||
mkdir(buildDir)
|
mkdir(buildDir)
|
||||||
execKonanClang(project.target) {
|
execClangForCompilerTests(project.target) {
|
||||||
args "$projectDir/interop/objc/kt42172/objclib.m"
|
args "$projectDir/interop/objc/kt42172/objclib.m"
|
||||||
args "-lobjc", '-fobjc-arc'
|
args "-lobjc", '-fobjc-arc'
|
||||||
args '-fPIC', '-shared', '-o', "$buildDir/libobjc_kt42172.dylib"
|
args '-fPIC', '-shared', '-o', "$buildDir/libobjc_kt42172.dylib"
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ open class GenerateCompilationDatabase @Inject constructor(@Input val target: St
|
|||||||
fun run() {
|
fun run() {
|
||||||
val plugin = project.convention.getPlugin(ExecClang::class.java)
|
val plugin = project.convention.getPlugin(ExecClang::class.java)
|
||||||
val executable = plugin.resolveExecutable(executable)
|
val executable = plugin.resolveExecutable(executable)
|
||||||
val args = listOf(executable) + compilerFlags + plugin.konanArgs(target)
|
val args = listOf(executable) + compilerFlags + plugin.clangArgsForCppRuntime(target)
|
||||||
val entries: List<Entry> = files.map { Entry.create(srcRoot, it, args, outputDir) }
|
val entries: List<Entry> = files.map { Entry.create(srcRoot, it, args, outputDir) }
|
||||||
Entry.writeListTo(outputFile, entries)
|
Entry.writeListTo(outputFile, entries)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ class ExecClang(private val project: Project) {
|
|||||||
|
|
||||||
private val platformManager = project.project(":kotlin-native").findProperty("platformManager") as PlatformManager
|
private val platformManager = project.project(":kotlin-native").findProperty("platformManager") as PlatformManager
|
||||||
|
|
||||||
private fun konanArgs(target: KonanTarget): List<String> {
|
private fun clangArgsForCppRuntime(target: KonanTarget): List<String> {
|
||||||
return platformManager.platform(target).clang.clangArgsForKonanSources.asList()
|
return platformManager.platform(target).clang.clangArgsForKonanSources.asList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun konanArgs(targetName: String?): List<String> {
|
fun clangArgsForCppRuntime(targetName: String?): List<String> {
|
||||||
val target = platformManager.targetManager(targetName).target
|
val target = platformManager.targetManager(targetName).target
|
||||||
return konanArgs(target)
|
return clangArgsForCppRuntime(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveExecutable(executableOrNull: String?): String {
|
fun resolveExecutable(executableOrNull: String?): String {
|
||||||
@@ -82,21 +82,46 @@ class ExecClang(private val project: Project) {
|
|||||||
// (nullable, which means host) target name.
|
// (nullable, which means host) target name.
|
||||||
|
|
||||||
fun execKonanClang(target: String?, action: Action<in ExecSpec>): ExecResult {
|
fun execKonanClang(target: String?, action: Action<in ExecSpec>): ExecResult {
|
||||||
return this.execClang(konanArgs(target), action)
|
return this.execClang(clangArgsForCppRuntime(target), action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execKonanClang(target: KonanTarget, action: Action<in ExecSpec>): ExecResult {
|
fun execKonanClang(target: KonanTarget, action: Action<in ExecSpec>): ExecResult {
|
||||||
return this.execClang(konanArgs(target), action)
|
return this.execClang(clangArgsForCppRuntime(target), action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execKonanClang(target: String?, closure: Closure<in ExecSpec>): ExecResult {
|
fun execKonanClang(target: String?, closure: Closure<in ExecSpec>): ExecResult {
|
||||||
return this.execClang(konanArgs(target), closure)
|
return this.execClang(clangArgsForCppRuntime(target), closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execKonanClang(target: KonanTarget, closure: Closure<in ExecSpec>): ExecResult {
|
fun execKonanClang(target: KonanTarget, closure: Closure<in ExecSpec>): ExecResult {
|
||||||
return this.execClang(konanArgs(target), closure)
|
return this.execClang(clangArgsForCppRuntime(target), closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute Clang the way that produced object file is compatible with
|
||||||
|
* the one that produced by Kotlin/Native for given [target]. It means:
|
||||||
|
* 1. We pass flags that set sysroot.
|
||||||
|
* 2. We call Clang from toolchain in case of Apple target.
|
||||||
|
*/
|
||||||
|
fun execClangForCompilerTests(target: KonanTarget, action: Action<in ExecSpec>): ExecResult {
|
||||||
|
val defaultArgs = platformManager.platform(target).clang.clangArgs
|
||||||
|
return project.exec(Action<ExecSpec> {
|
||||||
|
action.execute(this)
|
||||||
|
executable = if (target.family.isAppleFamily) {
|
||||||
|
resolveToolchainExecutable(target, executable)
|
||||||
|
} else {
|
||||||
|
resolveExecutable(executable)
|
||||||
|
}
|
||||||
|
args = defaultArgs + args
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see execClangForCompilerTests
|
||||||
|
*/
|
||||||
|
fun execClangForCompilerTests(target: KonanTarget, closure: Closure<in ExecSpec>): ExecResult =
|
||||||
|
execClangForCompilerTests(target, ConfigureUtil.configureUsing(closure))
|
||||||
|
|
||||||
// The toolchain ones execute clang from the toolchain.
|
// The toolchain ones execute clang from the toolchain.
|
||||||
|
|
||||||
fun execToolchainClang(target: String?, action: Action<in ExecSpec>): ExecResult {
|
fun execToolchainClang(target: String?, action: Action<in ExecSpec>): ExecResult {
|
||||||
@@ -119,8 +144,6 @@ class ExecClang(private val project: Project) {
|
|||||||
return this.execToolchainClang(target, ConfigureUtil.configureUsing(closure))
|
return this.execToolchainClang(target, ConfigureUtil.configureUsing(closure))
|
||||||
}
|
}
|
||||||
|
|
||||||
// These ones are private, so one has to choose either Bare or Konan.
|
|
||||||
|
|
||||||
private fun execClang(defaultArgs: List<String>, closure: Closure<in ExecSpec>): ExecResult {
|
private fun execClang(defaultArgs: List<String>, closure: Closure<in ExecSpec>): ExecResult {
|
||||||
return this.execClang(defaultArgs, ConfigureUtil.configureUsing(closure))
|
return this.execClang(defaultArgs, ConfigureUtil.configureUsing(closure))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,11 +376,8 @@ fun Project.buildStaticLibrary(cSources: Collection<File>, output: File, objDir:
|
|||||||
val platform = platformManager.platform(testTarget)
|
val platform = platformManager.platform(testTarget)
|
||||||
|
|
||||||
objDir.mkdirs()
|
objDir.mkdirs()
|
||||||
exec {
|
ExecClang(project).execClangForCompilerTests(testTarget) {
|
||||||
commandLine(platform.clang.clangC(
|
args = listOf("-c", *cSources.map { it.absolutePath }.toTypedArray())
|
||||||
"-c",
|
|
||||||
*cSources.map { it.absolutePath }.toTypedArray()
|
|
||||||
))
|
|
||||||
workingDir(objDir)
|
workingDir(objDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user