Skip to content

Commit

Permalink
Enable JS IR backend (#1832)
Browse files Browse the repository at this point in the history
* Enable JS IR backend
* Workaround resolving Gradle metadata in kotlin2js plugin

Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
  • Loading branch information
skuzmich and qwwdfsad authored Mar 11, 2020
1 parent 03f4e84 commit fa97af2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ robolectric_version=4.0.2
baksmali_version=2.2.7

# JS
kotlin.js.compiler=both
gradle_node_version=1.2.0
node_version=8.9.3
npm_version=5.7.1
Expand All @@ -43,3 +44,7 @@ kotlin.native.ignoreDisabledTargets=true

# Site deneration
jekyll_version=4.0

# JS IR baceknd sometimes crashes with out-of-memory
# TODO: Remove once KT-37187 is fixed
org.gradle.jvmargs=-Xmx2g
17 changes: 15 additions & 2 deletions gradle/compile-js-multiplatform.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ apply from: rootProject.file('gradle/node-js.gradle')

kotlin {
targets {
fromPreset(presets.js, 'js')
fromPreset(presets.js, 'js') {
// Enable built-in test runner only for IR target.
// These runners don't support changing js module name change.
if (js.hasProperty("irTarget")) {
irTarget.nodejs()
irTarget?.compilations['main']?.dependencies {
api "org.jetbrains.kotlinx:atomicfu-js:$atomicfu_version"
}
}
}
}

sourceSets {
Expand Down Expand Up @@ -41,12 +50,16 @@ compileTestKotlinJs {
kotlinOptions.moduleKind = 'umd'
}


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

def configuration = configurations.jsTestRuntimeClasspath
def configuration = configurations.hasProperty("legacyjsTestRuntimeClasspath")
? configurations.legacyjsTestRuntimeClasspath
: configurations.jsTestRuntimeClasspath

from(files {
configuration.collect { File file ->
file.name.endsWith(".jar") ?
Expand Down
4 changes: 2 additions & 2 deletions gradle/publish-bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ publishing {
break
}

// disable metadata everywhere, but in native modules
if (type == 'maven' || type == 'metadata' || type == 'jvm' || type == 'js') {
// disable metadata everywhere, but in native and js modules
if (type == 'maven' || type == 'metadata' || type == 'jvm') {
moduleDescriptorGenerator = null
}
}
Expand Down
6 changes: 4 additions & 2 deletions gradle/test-mocha-js.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlinJs, installDepen
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
}

jsTest.dependsOn testMochaNode
def legacyjsTestTask = project.tasks.findByName('legacyjsTest') ? legacyjsTest : jsTest

legacyjsTestTask.dependsOn testMochaNode

// -- Testing with Mocha under headless Chrome

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

jsTest.dependsOn testMochaJsdom
legacyjsTestTask.dependsOn testMochaJsdom

18 changes: 18 additions & 0 deletions js/example-frontend-js/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
apply plugin: 'kotlin-dce-js'
apply from: rootProject.file('gradle/node-js.gradle')

// Workaround resolving new Gradle metadata with kotlin2js
// TODO: Remove once KT-37188 is fixed
try {
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.JsCompilerType")
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
configurations {
matching {
it.name.endsWith("Classpath")
}.forEach {
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
}
}
} catch (java.lang.ClassNotFoundException e) {
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
}

dependencies {
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
}
Expand Down

0 comments on commit fa97af2

Please sign in to comment.