Skip to content

Add build parameter to build coroutines with JVM IR compiler #2389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ buildscript {
throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
}
}
// These three flags are enabled in train builds for JVM IR compiler testing
ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
ext.jvm_ir_api_check_enabled = rootProject.properties['enable_jvm_ir_api_check'] != null
ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null

// Determine if any project dependency is using a snapshot version
ext.using_snapshot_version = build_snapshot_train
Expand Down Expand Up @@ -323,3 +327,12 @@ knit {
}

knitPrepare.dependsOn getTasksByName("dokka", true)

// Disable binary compatibility check for JVM IR compiler output by default
if (jvm_ir_enabled) {
subprojects { project ->
configure(tasks.matching { it.name == "apiCheck" }) {
enabled = enabled && jvm_ir_api_check_enabled
}
}
}
8 changes: 6 additions & 2 deletions gradle/compile-jvm-multiplatform.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ sourceCompatibility = 1.6
targetCompatibility = 1.6

kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
jvm {
if (rootProject.ext.jvm_ir_enabled) {
compilations.all {
kotlinOptions.useIR = true
}
}
}
sourceSets {
jvmTest.dependencies {
Expand Down
6 changes: 6 additions & 0 deletions gradle/compile-jvm.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ apply plugin: 'org.jetbrains.kotlin.jvm'
sourceCompatibility = 1.6
targetCompatibility = 1.6

if (rootProject.ext.jvm_ir_enabled) {
kotlin.target.compilations.all {
kotlinOptions.useIR = true
}
}

dependencies {
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
// Workaround to make addSuppressed work in tests
Expand Down
23 changes: 19 additions & 4 deletions kotlinx-coroutines-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle")
apply from: rootProject.file("gradle/compile-common.gradle")

if (rootProject.ext.native_targets_enabled) {
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
}

apply from: rootProject.file("gradle/compile-js-multiplatform.gradle")
apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
apply from: rootProject.file('gradle/publish-npm-js.gradle')

/* ==========================================================================
Expand Down Expand Up @@ -52,8 +56,11 @@ static boolean isNativeDarwin(String name) { return ["ios", "macos", "tvos", "wa
static boolean isNativeOther(String name) { return ["linux", "mingw"].any { name.startsWith(it) } }

defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }

if (rootProject.ext.native_targets_enabled) {
defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }
}

/* ========================================================================== */

Expand Down Expand Up @@ -129,7 +136,7 @@ def configureNativeSourceSetPreset(name, preset) {
}

// :KLUDGE: Idea.active: Configure platform libraries for native source sets when working in IDEA
if (Idea.active) {
if (Idea.active && rootProject.ext.native_targets_enabled) {
def manager = project.ext.hostManager
def linuxPreset = kotlin.presets.linuxX64
def macosPreset = kotlin.presets.macosX64
Expand Down Expand Up @@ -183,6 +190,14 @@ jvmTest {
exclude '**/*StressTest.*'
}
systemProperty 'kotlinx.coroutines.scheduler.keep.alive.sec', '100000' // any unpark problem hangs test

// TODO: JVM IR generates different stacktrace so temporary disable stacktrace tests
if (rootProject.ext.jvm_ir_enabled) {
filter {
excludeTest('kotlinx.coroutines.debug.CoroutinesDumpTest', 'testCreationStackTrace')
excludeTestsMatching('kotlinx.coroutines.exceptions.StackTraceRecovery*')
}
}
}

jvmJar {
Expand Down
10 changes: 10 additions & 0 deletions kotlinx-coroutines-debug/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ dependencies {
api "net.java.dev.jna:jna-platform:$jna_version"
}

// TODO: JVM IR generates different stacktrace so temporary disable stacktrace tests
if (rootProject.ext.jvm_ir_enabled) {
tasks.named('test', Test) {
filter {
excludeTest('kotlinx.coroutines.debug.CoroutinesDumpTest', 'testCreationStackTrace')
excludeTestsMatching('kotlinx.coroutines.debug.DebugProbesTest')
}
}
}

jar {
manifest {
attributes "Premain-Class": "kotlinx.coroutines.debug.AgentPremain"
Expand Down