Skip to content
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

Enable JS IR backend #1832

Merged
merged 4 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
# 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()
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it going to break our releases with Kotlin 1.3.70? Do we really have to publish metadata if IR BE is not here?

Copy link
Member Author

@skuzmich skuzmich Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really have to publish metadata if IR BE is not here?

We don't

Isn't it going to break our releases with Kotlin 1.3.70?

I assumed adding metadata wouldn't break stuff. @ilgonmic please take a look

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Gradle 5.3 it can consume metadata for dependency from repo. So for this version range it should not break release.
But this check can be covered with plus one check on 1.4 release, and not publish metadata for 1.3.70 releases

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
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved

// -- 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