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

Support JVM IR compiler plugin in AtomicfuGradlePlugin #246

Merged
merged 8 commits into from Oct 18, 2022

Conversation

mvicsokolova
Copy link
Collaborator

  • Introduced new flags for application of JS and JVM compiler plugins: kotlinx.atomicfu.enableJsIrTransformation and kotlinx.atomicfu.enableJvmIrTransformation
  • Separate application of compiler plugins for both backends supported via the AtomicfuKotlinGradleExtension

Waiting to merge this PR after update to 1.7.20

@qwwdfsad
Copy link
Member

Why doesn't the build pass with RC?

@mvicsokolova
Copy link
Collaborator Author

This fix for kotlin.targets config in build.gradle should work

@qwwdfsad qwwdfsad self-requested a review September 19, 2022 09:05
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

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

Also, please add quite a few tests for that functionality:

  • Only JVM_IR transformation with Kotlin 1.7.0
  • Only JS_IR transformation with Kotlin 1.7.0
  • Both transformations

JVM tests worth adding for both MPP and JVM-only projects

@@ -29,16 +29,16 @@ private const val ORIGINAL_DIR_NAME = "originalClassesDir"
private const val COMPILE_ONLY_CONFIGURATION = "compileOnly"
private const val IMPLEMENTATION_CONFIGURATION = "implementation"
private const val TEST_IMPLEMENTATION_CONFIGURATION = "testImplementation"
private const val ENABLE_IR_TRANSFORMATION = "kotlinx.atomicfu.enableIrTransformation"
private const val ENABLE_JS_IR_TRANSFORMATION_LEGACY = "kotlinx.atomicfu.enableIrTransformation"
Copy link
Member

Choose a reason for hiding this comment

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

Please leave a comment why it is legacy and when it is safe to remove it

// for KGP >= 1.7.20:
// compiler plugin for JS IR is applied via the property `kotlinx.atomicfu.enableJsIrTransformation`
// compiler plugin for JVM IR is applied via the property `kotlinx.atomicfu.enableJvmIrTransformation`
if (kotlinVersion.major == 1 && (kotlinVersion.minor == 7 && kotlinVersion.patch >= 20 || kotlinVersion.minor > 7)) {
Copy link
Member

Choose a reason for hiding this comment

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

You have at least three duplicating checks, each of them requires non-trivial effort to see if it's correct.
I suggest introducing something like if (kotlinVersion.atLeast(1, 7, 20) and use it everywhere

@@ -109,7 +141,8 @@ private fun String.toBooleanStrict(): Boolean = when (this) {
}

private fun Project.needsJsIrTransformation(target: KotlinTarget): Boolean =
rootProject.getBooleanProperty(ENABLE_IR_TRANSFORMATION) && target.isJsIrTarget()
(rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION) || rootProject.getBooleanProperty(ENABLE_JS_IR_TRANSFORMATION_LEGACY))
&& target.isJsIrTarget()

private fun KotlinTarget.isJsIrTarget() = (this is KotlinJsTarget && this.irTarget != null) || this is KotlinJsIrTarget
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't addCompilerPluginDependency add dependency for JVM transformation as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, the atomicfu-runtime dependency is required by the JS plugin only

@mvicsokolova mvicsokolova merged commit d6ecd36 into develop Oct 18, 2022
@mvicsokolova mvicsokolova deleted the support-jvmir-compiler-plugin branch October 18, 2022 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants