Skip to content

Commit 42cfce6

Browse files
authored
Add linuxMain source set (#2007)
This PR creates a new `linuxMain` source set which depends on `nativeMain`. It can be created with `linux()`, this is similar to how it is done for other targets. Replaced individual `linuxX64()`/`linuxArm64()` targets with this new `linux()` call. I did not add linux support to any new modules, this PR is so the actual PR supporting Linux for Compose UI will be a bit smaller. The additional linuxMain source set is required for that. ## Testing N/A ## Release Notes N/A
1 parent 18aa409 commit 42cfce6

File tree

12 files changed

+37
-47
lines changed

12 files changed

+37
-47
lines changed

annotation/annotation-compatibility-stub/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ androidXComposeMultiplatform {
3535
js()
3636
wasm()
3737
darwin()
38-
39-
linuxX64()
40-
linuxArm64()
38+
linux()
4139
}
4240

4341
kotlin {

annotation/annotation/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ androidXComposeMultiplatform {
1919
js()
2020
wasm()
2121
darwin()
22-
23-
linuxX64()
24-
linuxArm64()
22+
linux()
2523
}
2624

2725
kotlin {

buildSrc/private/src/main/kotlin/androidx/build/AndroidXComposeMultiplatformExtensionImpl.kt

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
206206
iosArm64("uikitArm64")
207207
iosSimulatorArm64("uikitSimArm64")
208208

209-
val commonMain = sourceSets.getByName("commonMain")
210-
val nativeMain = sourceSets.create("nativeMain")
209+
val nativeMain = getOrCreateNativeMain()
211210
val darwinMain = sourceSets.create("darwinMain")
212211
val macosMain = sourceSets.create("macosMain")
213212
val macosX64Main = sourceSets.getByName("macosX64Main")
@@ -216,7 +215,6 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
216215
val uikitX64Main = sourceSets.getByName("uikitX64Main")
217216
val uikitArm64Main = sourceSets.getByName("uikitArm64Main")
218217
val uikitSimArm64Main = sourceSets.getByName("uikitSimArm64Main")
219-
nativeMain.dependsOn(commonMain)
220218
darwinMain.dependsOn(nativeMain)
221219
macosMain.dependsOn(darwinMain)
222220
macosX64Main.dependsOn(macosMain)
@@ -226,8 +224,7 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
226224
uikitArm64Main.dependsOn(uikitMain)
227225
uikitSimArm64Main.dependsOn(uikitMain)
228226

229-
val commonTest = sourceSets.getByName("commonTest")
230-
val nativeTest = sourceSets.create("nativeTest")
227+
val nativeTest = getOrCreateNativeTest()
231228
val darwinTest = sourceSets.create("darwinTest")
232229
val macosTest = sourceSets.create("macosTest")
233230
val macosX64Test = sourceSets.getByName("macosX64Test")
@@ -236,7 +233,6 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
236233
val uikitX64Test = sourceSets.getByName("uikitX64Test")
237234
val uikitArm64Test = sourceSets.getByName("uikitArm64Test")
238235
val uikitSimArm64Test = sourceSets.getByName("uikitSimArm64Test")
239-
nativeTest.dependsOn(commonTest)
240236
darwinTest.dependsOn(nativeTest)
241237
macosTest.dependsOn(darwinTest)
242238
macosX64Test.dependsOn(macosTest)
@@ -247,12 +243,25 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
247243
uikitSimArm64Test.dependsOn(uikitTest)
248244
}
249245

250-
override fun linuxX64(): Unit = multiplatformExtension.run {
246+
override fun linux(): Unit = multiplatformExtension.run {
251247
linuxX64()
252-
}
253-
254-
override fun linuxArm64(): Unit = multiplatformExtension.run {
255248
linuxArm64()
249+
250+
val nativeMain = getOrCreateNativeMain()
251+
val linuxMain = sourceSets.create("linuxMain")
252+
val linuxX64Main = sourceSets.getByName("linuxX64Main")
253+
val linuxArm64Main = sourceSets.getByName("linuxArm64Main")
254+
linuxMain.dependsOn(nativeMain)
255+
linuxX64Main.dependsOn(linuxMain)
256+
linuxArm64Main.dependsOn(linuxMain)
257+
258+
val nativeTest = getOrCreateNativeTest()
259+
val linuxTest = sourceSets.create("linuxTest")
260+
val linuxX64Test = sourceSets.getByName("linuxX64Test")
261+
val linuxArm64Test = sourceSets.getByName("linuxArm64Test")
262+
linuxTest.dependsOn(nativeTest)
263+
linuxX64Test.dependsOn(linuxTest)
264+
linuxArm64Test.dependsOn(linuxTest)
256265
}
257266

258267
private fun getOrCreateJvmMain(): KotlinSourceSet =
@@ -261,6 +270,12 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
261270
private fun getOrCreateJvmTest(): KotlinSourceSet =
262271
getOrCreateSourceSet("jvmTest", "commonTest")
263272

273+
private fun getOrCreateNativeMain(): KotlinSourceSet =
274+
getOrCreateSourceSet("nativeMain", "commonMain")
275+
276+
private fun getOrCreateNativeTest(): KotlinSourceSet =
277+
getOrCreateSourceSet("nativeTest", "commonTest")
278+
264279
private fun getOrCreateSourceSet(
265280
name: String,
266281
dependsOnSourceSetName: String

buildSrc/public/src/main/kotlin/androidx/build/AndroidXComposeMultiplatformExtension.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,9 @@ abstract class AndroidXComposeMultiplatformExtension {
5656

5757
/**
5858
* Provides the default target configuration and source set dependencies
59-
* for all linuxX64 native targets.
59+
* for all linux native targets.
6060
*/
61-
abstract fun linuxX64(): Unit
62-
63-
/**
64-
* Provides the default target configuration and source set dependencies
65-
* for all linuxArm64 native targets.
66-
*/
67-
abstract fun linuxArm64(): Unit
61+
abstract fun linux(): Unit
6862

6963
/**
7064
* Configures native compilation tasks with flags to link required frameworks

collection/collection-compatibility-stub/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ androidXComposeMultiplatform {
3535
js()
3636
wasm()
3737
darwin()
38-
39-
linuxX64()
40-
linuxArm64()
38+
linux()
4139
}
4240

4341
kotlin {

collection/collection/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ androidXComposeMultiplatform {
3535
js()
3636
wasm()
3737
darwin()
38-
39-
linuxX64()
40-
linuxArm64()
38+
linux()
4139
}
4240

4341
kotlin {

compose/runtime/runtime-annotation/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ androidXComposeMultiplatform {
4141
darwin()
4242
js()
4343
wasm()
44-
45-
linuxX64()
46-
linuxArm64()
44+
linux()
4745
}
4846

4947
kotlin {

compose/runtime/runtime-saveable/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
7373
darwin()
7474
js()
7575
wasm()
76-
77-
linuxX64()
78-
linuxArm64()
76+
linux()
7977
}
8078

8179
kotlin {

compose/runtime/runtime-test-utils/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ androidXComposeMultiplatform {
3737
darwin()
3838
js()
3939
wasm()
40-
linuxX64()
41-
linuxArm64()
40+
linux()
4241
}
4342

4443
kotlin {

compose/runtime/runtime/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
6969
js()
7070
wasm()
7171
darwin()
72-
73-
linuxX64()
74-
linuxArm64()
72+
linux()
7573
}
7674

7775
kotlin {

0 commit comments

Comments
 (0)