[K/N] Move files, env interop generation to kotlin-native/common/

This commit is contained in:
Alexander Shabalin
2024-03-02 00:15:09 +01:00
committed by Space Team
parent 9f0a6537bb
commit ab62632a85
4 changed files with 52 additions and 66 deletions
-61
View File
@@ -5,9 +5,6 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.PlatformInfo import org.jetbrains.kotlin.PlatformInfo
import org.jetbrains.kotlin.cpp.CppConsumerPlugin
import org.jetbrains.kotlin.cpp.CppUsage
import org.jetbrains.kotlin.cpp.DependencyHandlerExKt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.tools.NativePluginKt import org.jetbrains.kotlin.tools.NativePluginKt
@@ -20,7 +17,6 @@ apply plugin: 'java'
apply plugin: 'kotlin' apply plugin: 'kotlin'
apply plugin: "native-interop-plugin" apply plugin: "native-interop-plugin"
apply plugin: "maven-publish" apply plugin: "maven-publish"
apply plugin: CppConsumerPlugin
sourceSets { sourceSets {
compiler { compiler {
@@ -46,8 +42,6 @@ compileCompilerKotlin {
} }
def tasksWithoutOptInUsage = [ def tasksWithoutOptInUsage = [
"compileEnvInteropStubsKotlin",
"compileFilesInteropStubsKotlin",
"compileLlvmInteropStubsKotlin" "compileLlvmInteropStubsKotlin"
] ]
tasks.withType(KotlinCompilationTask.class).configureEach { tasks.withType(KotlinCompilationTask.class).configureEach {
@@ -60,30 +54,6 @@ compileCli_bcKotlin {
compilerOptions.freeCompilerArgs.add('-Xskip-prerelease-check') compilerOptions.freeCompilerArgs.add('-Xskip-prerelease-check')
} }
configurations {
commonFilesBitcode {
canBeConsumed = false
canBeResolved = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE))
}
}
commonEnvBitcode {
canBeConsumed = false
canBeResolved = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, CppUsage.LLVM_BITCODE))
}
}
}
dependencies {
use(DependencyHandlerExKt) {
commonFilesBitcode module(project(":kotlin-native:common"), "files")
commonEnvBitcode module(project(":kotlin-native:common"), "env")
}
}
kotlinNativeInterop { kotlinNativeInterop {
llvm { llvm {
@@ -104,40 +74,11 @@ kotlinNativeInterop {
} }
linkerOpts "-L$llvmDir/lib", "-L${rootProject.project(':kotlin-native:llvmDebugInfoC').layout.buildDirectory.get().asFile}", "-L${rootProject.project(':kotlin-native:libllvmext').layout.buildDirectory.get().asFile}" linkerOpts "-L$llvmDir/lib", "-L${rootProject.project(':kotlin-native:llvmDebugInfoC').layout.buildDirectory.get().asFile}", "-L${rootProject.project(':kotlin-native:libllvmext').layout.buildDirectory.get().asFile}"
} }
files {
linker 'clang++'
link configurations.commonFilesBitcode
// TODO: These should come from some sort of commonFilesApi configuration
headers fileTree('../common/src/files/headers') {
include '**/*.h'
include '**/*.hpp'
}
pkg 'org.jetbrains.kotlin.backend.konan.files'
}
env {
linker 'clang++'
link configurations.commonEnvBitcode
// TODO: These should come from some sort of commonEnvApi configuration
headers fileTree('../common/src/env/headers') {
include '**/*.h'
include '**/*.hpp'
}
pkg 'org.jetbrains.kotlin.backend.konan.env'
}
} }
configurations { configurations {
compilerApi { compilerApi {
extendsFrom kotlinNativeInterop['llvm'].configuration extendsFrom kotlinNativeInterop['llvm'].configuration
extendsFrom kotlinNativeInterop['files'].configuration
extendsFrom kotlinNativeInterop['env'].configuration
} }
kotlin_compiler_jar kotlin_compiler_jar
kotlin_stdlib_jar kotlin_stdlib_jar
@@ -204,8 +145,6 @@ classes.dependsOn 'compilerClasses', 'cli_bcClasses'
tasks.named("jar") { tasks.named("jar") {
from sourceSets.cli_bc.output, from sourceSets.cli_bc.output,
sourceSets.compiler.output, sourceSets.compiler.output,
sourceSets.filesInteropStubs.output,
sourceSets.envInteropStubs.output,
sourceSets.llvmInteropStubs.output sourceSets.llvmInteropStubs.output
dependsOn 'external_jars' dependsOn 'external_jars'
+10
View File
@@ -163,6 +163,11 @@ configurations {
canBeConsumed = false canBeConsumed = false
canBeResolved = true canBeResolved = true
} }
nativeLibs {
canBeConsumed = false
canBeResolved = true
}
} }
apply plugin: CompilationDatabasePlugin apply plugin: CompilationDatabasePlugin
@@ -188,6 +193,7 @@ dependencies {
runtimeBitcode project(":kotlin-native:runtime") runtimeBitcode project(":kotlin-native:runtime")
objcExportApi project(":kotlin-native:runtime") objcExportApi project(":kotlin-native:runtime")
embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements') embeddableJar project(path: ':kotlin-native:prepare:kotlin-native-compiler-embeddable', configuration: 'runtimeElements')
nativeLibs project(path: ':kotlin-native:common', configuration: 'nativeLibs')
} }
apply plugin: GitClangFormatPlugin apply plugin: GitClangFormatPlugin
@@ -277,6 +283,10 @@ tasks.register("distCompiler", Copy) {
into('konan/nativelib') into('konan/nativelib')
} }
from(configurations.nativeLibs) {
into('konan/nativelib')
}
from(project(':kotlin-native:backend.native').file('build/external_jars/trove4j.jar')) { from(project(':kotlin-native:backend.native').file('build/external_jars/trove4j.jar')) {
into('konan/lib') into('konan/lib')
} }
+31 -6
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.konan.target.TargetWithSanitizer
/* /*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file. * that can be found in the LICENSE file.
@@ -6,6 +8,8 @@
plugins { plugins {
id("kotlin.native.build-tools-conventions") id("kotlin.native.build-tools-conventions")
id("compile-to-bitcode") id("compile-to-bitcode")
kotlin("jvm")
id("native-interop-plugin")
} }
bitcode { bitcode {
@@ -26,12 +30,33 @@ bitcode {
} }
} }
val hostName: String by project kotlinNativeInterop {
create("files") {
tasks.register("build") { pkg("org.jetbrains.kotlin.backend.konan.files")
dependsOn("${hostName}Common") linker("clang++")
linkOutputs(bitcode.hostTarget.module("files").get().sourceSets.main.get().task.get())
headers(layout.projectDirectory.files("src/files/headers/Files.h"))
} }
tasks.register<Delete>("clean") { create("env") {
delete(layout.buildDirectory) pkg("org.jetbrains.kotlin.backend.konan.env")
linker("clang++")
linkOutputs(bitcode.hostTarget.module("env").get().sourceSets.main.get().task.get())
headers(layout.projectDirectory.files("src/env/headers/Env.h"))
}
}
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["files"].genTask, kotlinNativeInterop["env"].genTask)
}
} }
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -10,6 +12,16 @@ dependencies {
implementation(project(":kotlin-native:klib")) implementation(project(":kotlin-native:klib"))
implementation(project(":kotlin-native:endorsedLibraries:kotlinx.cli", configuration = "jvmRuntimeElements")) implementation(project(":kotlin-native:endorsedLibraries:kotlinx.cli", configuration = "jvmRuntimeElements"))
implementation(project(":native:kotlin-native-utils")) implementation(project(":native:kotlin-native-utils"))
implementation(project(":kotlin-native:common", configuration = "filesInteropStubs"))
implementation(project(":kotlin-native:common", configuration = "envInteropStubs"))
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.optIn.addAll(
listOf(
"kotlinx.cinterop.ExperimentalForeignApi",
)
)
} }
sourceSets { sourceSets {