diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle index 66e3e4525a7..9031ff1b14c 100644 --- a/kotlin-native/backend.native/build.gradle +++ b/kotlin-native/backend.native/build.gradle @@ -4,9 +4,7 @@ */ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask -import org.jetbrains.kotlin.PlatformInfo import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.tools.NativePluginKt buildscript { @@ -15,7 +13,6 @@ buildscript { apply plugin: 'java' apply plugin: 'kotlin' -apply plugin: "native-interop-plugin" apply plugin: "maven-publish" sourceSets { @@ -41,45 +38,15 @@ compileCompilerKotlin { compilerOptions.freeCompilerArgs.add('-Xskip-prerelease-check') } -def tasksWithoutOptInUsage = [ - "compileLlvmInteropStubsKotlin" -] tasks.withType(KotlinCompilationTask.class).configureEach { - if (!tasksWithoutOptInUsage.contains(name)) { - compilerOptions.optIn.add("org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI") - } + compilerOptions.optIn.add("org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI") } compileCli_bcKotlin { compilerOptions.freeCompilerArgs.add('-Xskip-prerelease-check') } -kotlinNativeInterop { - llvm { - - dependsOn ":kotlin-native:llvmDebugInfoC:${NativePluginKt.lib("debugInfo")}" - dependsOn ":kotlin-native:libllvmext:${NativePluginKt.lib("llvmext")}" - defFile 'llvm.def' - compilerOpts "-I$llvmDir/include", "-I${rootProject.project(':kotlin-native:llvmDebugInfoC').projectDir}/src/main/include", "-I${rootProject.project(':kotlin-native:libllvmext').projectDir}/src/main/include" - if (PlatformInfo.isMac()) { - // $llvmDir/lib contains libc++.1.dylib too, and it seems to be preferred by the linker - // over the sysroot-provided one. - // As a result, libllvmstubs.dylib gets linked with $llvmDir/lib/libc++.1.dylib. - // It has install_name = @rpath/libc++.1.dylib, which won't work for us, because - // dynamic loader won't be able to find libc++ when loading libllvmstubs. - // For some reason, this worked fine before macOS 12.3. - // - // To enforce linking with proper libc++, pass the default path explicitly: - linkerOpts "-L${hostPlatform.absoluteTargetSysRoot}/usr/lib" - } - linkerOpts "-L$llvmDir/lib", "-L${rootProject.project(':kotlin-native:llvmDebugInfoC').layout.buildDirectory.get().asFile}", "-L${rootProject.project(':kotlin-native:libllvmext').layout.buildDirectory.get().asFile}" - } -} - configurations { - compilerApi { - extendsFrom kotlinNativeInterop['llvm'].configuration - } kotlin_compiler_jar kotlin_stdlib_jar kotlin_reflect_jar @@ -111,6 +78,7 @@ dependencies { compilerApi project(":native:objcexport-header-generator-k1") compilerApi project(":native:base") + compilerApi project(path: ":kotlin-native:llvmInterop", configuration: "llvmInteropStubs") compilerApi project(":native:kotlin-native-utils") compilerApi project(":core:descriptors") compilerApi project(":core:compiler.common.native") @@ -144,8 +112,7 @@ classes.dependsOn 'compilerClasses', 'cli_bcClasses' tasks.named("jar") { from sourceSets.cli_bc.output, - sourceSets.compiler.output, - sourceSets.llvmInteropStubs.output + sourceSets.compiler.output dependsOn 'external_jars' } diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 5f8f85b4aa8..8f9739c7434 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -194,6 +194,7 @@ dependencies { objcExportApi project(":kotlin-native:runtime") embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements') nativeLibs project(path: ':kotlin-native:common', configuration: 'nativeLibs') + nativeLibs project(path: ':kotlin-native:llvmInterop', configuration: 'nativeLibs') } apply plugin: GitClangFormatPlugin @@ -279,10 +280,6 @@ tasks.register("distCompiler", Copy) { destinationDir distDir - from(project(':kotlin-native:backend.native').file("build/nativelibs/$hostName")) { - into('konan/nativelib') - } - from(configurations.nativeLibs) { into('konan/nativelib') } diff --git a/kotlin-native/llvmInterop/build.gradle.kts b/kotlin-native/llvmInterop/build.gradle.kts new file mode 100644 index 00000000000..7171e439b20 --- /dev/null +++ b/kotlin-native/llvmInterop/build.gradle.kts @@ -0,0 +1,44 @@ +import org.jetbrains.kotlin.PlatformInfo +import org.jetbrains.kotlin.konan.target.TargetWithSanitizer +import org.jetbrains.kotlin.tools.lib + +plugins { + kotlin("jvm") + id("native-interop-plugin") +} + +kotlinNativeInterop { + create("llvm") { + dependsOn(":kotlin-native:llvmDebugInfoC:${lib("debugInfo")}") + dependsOn(":kotlin-native:libllvmext:${lib("llvmext")}") + defFile("llvm.def") + compilerOpts("-I$llvmDir/include", "-I${rootProject.project(":kotlin-native:llvmDebugInfoC").projectDir}/src/main/include", "-I${rootProject.project(":kotlin-native:libllvmext").projectDir}/src/main/include") + if (PlatformInfo.isMac()) { + // $llvmDir/lib contains libc++.1.dylib too, and it seems to be preferred by the linker + // over the sysroot-provided one. + // As a result, libllvmstubs.dylib gets linked with $llvmDir/lib/libc++.1.dylib. + // It has install_name = @rpath/libc++.1.dylib, which won't work for us, because + // dynamic loader won't be able to find libc++ when loading libllvmstubs. + // For some reason, this worked fine before macOS 12.3. + // + // To enforce linking with proper libc++, pass the default path explicitly: + linkerOpts("-L${hostPlatform.absoluteTargetSysRoot}/usr/lib") + } + linkerOpts("-L$llvmDir/lib", "-L${rootProject.project(":kotlin-native:llvmDebugInfoC").layout.buildDirectory.get().asFile}", "-L${rootProject.project(":kotlin-native:libllvmext").layout.buildDirectory.get().asFile}") + } +} + +val nativeLibs by configurations.creating { + isCanBeConsumed = true + isCanBeResolved = false + attributes { + attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE) + attribute(TargetWithSanitizer.TARGET_ATTRIBUTE, TargetWithSanitizer.host) + } +} + +artifacts { + add(nativeLibs.name, layout.buildDirectory.dir("nativelibs/${TargetWithSanitizer.host}")) { + builtBy(kotlinNativeInterop["llvm"].genTask) + } +} \ No newline at end of file diff --git a/kotlin-native/backend.native/llvm.def b/kotlin-native/llvmInterop/llvm.def similarity index 100% rename from kotlin-native/backend.native/llvm.def rename to kotlin-native/llvmInterop/llvm.def diff --git a/kotlin-native/backend.native/llvm.list b/kotlin-native/llvmInterop/llvm.list similarity index 100% rename from kotlin-native/backend.native/llvm.list rename to kotlin-native/llvmInterop/llvm.list diff --git a/settings.gradle b/settings.gradle index eee3cee708e..289929ea105 100644 --- a/settings.gradle +++ b/settings.gradle @@ -895,6 +895,7 @@ if (buildProperties.isKotlinNativeEnabled) { include ':kotlin-native:utilities' include ':kotlin-native:platformLibs' include ':kotlin-native:libclangext' + include ':kotlin-native:llvmInterop' include ':kotlin-native:backend.native:tests' include ':kotlin-native:prepare:kotlin-native-compiler-embeddable' include ':native:kotlin-test-native-xctest'