Skip to content

Commit 64fa77c

Browse files
committed
Add compose wasm as independent target
1 parent 5c9de5f commit 64fa77c

File tree

23 files changed

+227
-1033
lines changed

23 files changed

+227
-1033
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ RUN if [ -z "$KOTLIN_VERSION" ]; then \
1010
ENV KOTLIN_LIB=$KOTLIN_VERSION
1111
ENV KOTLIN_LIB_JS=${KOTLIN_VERSION}-js
1212
ENV KOTLIN_LIB_WASM=${KOTLIN_VERSION}-wasm
13-
ENV KOTLIN_COMPILER_PLUGINS=${KOTLIN_VERSION}-compiler-plugins
13+
ENV KOTLIN_LIB_COMPOSE_WASM=${KOTLIN_VERSION}-compose-wasm
14+
ENV KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS=${KOTLIN_VERSION}-compose-wasm-compiler-plugins
1415

1516
RUN mkdir -p /kotlin-compiler-server
1617
WORKDIR /kotlin-compiler-server
@@ -30,7 +31,8 @@ COPY --from=build /build/libs/BOOT-INF/classes /kotlin-compiler-server
3031
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB} /kotlin-compiler-server/${KOTLIN_LIB}
3132
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_JS} /kotlin-compiler-server/${KOTLIN_LIB_JS}
3233
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_WASM} /kotlin-compiler-server/${KOTLIN_LIB_WASM}
33-
COPY --from=build /kotlin-compiler-server/${KOTLIN_COMPILER_PLUGINS} /kotlin-compiler-server/${KOTLIN_COMPILER_PLUGINS}
34+
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_COMPOSE_WASM} /kotlin-compiler-server/${KOTLIN_LIB_COMPOSE_WASM}
35+
COPY --from=build /kotlin-compiler-server/${KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS} /kotlin-compiler-server/${KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS}
3436
COPY --from=build /kotlin-compiler-server/executor.policy /kotlin-compiler-server/
3537
COPY --from=build /kotlin-compiler-server/indexes.json /kotlin-compiler-server/
3638
COPY --from=build /kotlin-compiler-server/indexesJs.json /kotlin-compiler-server/

build.gradle.kts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ fun generateProperties(prefix: String = "") = """
9797
indexes.file=${prefix + indexes}
9898
indexesJs.file=${prefix + indexesJs}
9999
indexesWasm.file=${prefix + indexesWasm}
100+
indexesComposeWasm.file=${prefix + indexesComposeWasm}
100101
libraries.folder.jvm=${prefix + libJVMFolder}
101102
libraries.folder.js=${prefix + libJSFolder}
102103
libraries.folder.wasm=${prefix + libWasmFolder}
103-
libraries.folder.compiler-plugins=${prefix + libCompilerPluginsFolder}
104+
libraries.folder.compose-wasm=${prefix + libComposeWasmFolder}
105+
libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPluginsFolder}
104106
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
105107
server.compression.enabled=true
106108
server.compression.mime-types=application/json
@@ -120,7 +122,8 @@ tasks.withType<KotlinCompile> {
120122
dependsOn(":dependencies:copyDependencies")
121123
dependsOn(":dependencies:copyJSDependencies")
122124
dependsOn(":dependencies:copyWasmDependencies")
123-
dependsOn(":dependencies:copyCompilerPlugins")
125+
dependsOn(":dependencies:copyComposeWasmDependencies")
126+
dependsOn(":dependencies:copyComposeWasmCompilerPlugins")
124127
dependsOn(":executors:jar")
125128
dependsOn(":indexation:run")
126129
buildPropertyFile()
@@ -146,8 +149,9 @@ val buildLambda by tasks.creating(Zip::class) {
146149
from(indexesWasm)
147150
from(libJSFolder) { into(libJS) }
148151
from(libWasmFolder) { into(libWasm) }
152+
from(libComposeWasmFolder) { into(libComposeWasm) }
149153
from(libJVMFolder) { into(libJVM) }
150-
from(libCompilerPluginsFolder) { into(libCompilerPlugins) }
154+
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
151155
into("lib") {
152156
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
153157
}

buildSrc/src/main/kotlin/properties.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ val kotlinIdeVersionSuffix: String by System.getProperties()
77
val indexes: String by System.getProperties()
88
val indexesJs: String by System.getProperties()
99
val indexesWasm: String by System.getProperties()
10+
val indexesComposeWasm: String by System.getProperties()
1011

1112
val libJS = "$kotlinVersion-js"
1213
val libWasm = "$kotlinVersion-wasm"
13-
val libCompilerPlugins = "$kotlinVersion-compiler-plugins"
14+
val libComposeWasm = "$kotlinVersion-compose-wasm"
15+
val libComposeWasmCompilerPlugins = "$kotlinVersion-compose-wasm-compiler-plugins"
1416
val libJVM = kotlinVersion
1517

1618
val Project.libJSFolder
@@ -19,8 +21,11 @@ val Project.libJSFolder
1921
val Project.libWasmFolder
2022
get() = rootProject.layout.projectDirectory.dir(libWasm)
2123

22-
val Project.libCompilerPluginsFolder
23-
get() = rootProject.layout.projectDirectory.dir(libCompilerPlugins)
24+
val Project.libComposeWasmFolder
25+
get() = rootProject.layout.projectDirectory.dir(libComposeWasm)
26+
27+
val Project.libComposeWasmCompilerPluginsFolder
28+
get() = rootProject.layout.projectDirectory.dir(libComposeWasmCompilerPlugins)
2429

2530
val Project.libJVMFolder
2631
get() = rootProject.layout.projectDirectory.dir(libJVM)

common/src/main/kotlin/component/KotlinEnvironment.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
1010
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
1111
import org.jetbrains.kotlin.cli.jvm.config.configureJdkClasspathRoots
1212
import org.jetbrains.kotlin.cli.jvm.configureAdvancedJvmOptions
13+
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
1314
import org.jetbrains.kotlin.config.CommonConfigurationKeys
1415
import org.jetbrains.kotlin.config.CompilerConfiguration
1516
import org.jetbrains.kotlin.config.JVMConfigurationKeys
@@ -26,8 +27,9 @@ class KotlinEnvironment(
2627
val classpath: List<File>,
2728
additionalJsClasspath: List<File>,
2829
additionalWasmClasspath: List<File>,
29-
compilerPlugins: List<File>,
30-
compilerPluginsOptions: List<CompilerPluginOption>
30+
additionalComposeWasmClasspath: List<File>,
31+
composeWasmCompilerPlugins: List<File>,
32+
composeWasmCompilerPluginsOptions: List<CompilerPluginOption>
3133
) {
3234
companion object {
3335
/**
@@ -62,10 +64,13 @@ class KotlinEnvironment(
6264
val WASM_LIBRARIES = additionalWasmClasspath
6365
.map { it.absolutePath }
6466
.filter { isKotlinLibrary(File(it)) }
65-
val COMPILER_PLUGINS = compilerPlugins
67+
val COMPOSE_WASM_LIBRARIES = additionalComposeWasmClasspath
68+
.map { it.absolutePath }
69+
.filter { isKotlinLibrary(File(it)) }
70+
val COMPOSE_WASM_COMPILER_PLUGINS = composeWasmCompilerPlugins
6671
.map { it.absolutePath }
6772

68-
val compilerPluginOptions = compilerPluginsOptions
73+
val composeWasmCompilerPluginOptions = composeWasmCompilerPluginsOptions
6974
.map { "plugin:${it.id}:${it.option}=${it.value}" }
7075

7176
@Synchronized
@@ -87,6 +92,20 @@ class KotlinEnvironment(
8792
put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, false)
8893
}
8994

95+
val composeWasmConfiguration: CompilerConfiguration = configuration.copy().apply {
96+
put(CommonConfigurationKeys.MODULE_NAME, "moduleId")
97+
put(JSConfigurationKeys.LIBRARIES, COMPOSE_WASM_LIBRARIES)
98+
put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, false)
99+
put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, false)
100+
101+
PluginCliParser.loadPluginsSafe(
102+
COMPOSE_WASM_COMPILER_PLUGINS,
103+
composeWasmCompilerPluginOptions,
104+
emptyList(),
105+
this
106+
)
107+
}
108+
90109
private val environment = KotlinCoreEnvironment.createForProduction(
91110
parentDisposable = Disposer.newDisposable(),
92111
configuration = configuration.copy(),

dependencies/build.gradle.kts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,23 @@ val kotlinWasmDependency: Configuration by configurations.creating {
3838
}
3939
}
4040

41-
val compilerPlugins: Configuration by configurations.creating {
41+
val kotlinComposeWasmDependency: Configuration by configurations.creating {
42+
isCanBeResolved = true
43+
isCanBeConsumed = false
44+
45+
attributes {
46+
attribute(
47+
KotlinPlatformType.attribute,
48+
KotlinPlatformType.wasm
49+
)
50+
attribute(
51+
KotlinWasmTargetAttribute.wasmTargetAttribute,
52+
KotlinWasmTargetAttribute.js
53+
)
54+
}
55+
}
56+
57+
val composeWasmCompilerPlugins: Configuration by configurations.creating {
4258
isTransitive = false
4359
}
4460

@@ -59,9 +75,14 @@ val copyWasmDependencies by tasks.creating(Copy::class) {
5975
into(libWasmFolder)
6076
}
6177

62-
val copyCompilerPlugins by tasks.creating(Copy::class) {
63-
from(compilerPlugins)
64-
into(libCompilerPluginsFolder)
78+
val copyComposeWasmDependencies by tasks.creating(Copy::class) {
79+
from(kotlinComposeWasmDependency)
80+
into(libComposeWasmFolder)
81+
}
82+
83+
val copyComposeWasmCompilerPlugins by tasks.creating(Copy::class) {
84+
from(composeWasmCompilerPlugins)
85+
into(libComposeWasmCompilerPluginsFolder)
6586
}
6687

6788
plugins {
@@ -86,13 +107,14 @@ dependencies {
86107
kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")
87108

88109
// compose
89-
kotlinWasmDependency("org.jetbrains.compose.runtime:runtime:1.6.0-alpha01")
90-
kotlinWasmDependency("org.jetbrains.compose.ui:ui:1.6.0-alpha01")
91-
kotlinWasmDependency("org.jetbrains.compose.animation:animation:1.6.0-alpha01")
92-
kotlinWasmDependency("org.jetbrains.compose.animation:animation-graphics:1.6.0-alpha01")
93-
kotlinWasmDependency("org.jetbrains.compose.foundation:foundation:1.6.0-alpha01")
94-
kotlinWasmDependency("org.jetbrains.compose.material:material:1.6.0-alpha01")
95-
kotlinWasmDependency("org.jetbrains.compose.components:components-resources:1.6.0-alpha01")
96-
97-
compilerPlugins("org.jetbrains.compose.compiler:compiler-hosted:1.5.4")
110+
kotlinComposeWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")
111+
kotlinComposeWasmDependency("org.jetbrains.compose.runtime:runtime:1.6.0")
112+
kotlinComposeWasmDependency("org.jetbrains.compose.ui:ui:1.6.0")
113+
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation:1.6.0")
114+
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation-graphics:1.6.0")
115+
kotlinComposeWasmDependency("org.jetbrains.compose.foundation:foundation:1.6.0")
116+
kotlinComposeWasmDependency("org.jetbrains.compose.material:material:1.6.0")
117+
kotlinComposeWasmDependency("org.jetbrains.compose.components:components-resources:1.6.0")
118+
119+
composeWasmCompilerPlugins("org.jetbrains.compose.compiler:compiler-hosted:1.5.10")
98120
}

indexation/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tasks.withType<JavaExec> {
2121
"$rootName${File.separator}$kotlinVersion",
2222
"$rootName${File.separator}$indexes",
2323
"$rootName${File.separator}$indexesJs",
24-
"$rootName${File.separator}$indexesWasm"
24+
"$rootName${File.separator}$indexesWasm",
25+
"$rootName${File.separator}$indexesComposeWasm",
2526
)
2627
}

indexation/src/main/kotlin/KotlinEnvironmentConfiguration.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class KotlinEnvironmentConfiguration(
1212
val jvmFile = File(fileName)
1313
val jsFile = File("$fileName-js")
1414
val wasmFile = File("$fileName-wasm")
15-
val compilerPluginsFile = File("$fileName-compiler-plugins")
15+
val composeWasmFile = File("$fileName-compose-wasm")
16+
val composeWasmCompilerPluginsFile = File("$fileName-compose-wasm-compiler-plugins")
1617
val classPath =
1718
listOfNotNull(jvmFile)
1819
.flatMap {
@@ -22,13 +23,15 @@ class KotlinEnvironmentConfiguration(
2223

2324
val additionalJsClasspath = jsFile.listFiles()?.toList() ?: emptyList()
2425
val additionalWasmClasspath = wasmFile.listFiles()?.toList() ?: emptyList()
25-
val compilerPlugins = compilerPluginsFile.listFiles()?.toList() ?: emptyList()
26+
val additionalComposeWasmClasspath = composeWasmFile.listFiles()?.toList() ?: emptyList()
27+
val composeWasmCompilerPlugins = composeWasmCompilerPluginsFile.listFiles()?.toList() ?: emptyList()
2628

2729
KotlinEnvironment(
2830
classPath,
2931
additionalJsClasspath,
3032
additionalWasmClasspath,
31-
compilerPlugins,
33+
additionalComposeWasmClasspath,
34+
composeWasmCompilerPlugins,
3235
listOf(
3336
CompilerPluginOption(
3437
"androidx.compose.compiler.plugins.kotlin",

indexation/src/main/kotlin/Main.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,39 @@ package indexation
66
* Third argument is path to output file for js indexes
77
*/
88
fun main(args: Array<String>) {
9-
val (version, directory, outputPathJvm, outputPathJs, outputPathWasm) = args
9+
val version = args[0]
10+
val directory = args[1]
11+
val outputPathJvm = args[2]
12+
val outputPathJs = args[3]
13+
val outputPathWasm = args[4]
14+
val outputPathComposeWasm = args[5]
1015
val kotlinEnvironment = KotlinEnvironmentConfiguration(version, directory).kotlinEnvironment
1116
JvmIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJvm)
1217

1318
WebIndexationBuilder(
1419
kotlinEnvironment = kotlinEnvironment,
1520
inputConfiguration = kotlinEnvironment.jsConfiguration,
1621
libraries = kotlinEnvironment.JS_LIBRARIES,
17-
compilerPlugins = false,
22+
compilerPlugins = emptyList(),
23+
compilerPluginOptions = emptyList(),
1824
platformConfiguration = kotlinEnvironment.jsConfiguration
1925
).writeIndexesToFile(outputPathJs)
2026

2127
WebIndexationBuilder(
2228
kotlinEnvironment = kotlinEnvironment,
2329
inputConfiguration = kotlinEnvironment.wasmConfiguration,
2430
libraries = kotlinEnvironment.WASM_LIBRARIES,
25-
compilerPlugins = true,
31+
compilerPlugins = emptyList(),
32+
compilerPluginOptions = emptyList(),
2633
platformConfiguration = kotlinEnvironment.wasmConfiguration
2734
).writeIndexesToFile(outputPathWasm)
35+
36+
WebIndexationBuilder(
37+
kotlinEnvironment = kotlinEnvironment,
38+
inputConfiguration = kotlinEnvironment.composeWasmConfiguration,
39+
libraries = kotlinEnvironment.COMPOSE_WASM_LIBRARIES,
40+
compilerPlugins = kotlinEnvironment.COMPOSE_WASM_COMPILER_PLUGINS,
41+
compilerPluginOptions = kotlinEnvironment.composeWasmCompilerPluginOptions,
42+
platformConfiguration = kotlinEnvironment.composeWasmConfiguration
43+
).writeIndexesToFile(outputPathComposeWasm)
2844
}

indexation/src/main/kotlin/WebIndexationBuilder.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class WebIndexationBuilder(
1313
private val kotlinEnvironment: KotlinEnvironment,
1414
inputConfiguration: CompilerConfiguration,
1515
private val libraries: List<String>,
16-
private val compilerPlugins: Boolean,
16+
private val compilerPlugins: List<String>,
17+
private val compilerPluginOptions: List<String>,
1718
private val platformConfiguration: CompilerConfiguration
1819
): IndexationBuilder() {
1920

@@ -23,10 +24,10 @@ class WebIndexationBuilder(
2324
kotlinEnvironment.environment { coreEnvironment ->
2425
val project = coreEnvironment.project
2526

26-
if (compilerPlugins) {
27+
if (compilerPlugins.isNotEmpty()) {
2728
PluginCliParser.loadPluginsSafe(
28-
kotlinEnvironment.COMPILER_PLUGINS,
29-
kotlinEnvironment.compilerPluginOptions,
29+
compilerPlugins,
30+
compilerPluginOptions,
3031
emptyList(),
3132
configuration
3233
)

src/main/kotlin/com/compiler/server/compiler/components/CompletionProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ class CompletionProvider(
204204
val analysis = when {
205205
projectType.isJvmRelated() -> errorAnalyzer.analysisOf(files, coreEnvironment)
206206
projectType.isJsRelated() -> errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
207-
projectType.isWasmRelated() -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
207+
projectType == ProjectType.WASM -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
208+
projectType == ProjectType.COMPOSE_WASM -> errorAnalyzer.analyzeFileForComposeWasm(files, coreEnvironment)
208209
else -> throw IllegalArgumentException("Unknown project type $projectType")
209210
}
210211
return with(analysis) {

0 commit comments

Comments
 (0)