Skip to content

Commit

Permalink
Add compose wasm as independent target
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic committed Mar 12, 2024
1 parent 5c9de5f commit 64fa77c
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 1,033 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RUN if [ -z "$KOTLIN_VERSION" ]; then \
ENV KOTLIN_LIB=$KOTLIN_VERSION
ENV KOTLIN_LIB_JS=${KOTLIN_VERSION}-js
ENV KOTLIN_LIB_WASM=${KOTLIN_VERSION}-wasm
ENV KOTLIN_COMPILER_PLUGINS=${KOTLIN_VERSION}-compiler-plugins
ENV KOTLIN_LIB_COMPOSE_WASM=${KOTLIN_VERSION}-compose-wasm
ENV KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS=${KOTLIN_VERSION}-compose-wasm-compiler-plugins

RUN mkdir -p /kotlin-compiler-server
WORKDIR /kotlin-compiler-server
Expand All @@ -30,7 +31,8 @@ COPY --from=build /build/libs/BOOT-INF/classes /kotlin-compiler-server
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB} /kotlin-compiler-server/${KOTLIN_LIB}
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_JS} /kotlin-compiler-server/${KOTLIN_LIB_JS}
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_WASM} /kotlin-compiler-server/${KOTLIN_LIB_WASM}
COPY --from=build /kotlin-compiler-server/${KOTLIN_COMPILER_PLUGINS} /kotlin-compiler-server/${KOTLIN_COMPILER_PLUGINS}
COPY --from=build /kotlin-compiler-server/${KOTLIN_LIB_COMPOSE_WASM} /kotlin-compiler-server/${KOTLIN_LIB_COMPOSE_WASM}
COPY --from=build /kotlin-compiler-server/${KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS} /kotlin-compiler-server/${KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS}
COPY --from=build /kotlin-compiler-server/executor.policy /kotlin-compiler-server/
COPY --from=build /kotlin-compiler-server/indexes.json /kotlin-compiler-server/
COPY --from=build /kotlin-compiler-server/indexesJs.json /kotlin-compiler-server/
Expand Down
10 changes: 7 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ fun generateProperties(prefix: String = "") = """
indexes.file=${prefix + indexes}
indexesJs.file=${prefix + indexesJs}
indexesWasm.file=${prefix + indexesWasm}
indexesComposeWasm.file=${prefix + indexesComposeWasm}
libraries.folder.jvm=${prefix + libJVMFolder}
libraries.folder.js=${prefix + libJSFolder}
libraries.folder.wasm=${prefix + libWasmFolder}
libraries.folder.compiler-plugins=${prefix + libCompilerPluginsFolder}
libraries.folder.compose-wasm=${prefix + libComposeWasmFolder}
libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPluginsFolder}
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
server.compression.enabled=true
server.compression.mime-types=application/json
Expand All @@ -120,7 +122,8 @@ tasks.withType<KotlinCompile> {
dependsOn(":dependencies:copyDependencies")
dependsOn(":dependencies:copyJSDependencies")
dependsOn(":dependencies:copyWasmDependencies")
dependsOn(":dependencies:copyCompilerPlugins")
dependsOn(":dependencies:copyComposeWasmDependencies")
dependsOn(":dependencies:copyComposeWasmCompilerPlugins")
dependsOn(":executors:jar")
dependsOn(":indexation:run")
buildPropertyFile()
Expand All @@ -146,8 +149,9 @@ val buildLambda by tasks.creating(Zip::class) {
from(indexesWasm)
from(libJSFolder) { into(libJS) }
from(libWasmFolder) { into(libWasm) }
from(libComposeWasmFolder) { into(libComposeWasm) }
from(libJVMFolder) { into(libJVM) }
from(libCompilerPluginsFolder) { into(libCompilerPlugins) }
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
into("lib") {
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
}
Expand Down
11 changes: 8 additions & 3 deletions buildSrc/src/main/kotlin/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ val kotlinIdeVersionSuffix: String by System.getProperties()
val indexes: String by System.getProperties()
val indexesJs: String by System.getProperties()
val indexesWasm: String by System.getProperties()
val indexesComposeWasm: String by System.getProperties()

val libJS = "$kotlinVersion-js"
val libWasm = "$kotlinVersion-wasm"
val libCompilerPlugins = "$kotlinVersion-compiler-plugins"
val libComposeWasm = "$kotlinVersion-compose-wasm"
val libComposeWasmCompilerPlugins = "$kotlinVersion-compose-wasm-compiler-plugins"
val libJVM = kotlinVersion

val Project.libJSFolder
Expand All @@ -19,8 +21,11 @@ val Project.libJSFolder
val Project.libWasmFolder
get() = rootProject.layout.projectDirectory.dir(libWasm)

val Project.libCompilerPluginsFolder
get() = rootProject.layout.projectDirectory.dir(libCompilerPlugins)
val Project.libComposeWasmFolder
get() = rootProject.layout.projectDirectory.dir(libComposeWasm)

val Project.libComposeWasmCompilerPluginsFolder
get() = rootProject.layout.projectDirectory.dir(libComposeWasmCompilerPlugins)

val Project.libJVMFolder
get() = rootProject.layout.projectDirectory.dir(libJVM)
27 changes: 23 additions & 4 deletions common/src/main/kotlin/component/KotlinEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.cli.jvm.config.configureJdkClasspathRoots
import org.jetbrains.kotlin.cli.jvm.configureAdvancedJvmOptions
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
Expand All @@ -26,8 +27,9 @@ class KotlinEnvironment(
val classpath: List<File>,
additionalJsClasspath: List<File>,
additionalWasmClasspath: List<File>,
compilerPlugins: List<File>,
compilerPluginsOptions: List<CompilerPluginOption>
additionalComposeWasmClasspath: List<File>,
composeWasmCompilerPlugins: List<File>,
composeWasmCompilerPluginsOptions: List<CompilerPluginOption>
) {
companion object {
/**
Expand Down Expand Up @@ -62,10 +64,13 @@ class KotlinEnvironment(
val WASM_LIBRARIES = additionalWasmClasspath
.map { it.absolutePath }
.filter { isKotlinLibrary(File(it)) }
val COMPILER_PLUGINS = compilerPlugins
val COMPOSE_WASM_LIBRARIES = additionalComposeWasmClasspath
.map { it.absolutePath }
.filter { isKotlinLibrary(File(it)) }
val COMPOSE_WASM_COMPILER_PLUGINS = composeWasmCompilerPlugins
.map { it.absolutePath }

val compilerPluginOptions = compilerPluginsOptions
val composeWasmCompilerPluginOptions = composeWasmCompilerPluginsOptions
.map { "plugin:${it.id}:${it.option}=${it.value}" }

@Synchronized
Expand All @@ -87,6 +92,20 @@ class KotlinEnvironment(
put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, false)
}

val composeWasmConfiguration: CompilerConfiguration = configuration.copy().apply {
put(CommonConfigurationKeys.MODULE_NAME, "moduleId")
put(JSConfigurationKeys.LIBRARIES, COMPOSE_WASM_LIBRARIES)
put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, false)
put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, false)

PluginCliParser.loadPluginsSafe(
COMPOSE_WASM_COMPILER_PLUGINS,
composeWasmCompilerPluginOptions,
emptyList(),
this
)
}

private val environment = KotlinCoreEnvironment.createForProduction(
parentDisposable = Disposer.newDisposable(),
configuration = configuration.copy(),
Expand Down
48 changes: 35 additions & 13 deletions dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,23 @@ val kotlinWasmDependency: Configuration by configurations.creating {
}
}

val compilerPlugins: Configuration by configurations.creating {
val kotlinComposeWasmDependency: Configuration by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false

attributes {
attribute(
KotlinPlatformType.attribute,
KotlinPlatformType.wasm
)
attribute(
KotlinWasmTargetAttribute.wasmTargetAttribute,
KotlinWasmTargetAttribute.js
)
}
}

val composeWasmCompilerPlugins: Configuration by configurations.creating {
isTransitive = false
}

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

val copyCompilerPlugins by tasks.creating(Copy::class) {
from(compilerPlugins)
into(libCompilerPluginsFolder)
val copyComposeWasmDependencies by tasks.creating(Copy::class) {
from(kotlinComposeWasmDependency)
into(libComposeWasmFolder)
}

val copyComposeWasmCompilerPlugins by tasks.creating(Copy::class) {
from(composeWasmCompilerPlugins)
into(libComposeWasmCompilerPluginsFolder)
}

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

// compose
kotlinWasmDependency("org.jetbrains.compose.runtime:runtime:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.ui:ui:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.animation:animation:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.animation:animation-graphics:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.foundation:foundation:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.material:material:1.6.0-alpha01")
kotlinWasmDependency("org.jetbrains.compose.components:components-resources:1.6.0-alpha01")

compilerPlugins("org.jetbrains.compose.compiler:compiler-hosted:1.5.4")
kotlinComposeWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion")
kotlinComposeWasmDependency("org.jetbrains.compose.runtime:runtime:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.ui:ui:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.animation:animation-graphics:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.foundation:foundation:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.material:material:1.6.0")
kotlinComposeWasmDependency("org.jetbrains.compose.components:components-resources:1.6.0")

composeWasmCompilerPlugins("org.jetbrains.compose.compiler:compiler-hosted:1.5.10")
}
3 changes: 2 additions & 1 deletion indexation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tasks.withType<JavaExec> {
"$rootName${File.separator}$kotlinVersion",
"$rootName${File.separator}$indexes",
"$rootName${File.separator}$indexesJs",
"$rootName${File.separator}$indexesWasm"
"$rootName${File.separator}$indexesWasm",
"$rootName${File.separator}$indexesComposeWasm",
)
}
9 changes: 6 additions & 3 deletions indexation/src/main/kotlin/KotlinEnvironmentConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class KotlinEnvironmentConfiguration(
val jvmFile = File(fileName)
val jsFile = File("$fileName-js")
val wasmFile = File("$fileName-wasm")
val compilerPluginsFile = File("$fileName-compiler-plugins")
val composeWasmFile = File("$fileName-compose-wasm")
val composeWasmCompilerPluginsFile = File("$fileName-compose-wasm-compiler-plugins")
val classPath =
listOfNotNull(jvmFile)
.flatMap {
Expand All @@ -22,13 +23,15 @@ class KotlinEnvironmentConfiguration(

val additionalJsClasspath = jsFile.listFiles()?.toList() ?: emptyList()
val additionalWasmClasspath = wasmFile.listFiles()?.toList() ?: emptyList()
val compilerPlugins = compilerPluginsFile.listFiles()?.toList() ?: emptyList()
val additionalComposeWasmClasspath = composeWasmFile.listFiles()?.toList() ?: emptyList()
val composeWasmCompilerPlugins = composeWasmCompilerPluginsFile.listFiles()?.toList() ?: emptyList()

KotlinEnvironment(
classPath,
additionalJsClasspath,
additionalWasmClasspath,
compilerPlugins,
additionalComposeWasmClasspath,
composeWasmCompilerPlugins,
listOf(
CompilerPluginOption(
"androidx.compose.compiler.plugins.kotlin",
Expand Down
22 changes: 19 additions & 3 deletions indexation/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,39 @@ package indexation
* Third argument is path to output file for js indexes
*/
fun main(args: Array<String>) {
val (version, directory, outputPathJvm, outputPathJs, outputPathWasm) = args
val version = args[0]
val directory = args[1]
val outputPathJvm = args[2]
val outputPathJs = args[3]
val outputPathWasm = args[4]
val outputPathComposeWasm = args[5]
val kotlinEnvironment = KotlinEnvironmentConfiguration(version, directory).kotlinEnvironment
JvmIndexationBuilder(kotlinEnvironment = kotlinEnvironment).writeIndexesToFile(outputPathJvm)

WebIndexationBuilder(
kotlinEnvironment = kotlinEnvironment,
inputConfiguration = kotlinEnvironment.jsConfiguration,
libraries = kotlinEnvironment.JS_LIBRARIES,
compilerPlugins = false,
compilerPlugins = emptyList(),
compilerPluginOptions = emptyList(),
platformConfiguration = kotlinEnvironment.jsConfiguration
).writeIndexesToFile(outputPathJs)

WebIndexationBuilder(
kotlinEnvironment = kotlinEnvironment,
inputConfiguration = kotlinEnvironment.wasmConfiguration,
libraries = kotlinEnvironment.WASM_LIBRARIES,
compilerPlugins = true,
compilerPlugins = emptyList(),
compilerPluginOptions = emptyList(),
platformConfiguration = kotlinEnvironment.wasmConfiguration
).writeIndexesToFile(outputPathWasm)

WebIndexationBuilder(
kotlinEnvironment = kotlinEnvironment,
inputConfiguration = kotlinEnvironment.composeWasmConfiguration,
libraries = kotlinEnvironment.COMPOSE_WASM_LIBRARIES,
compilerPlugins = kotlinEnvironment.COMPOSE_WASM_COMPILER_PLUGINS,
compilerPluginOptions = kotlinEnvironment.composeWasmCompilerPluginOptions,
platformConfiguration = kotlinEnvironment.composeWasmConfiguration
).writeIndexesToFile(outputPathComposeWasm)
}
9 changes: 5 additions & 4 deletions indexation/src/main/kotlin/WebIndexationBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class WebIndexationBuilder(
private val kotlinEnvironment: KotlinEnvironment,
inputConfiguration: CompilerConfiguration,
private val libraries: List<String>,
private val compilerPlugins: Boolean,
private val compilerPlugins: List<String>,
private val compilerPluginOptions: List<String>,
private val platformConfiguration: CompilerConfiguration
): IndexationBuilder() {

Expand All @@ -23,10 +24,10 @@ class WebIndexationBuilder(
kotlinEnvironment.environment { coreEnvironment ->
val project = coreEnvironment.project

if (compilerPlugins) {
if (compilerPlugins.isNotEmpty()) {
PluginCliParser.loadPluginsSafe(
kotlinEnvironment.COMPILER_PLUGINS,
kotlinEnvironment.compilerPluginOptions,
compilerPlugins,
compilerPluginOptions,
emptyList(),
configuration
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ class CompletionProvider(
val analysis = when {
projectType.isJvmRelated() -> errorAnalyzer.analysisOf(files, coreEnvironment)
projectType.isJsRelated() -> errorAnalyzer.analyzeFileForJs(files, coreEnvironment)
projectType.isWasmRelated() -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
projectType == ProjectType.WASM -> errorAnalyzer.analyzeFileForWasm(files, coreEnvironment)
projectType == ProjectType.COMPOSE_WASM -> errorAnalyzer.analyzeFileForComposeWasm(files, coreEnvironment)
else -> throw IllegalArgumentException("Unknown project type $projectType")
}
return with(analysis) {
Expand Down
Loading

0 comments on commit 64fa77c

Please sign in to comment.