Skip to content

Commit 19f56ab

Browse files
committed
Add api kotlinx-atomicfu dependency for JS and WASM targets.
Fixes #448
1 parent 5119e1a commit 19f56ab

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ private fun Project.configureMultiplatformPluginDependencies(version: String) {
132132
}
133133
}
134134
}
135-
// atomicfu should also appear in apiElements config for native targets,
135+
// atomicfu should also appear in apiElements config for Kotlin/Native, JS and WASM targets,
136136
// otherwise the warning is triggered, see: KT-64109
137137
multiplatformExtension.targets
138-
.matching { target -> target.platformType == KotlinPlatformType.native }
138+
.matching { target ->
139+
target.platformType == KotlinPlatformType.native ||
140+
target.platformType == KotlinPlatformType.wasm ||
141+
target.platformType == KotlinPlatformType.js
142+
}
139143
.all { target ->
140144
target.compilations.all { compilation ->
141145
compilation

integration-testing/examples/mpp-sample/build.gradle.kts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ repositories {
2222
kotlin {
2323
jvm()
2424

25-
js()
25+
js {
26+
nodejs()
27+
}
2628

27-
wasmJs {}
28-
wasmWasi {}
29+
wasmJs {
30+
nodejs()
31+
}
32+
wasmWasi {
33+
nodejs()
34+
}
2935

3036
macosArm64()
3137
macosX64()

integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/JvmProjectTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ class JvmProjectTest {
1515
@Test
1616
fun testJvmWithEnabledIrTransformation() {
1717
jvmSample.enableJvmIrTransformation = true
18-
jvmSample.checkJvmCompileOnlyDependencies()
18+
jvmSample.jvmCheckAtomicfuInCompileClasspath()
19+
jvmSample.jvmCheckNoAtomicfuInRuntimeConfigs()
1920
jvmSample.checkConsumableDependencies()
2021
jvmSample.buildAndCheckBytecode()
2122
}
2223

2324
@Test
2425
fun testJvmWithDisabledIrTransformation() {
2526
jvmSample.enableJvmIrTransformation = false
26-
jvmSample.checkJvmCompileOnlyDependencies()
27+
jvmSample.jvmCheckAtomicfuInCompileClasspath()
28+
jvmSample.jvmCheckNoAtomicfuInRuntimeConfigs()
2729
jvmSample.checkConsumableDependencies()
2830
jvmSample.buildAndCheckBytecode()
2931
}

integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/cases/MppProjectTest.kt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ class MppProjectTest {
1414
@Test
1515
fun testMppWithEnabledJvmIrTransformation() {
1616
mppSample.enableJvmIrTransformation = true
17-
mppSample.checkMppJvmCompileOnlyDependencies()
17+
mppSample.mppCheckAtomicfuInCompileClasspath("jvm")
18+
mppSample.mppCheckNoAtomicfuInRuntimeConfigs("jvm")
1819
mppSample.checkConsumableDependencies()
1920
mppSample.buildAndCheckBytecode()
2021
}
2122

2223
@Test
2324
fun testMppWithDisabledJvmIrTransformation() {
2425
mppSample.enableJvmIrTransformation = false
25-
mppSample.checkMppJvmCompileOnlyDependencies()
26+
mppSample.mppCheckAtomicfuInCompileClasspath("jvm")
27+
mppSample.mppCheckNoAtomicfuInRuntimeConfigs("jvm")
2628
mppSample.checkConsumableDependencies()
2729
mppSample.buildAndCheckBytecode()
2830
}
@@ -33,28 +35,42 @@ class MppProjectTest {
3335
mppSample.enableJsIrTransformation = true
3436
mppSample.cleanAndBuild()
3537
mppSample.checkConsumableDependencies()
38+
mppSample.mppCheckAtomicfuInApi("js")
3639
}
3740

3841
@Test
3942
fun testMppWithDisabledJsIrTransformation() {
4043
mppSample.enableJsIrTransformation = false
4144
mppSample.cleanAndBuild()
4245
mppSample.checkConsumableDependencies()
46+
mppSample.mppCheckAtomicfuInApi("js")
4347
}
4448

4549
@Test
46-
fun testMppWasmBuild() {
50+
fun testMppWasmJsBuild() {
4751
mppSample.cleanAndBuild()
48-
mppSample.checkMppWasmJsImplementationDependencies()
49-
mppSample.checkMppWasmWasiImplementationDependencies()
52+
mppSample.mppCheckAtomicfuInCompileClasspath("wasmJs")
53+
mppSample.mppCheckAtomicfuInRuntimeClasspath("wasmJs")
54+
mppSample.checkConsumableDependencies()
55+
mppSample.mppCheckAtomicfuInApi("wasmJs")
56+
}
57+
58+
@Test
59+
fun testMppWasmWasiBuild() {
60+
mppSample.mppCheckAtomicfuInCompileClasspath("wasmWasi")
61+
mppSample.mppCheckAtomicfuInRuntimeClasspath("wasmWasi")
62+
mppSample.checkConsumableDependencies()
63+
mppSample.mppCheckAtomicfuInApi("wasmWasi")
5064
}
5165

5266
@Test
5367
fun testMppNativeWithEnabledIrTransformation() {
5468
mppSample.enableNativeIrTransformation = true
5569
mppSample.cleanAndBuild()
5670
// When Native IR transformations are applied, atomicfu-gradle-plugin still provides transitive atomicfu dependency
57-
mppSample.checkMppNativeImplementationDependencies()
71+
mppSample.mppNativeCheckAtomicfuInImplementation()
72+
mppSample.checkConsumableDependencies()
73+
mppSample.mppCheckAtomicfuInApi("macosX64")
5874
// TODO: klib checks are skipped for now because of this problem KT-61143
5975
//mppSample.buildAndCheckNativeKlib()
6076
}
@@ -63,7 +79,9 @@ class MppProjectTest {
6379
fun testMppNativeWithDisabledIrTransformation() {
6480
mppSample.enableNativeIrTransformation = false
6581
mppSample.cleanAndBuild()
66-
mppSample.checkMppNativeImplementationDependencies()
82+
mppSample.mppNativeCheckAtomicfuInImplementation()
83+
mppSample.checkConsumableDependencies()
84+
mppSample.mppCheckAtomicfuInApi("macosX64")
6785
// TODO: klib checks are skipped for now because of this problem KT-61143
6886
//mppSample.buildAndCheckNativeKlib()
6987
}

integration-testing/src/functionalTest/kotlin/kotlinx.atomicfu.gradle.plugin.test/framework/checker/DependenciesChecker.kt

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,47 @@ private fun GradleBuild.checkAtomicfuDependencyIsAbsent(configurations: List<Str
2424
val dependencies = dependencies()
2525
for (config in configurations) {
2626
val configDependencies = dependencies.getDependenciesForConfig(config)
27-
check(!configDependencies.contains(atomicfuDependency)) { "Dependency $atomicfuDependency should be compileOnly, but it was found in the configuration: $config" }
27+
check(!configDependencies.contains(atomicfuDependency)) { "Dependency $atomicfuDependency should not be present in the configuration: $config" }
2828
}
2929
}
3030

31+
internal fun GradleBuild.jvmCheckAtomicfuInCompileClasspath() {
32+
checkAtomicfuDependencyIsPresent(listOf("compileClasspath"), jvmAtomicfuDependency)
33+
}
34+
35+
internal fun GradleBuild.mppCheckAtomicfuInCompileClasspath(targetName: String) {
36+
checkAtomicfuDependencyIsPresent(listOf("${targetName}CompileClasspath"), commonAtomicfuDependency)
37+
}
38+
39+
internal fun GradleBuild.mppCheckAtomicfuInRuntimeClasspath(targetName: String) {
40+
checkAtomicfuDependencyIsPresent(listOf("${targetName}CompileClasspath"), commonAtomicfuDependency)
41+
}
42+
3143
/**
32-
* For JVM there are 4 final configurations:
44+
* There are 4 final configurations:
3345
* compileClasspath — compile dependencies
3446
* runtimeClasspath — runtime dependencies
3547
* apiElements — compile dependencies that will be included in publication
3648
* runtimeElements — runtime dependencies that will be included in publication
3749
*
38-
* The functions below check that `org.jetbrains.kotlinx:atomicfu` dependency is only included in compile configurations.
50+
* The functions below check that `org.jetbrains.kotlinx:atomicfu` dependency is not present in the runtime configurations.
3951
*/
4052

41-
// Checks a simple JVM project with a single target
42-
internal fun GradleBuild.checkJvmCompileOnlyDependencies() {
43-
checkAtomicfuDependencyIsPresent(listOf("compileClasspath"), jvmAtomicfuDependency)
53+
internal fun GradleBuild.jvmCheckNoAtomicfuInRuntimeConfigs() {
4454
checkAtomicfuDependencyIsAbsent(listOf("runtimeClasspath", "apiElements", "runtimeElements"), jvmAtomicfuDependency)
4555
}
4656

47-
// Checks JVM target of an MPP project
48-
internal fun GradleBuild.checkMppJvmCompileOnlyDependencies() {
49-
checkAtomicfuDependencyIsPresent(listOf("jvmCompileClasspath"), commonAtomicfuDependency)
50-
checkAtomicfuDependencyIsAbsent(listOf("jvmRuntimeClasspath", "jvmApiElements", "jvmRuntimeElements"), commonAtomicfuDependency)
51-
}
52-
53-
// Checks wasmJs target of an MPP project
54-
internal fun GradleBuild.checkMppWasmJsImplementationDependencies() {
55-
checkAtomicfuDependencyIsPresent(listOf("wasmJsCompileClasspath", "wasmJsRuntimeClasspath"), commonAtomicfuDependency)
57+
internal fun GradleBuild.mppCheckNoAtomicfuInRuntimeConfigs(targetName: String) {
58+
checkAtomicfuDependencyIsAbsent(listOf("${targetName}RuntimeClasspath", "${targetName}ApiElements", "${targetName}RuntimeElements"), commonAtomicfuDependency)
5659
}
5760

58-
internal fun GradleBuild.checkMppWasmWasiImplementationDependencies() {
59-
checkAtomicfuDependencyIsPresent(listOf("wasmWasiCompileClasspath", "wasmWasiRuntimeClasspath"), commonAtomicfuDependency)
60-
}
61-
62-
// Checks Native target of an MPP project
63-
internal fun GradleBuild.checkMppNativeCompileOnlyDependencies() {
64-
// Here the name of the native target is hardcoded because the tested mpp-sample project declares this target and
65-
// KGP generates the same set of dependencies for every declared native target ([mingwX64|linuxX64|macosX64...]CompileKlibraries)
66-
checkAtomicfuDependencyIsPresent(listOf("macosX64CompileKlibraries"), commonAtomicfuDependency)
67-
checkAtomicfuDependencyIsAbsent(listOf("macosX64MainImplementation"), commonAtomicfuDependency)
61+
internal fun GradleBuild.mppCheckAtomicfuInApi(targetName: String) {
62+
checkAtomicfuDependencyIsPresent(listOf("${targetName}MainApi"), commonAtomicfuDependency)
6863
}
6964

7065
// Checks Native target of an MPP project
71-
internal fun GradleBuild.checkMppNativeImplementationDependencies() {
72-
checkAtomicfuDependencyIsPresent(listOf("macosX64CompileKlibraries", "macosX64MainImplementation"), commonAtomicfuDependency)
66+
internal fun GradleBuild.mppNativeCheckAtomicfuInImplementation() {
67+
checkAtomicfuDependencyIsPresent(listOf("macosX64MainImplementation"), commonAtomicfuDependency)
7368
}
7469

7570
// Some dependencies may be not resolvable but consumable and will not be present in the output of :dependencies task,

0 commit comments

Comments
 (0)