Skip to content

Commit 1c939f9

Browse files
authored
Add wasmJs target (#5458)
* add wasmJs target * add comment * crash
1 parent 84f0f92 commit 1c939f9

File tree

42 files changed

+1017
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1017
-59
lines changed

build-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
implementation(libs.android.plugin)
3030
implementation(libs.gradle.japicmp.plugin)
3131
implementation(libs.vespene)
32+
implementation(libs.kotlinx.serialization.json)
3233
implementation(libs.poet.java)
3334
implementation(libs.poet.kotlin)
3435
implementation(libs.intellij.plugin)

build-logic/src/main/kotlin/CompilerOptions.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,16 @@ fun Project.configureJavaAndKotlinCompilers() {
8989
// Ensure "org.gradle.jvm.version" is set to "8" in Gradle metadata of jvm-only modules.
9090
options.release.set(8)
9191
}
92-
93-
allWarningsAsErrors(true)
92+
93+
/**
94+
* Required because of:
95+
*
96+
* > Task :apollo-runtime:compileKotlinWasmJs
97+
* w: duplicate library name: kotlin
98+
*
99+
* (maybe https://youtrack.jetbrains.com/issue/KT-51110?)
100+
*/
101+
allWarningsAsErrors(false)
94102
}
95103

96104
@Suppress("UnstableApiUsage")

build-logic/src/main/kotlin/Mpp.kt

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
77
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
88
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
99

10-
private val allAppleTargets = setOf(
10+
internal val allAppleTargets = setOf(
1111
"macosX64",
1212
"macosArm64",
1313
"iosArm64",
@@ -33,49 +33,13 @@ private val enableLinux = System.getenv("APOLLO_JVM_ONLY")?.toBoolean()?.not() ?
3333
private val enableJs = System.getenv("APOLLO_JVM_ONLY")?.toBoolean()?.not() ?: true
3434
private val enableApple = System.getenv("APOLLO_JVM_ONLY")?.toBoolean()?.not() ?: true
3535

36-
fun Project.configureMppDefaults(
37-
withJvm: Boolean,
38-
withJs: Boolean,
39-
withLinux: Boolean,
40-
withAndroid: Boolean,
41-
withApple: Boolean,
42-
) {
43-
configureMpp(
44-
withJvm = withJvm,
45-
withJs = withJs,
46-
browserTest = false,
47-
withLinux = withLinux,
48-
appleTargets = if (!withApple) emptySet() else allAppleTargets,
49-
withAndroid = withAndroid,
50-
)
51-
}
52-
53-
54-
/**
55-
* Same as [configureMppDefaults] but without Linux targets. Apple targets can be configured.
56-
* Tests only run on the JVM, JS and macOS
57-
*/
58-
fun Project.configureMppTestsDefaults(
59-
withJs: Boolean,
60-
withJvm: Boolean,
61-
browserTest: Boolean,
62-
appleTargets: Collection<String>,
63-
) {
64-
configureMpp(
65-
withJvm = withJvm,
66-
withJs = withJs,
67-
browserTest = browserTest,
68-
withLinux = false,
69-
withAndroid = false,
70-
appleTargets = appleTargets,
71-
)
72-
}
7336

7437
fun Project.configureMpp(
7538
withJvm: Boolean,
7639
withJs: Boolean,
7740
withLinux: Boolean,
7841
withAndroid: Boolean,
42+
withWasm: Boolean,
7943
appleTargets: Collection<String>,
8044
browserTest: Boolean,
8145
) {
@@ -138,6 +102,11 @@ fun Project.configureMpp(
138102
}
139103
}
140104
}
105+
if (withWasm) {
106+
wasmJs {
107+
nodejs()
108+
}
109+
}
141110

142111
configureSourceSetGraph()
143112
addTestDependencies()

build-logic/src/main/kotlin/api.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fun Project.apolloLibrary(
88
withLinux: Boolean = true,
99
withApple: Boolean = true,
1010
withJvm: Boolean = true,
11+
withWasm: Boolean = true,
1112
publish: Boolean = true
1213
) {
1314
group = property("GROUP")!!
@@ -35,12 +36,14 @@ fun Project.apolloLibrary(
3536
}
3637

3738
if (extensions.findByName("kotlin") is KotlinMultiplatformExtension) {
38-
configureMppDefaults(
39+
configureMpp(
3940
withJvm = withJvm,
4041
withJs = withJs,
42+
browserTest = false,
4143
withLinux = withLinux,
44+
appleTargets = if (!withApple) emptySet() else allAppleTargets,
4245
withAndroid = extensions.findByName("android") != null,
43-
withApple = withApple,
46+
withWasm = withWasm
4447
)
4548
}
4649

@@ -68,11 +71,14 @@ fun Project.apolloTest(
6871
configureTesting()
6972

7073
if (extensions.findByName("kotlin") is KotlinMultiplatformExtension) {
71-
configureMppTestsDefaults(
72-
withJs = withJs,
74+
configureMpp(
7375
withJvm = withJvm,
76+
withJs = withJs,
7477
browserTest = browserTest,
78+
withLinux = false,
79+
withAndroid = false,
7580
appleTargets = appleTargets,
81+
withWasm = false
7682
)
7783
}
7884
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ org.gradle.caching=true
2727
# org.gradle.configuration-cache=true
2828

2929
org.gradle.parallel=true
30+
31+
kotlin.wasm.stability.nowarn=true

gradle/libraries.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ kotlin-plugin-min = "1.8.0"
2929
kotlin-plugin = "2.0.0-Beta1"
3030
kotlin-plugin-max = "2.0.0-Beta1"
3131
kotlin-stdlib = "2.0.0-Beta1"
32-
kotlinx-coroutines = "1.7.3"
33-
kotlinx-datetime = "0.4.1"
34-
kotlinx-serialization-runtime = "1.5.0"
32+
kotlinx-coroutines = "1.8.0-RC"
33+
kotlinx-datetime = "0.5.0"
34+
kotlinx-serialization-runtime = "1.6.2"
3535
ksp = "2.0.0-Beta1-1.0.14"
36-
ktor = "2.3.3"
3736
okio = "3.6.0"
37+
ktor = "2.3.5"
3838
okhttp = "4.11.0"
3939
rx-android = "2.0.1"
4040
rx-java2 = "2.2.21"
4141
rx-java3 = "3.1.6"
42-
sqldelight = "2.0.0"
42+
sqldelight = "2.0.1"
4343
truth = "1.1.3"
4444
moshix = "0.14.1"
4545

@@ -83,7 +83,7 @@ apollo-testingsupport = { group = "com.apollographql.apollo3", name = "apollo-te
8383
# Used by the apollo-tooling project which uses a published version of Apollo
8484
apollo-testingsupport-published = { group = "com.apollographql.apollo3", name = "apollo-testing-support", version.ref = "apollo-published" }
8585
assertj = { group = "org.assertj", name = "assertj-core", version = "3.24.2" }
86-
atomicfu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version = "0.20.1" }
86+
atomicfu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version = "0.23.1" }
8787
benmanes-versions = { group = "com.github.ben-manes", name = "gradle-versions-plugin", version = "0.33.0" }
8888
clikt = { group = "com.github.ajalt.clikt", name = "clikt", version = "3.5.2" }
8989
compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "compose" }
@@ -126,6 +126,7 @@ kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect" } # t
126126
kotlin-stdlib-common = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-common", version.ref = "kotlin-stdlib" }
127127
kotlin-stdlib-jvm = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin-stdlib" }
128128
kotlin-stdlib-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-js", version.ref = "kotlin-stdlib" }
129+
kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-wasm-js", version.ref = "kotlin-stdlib" }
129130
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test" } # the Kotlin plugin resolves the version
130131
kotlin-test-annotations-common = { group = "org.jetbrains.kotlin", name = "kotlin-test-annotations-common" } # the Kotlin plugin resolves the version
131132
kotlin-test-common = { group = "org.jetbrains.kotlin", name = "kotlin-test-common" } # the Kotlin plugin resolves the version
@@ -173,7 +174,7 @@ sqldelight-jvm = { group = "app.cash.sqldelight", name = "sqlite-driver", versio
173174
sqldelight-native = { group = "app.cash.sqldelight", name = "native-driver", version.ref = "sqldelight" }
174175
sqldelight-plugin = { group = "app.cash.sqldelight", name = "gradle-plugin", version.ref = "sqldelight" }
175176
sqldelight-runtime = { group = "app.cash.sqldelight", name = "runtime", version.ref = "sqldelight" }
176-
sqldelight-sqlite = "app.cash.sqldelight:sqlite-dialect:2.0.0-alpha01"
177+
sqldelight-sqlite = { group = "app.cash.sqldelight", name = "sqlite-dialect", version.ref = "sqldelight" }
177178
sqlite-jdbc = "org.xerial:sqlite-jdbc:3.43.2.0"
178179
jar-relocator = "me.lucko:jar-relocator:1.5"
179180
benchmark-gradle-plugin = "androidx.benchmark:benchmark-gradle-plugin:1.1.1"

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-rc-1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

libraries/apollo-adapters/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ plugins {
44

55
apolloLibrary(
66
javaModuleName = "com.apollographql.apollo3.adapter",
7-
withLinux = false
7+
withLinux = false,
8+
withWasm = false
89
)
910

1011
kotlin {

libraries/apollo-annotations/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@ kotlin {
2727
api(libs.kotlin.stdlib.js)
2828
}
2929
}
30+
findByName("wasmJsMain")!!.apply {
31+
dependencies {
32+
api(libs.kotlin.stdlib.wasm.js)
33+
}
34+
}
3035
}
3136
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.apollographql.apollo3.annotations
2+
3+
import kotlin.reflect.AssociatedObjectKey
4+
import kotlin.reflect.ExperimentalAssociatedObjects
5+
import kotlin.reflect.KClass
6+
7+
@OptIn(ExperimentalAssociatedObjects::class)
8+
@AssociatedObjectKey
9+
@Retention(AnnotationRetention.BINARY)
10+
actual annotation class ApolloAdaptableWith(public actual val adapter: KClass<*>)

0 commit comments

Comments
 (0)