Skip to content

Commit fa97af2

Browse files
skuzmichqwwdfsad
andauthored
Enable JS IR backend (#1832)
* Enable JS IR backend * Workaround resolving Gradle metadata in kotlin2js plugin Co-authored-by: Vsevolod Tolstopyatov <[email protected]>
1 parent 03f4e84 commit fa97af2

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

gradle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ robolectric_version=4.0.2
2929
baksmali_version=2.2.7
3030

3131
# JS
32+
kotlin.js.compiler=both
3233
gradle_node_version=1.2.0
3334
node_version=8.9.3
3435
npm_version=5.7.1
@@ -43,3 +44,7 @@ kotlin.native.ignoreDisabledTargets=true
4344

4445
# Site deneration
4546
jekyll_version=4.0
47+
48+
# JS IR baceknd sometimes crashes with out-of-memory
49+
# TODO: Remove once KT-37187 is fixed
50+
org.gradle.jvmargs=-Xmx2g

gradle/compile-js-multiplatform.gradle

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ apply from: rootProject.file('gradle/node-js.gradle')
66

77
kotlin {
88
targets {
9-
fromPreset(presets.js, 'js')
9+
fromPreset(presets.js, 'js') {
10+
// Enable built-in test runner only for IR target.
11+
// These runners don't support changing js module name change.
12+
if (js.hasProperty("irTarget")) {
13+
irTarget.nodejs()
14+
irTarget?.compilations['main']?.dependencies {
15+
api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
16+
}
17+
}
18+
}
1019
}
1120

1221
sourceSets {
@@ -41,12 +50,16 @@ compileTestKotlinJs {
4150
kotlinOptions.moduleKind = 'umd'
4251
}
4352

53+
4454
task populateNodeModules(type: Copy, dependsOn: compileTestKotlinJs) {
4555
// we must copy output that is transformed by atomicfu
4656
from(kotlin.targets.js.compilations.main.output.allOutputs)
4757
into "$node.nodeModulesDir/node_modules"
4858

49-
def configuration = configurations.jsTestRuntimeClasspath
59+
def configuration = configurations.hasProperty("legacyjsTestRuntimeClasspath")
60+
? configurations.legacyjsTestRuntimeClasspath
61+
: configurations.jsTestRuntimeClasspath
62+
5063
from(files {
5164
configuration.collect { File file ->
5265
file.name.endsWith(".jar") ?

gradle/publish-bintray.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ publishing {
8989
break
9090
}
9191

92-
// disable metadata everywhere, but in native modules
93-
if (type == 'maven' || type == 'metadata' || type == 'jvm' || type == 'js') {
92+
// disable metadata everywhere, but in native and js modules
93+
if (type == 'maven' || type == 'metadata' || type == 'jvm') {
9494
moduleDescriptorGenerator = null
9595
}
9696
}

gradle/test-mocha-js.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlinJs, installDepen
1919
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
2020
}
2121

22-
jsTest.dependsOn testMochaNode
22+
def legacyjsTestTask = project.tasks.findByName('legacyjsTest') ? legacyjsTest : jsTest
23+
24+
legacyjsTestTask.dependsOn testMochaNode
2325

2426
// -- Testing with Mocha under headless Chrome
2527

@@ -89,5 +91,5 @@ task testMochaJsdom(type: NodeTask, dependsOn: [compileTestKotlinJs, installDepe
8991
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
9092
}
9193

92-
jsTest.dependsOn testMochaJsdom
94+
legacyjsTestTask.dependsOn testMochaJsdom
9395

js/example-frontend-js/build.gradle

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
apply plugin: 'kotlin-dce-js'
66
apply from: rootProject.file('gradle/node-js.gradle')
77

8+
// Workaround resolving new Gradle metadata with kotlin2js
9+
// TODO: Remove once KT-37188 is fixed
10+
try {
11+
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.JsCompilerType")
12+
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
13+
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
14+
configurations {
15+
matching {
16+
it.name.endsWith("Classpath")
17+
}.forEach {
18+
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
19+
}
20+
}
21+
} catch (java.lang.ClassNotFoundException e) {
22+
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
23+
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
24+
}
25+
826
dependencies {
927
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
1028
}

0 commit comments

Comments
 (0)