Skip to content

Commit 486f8cd

Browse files
committed
First version with typeinfo
1 parent aaf39de commit 486f8cd

File tree

14 files changed

+160
-185
lines changed

14 files changed

+160
-185
lines changed

build.gradle.kts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ val resourceDependency: Configuration by configurations.creating {
6767
}
6868

6969

70-
val kotlinComposeWasmIcLocalCache: Configuration by configurations.creating {
70+
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
7171
isTransitive = false
7272
isCanBeResolved = true
7373
isCanBeConsumed = false
@@ -78,23 +78,7 @@ val kotlinComposeWasmIcLocalCache: Configuration by configurations.creating {
7878
)
7979
attribute(
8080
CacheAttribute.cacheAttribute,
81-
CacheAttribute.LOCAL
82-
)
83-
}
84-
}
85-
86-
val kotlinComposeWasmIcLambdaCache: Configuration by configurations.creating {
87-
isTransitive = false
88-
isCanBeResolved = true
89-
isCanBeConsumed = false
90-
attributes {
91-
attribute(
92-
Category.CATEGORY_ATTRIBUTE,
93-
objects.categoryComposeCache
94-
)
95-
attribute(
96-
CacheAttribute.cacheAttribute,
97-
CacheAttribute.LAMBDA
81+
CacheAttribute.STDLIB
9882
)
9983
}
10084
}
@@ -127,8 +111,7 @@ dependencies {
127111

128112
resourceDependency(libs.skiko.js.wasm.runtime)
129113

130-
kotlinComposeWasmIcLocalCache(project(":cache-maker"))
131-
kotlinComposeWasmIcLambdaCache(project(":cache-maker"))
114+
kotlinComposeWasmStdlibTypeInfo(project(":cache-maker"))
132115
}
133116

134117
fun buildPropertyFile() {
@@ -165,7 +148,7 @@ tasks.withType<KotlinCompile> {
165148
}
166149
dependsOn(":executors:jar")
167150
dependsOn(":indexation:run")
168-
dependsOn(kotlinComposeWasmIcLocalCache)
151+
dependsOn(kotlinComposeWasmStdlibTypeInfo)
169152
buildPropertyFile()
170153
}
171154
println("Using Kotlin compiler ${libs.versions.kotlin.get()}")
@@ -198,7 +181,7 @@ val buildLambda by tasks.creating(Zip::class) {
198181
from(libJVMFolder) { into(libJVM) }
199182
from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
200183
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
201-
from(kotlinComposeWasmIcLambdaCache)
184+
from(kotlinComposeWasmStdlibTypeInfo) { into(cachesComposeWasm) }
202185
into("lib") {
203186
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
204187
}

buildSrc/src/main/kotlin/CacheAttribute.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import org.gradle.api.attributes.Attribute
22

33
enum class CacheAttribute {
4-
LOCAL,
5-
LAMBDA;
4+
STDLIB;
65

76
companion object {
87
val cacheAttribute = Attribute.of("org.jetbrains.kotlin-compiler-server.cache", CacheAttribute::class.java)

cache-maker/Dockerfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,13 @@ RUN if [ -z "$KOTLIN_VERSION" ]; then \
88
exit 1; \
99
fi
1010

11-
ENV KOTLIN_LIB=$KOTLIN_VERSION
12-
ENV KOTLIN_LIB_JS=${KOTLIN_VERSION}-js
13-
ENV KOTLIN_LIB_WASM=${KOTLIN_VERSION}-wasm
14-
ENV KOTLIN_LIB_COMPOSE_WASM=${KOTLIN_VERSION}-compose-wasm
15-
ENV KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS=${KOTLIN_VERSION}-compose-wasm-compiler-plugins
16-
ENV KOTLIN_CACHES_COMPOSE_WASM=${KOTLIN_VERSION}-caches-compose-wasm
11+
ENV KOTLIN_VERSION=$KOTLIN_VERSION
1712

1813
RUN mkdir -p $BASE_DIR
1914
WORKDIR $BASE_DIR
2015
ADD . $BASE_DIR
2116

22-
RUN rm -rf $KOTLIN_LIB
23-
RUN rm -rf $KOTLIN_LIB_JS
24-
RUN rm -rf $KOTLIN_LIB_WASM
25-
RUN rm -rf $KOTLIN_LIB_COMPOSE_WASM
26-
RUN rm -rf $KOTLIN_COMPOSE_WASM_COMPILER_PLUGINS
27-
RUN rm -rf $KOTLIN_CACHES_COMPOSE_WASM
17+
RUN sed -i 's@kotlin = ".*"@kotlin = "'$KOTLIN_VERSION'"@g' gradle/libs.versions.toml
2818
RUN ./gradlew clean
2919

30-
RUN ./gradlew :cache-maker:run
20+
RUN ./gradlew :cache-maker:compileProductionExecutableKotlinWasmJs

cache-maker/build.gradle.kts

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
plugins {
2-
kotlin("jvm")
3-
application
2+
kotlin("multiplatform")
43
}
54

6-
dependencies {
7-
implementation(project(":common", configuration = "default"))
8-
}
5+
kotlin {
6+
wasmJs {
7+
outputModuleName.set("stdlib")
8+
binaries.executable().forEach {
9+
it.linkTask.configure {
10+
compilerOptions.freeCompilerArgs.add("-Xir-dce=false")
11+
}
12+
}
13+
}
914

10-
application {
11-
mainClass.set("com.compiler.server.cache.MainKt")
15+
sourceSets {
16+
wasmJsMain {
17+
dependencies {
18+
implementation(libs.bundles.compose)
19+
implementation(libs.kotlinx.coroutines.core.compose.wasm)
20+
}
21+
}
22+
}
1223
}
1324

14-
val runTask = tasks.named<JavaExec>("run") {
15-
dependsOn(":dependencies:copyDependencies")
16-
dependsOn(":dependencies:copyWasmDependencies")
17-
dependsOn(":dependencies:copyComposeWasmCompilerPlugins")
18-
dependsOn(":dependencies:copyComposeWasmDependencies")
19-
20-
val kotlinVersion = libs.versions.kotlin.get()
21-
inputs.property("kotlinVersion", kotlinVersion)
22-
23-
inputs.dir(libWasmFolder)
24-
inputs.dir(libComposeWasmFolder)
25-
inputs.dir(libComposeWasmCompilerPluginsFolder)
25+
val composeWasmStdlibTypeInfo: Provider<RegularFile> = layout.buildDirectory
26+
.file("compose-wasm-stdlib-output/stdlib.typeinfo.bin")
2627

27-
outputs.dir(cachesComposeWasmFolder)
28-
29-
args(
30-
kotlinVersion,
31-
libJVMFolder.asFile.absolutePath,
32-
cachesComposeWasmFolder,
33-
)
34-
}
35-
36-
val outputLambdaCacheDir: Provider<Directory> = layout.buildDirectory.dir("incremental-cache")
37-
val buildCacheForLambda by tasks.registering(Exec::class) {
28+
val buildComposeWasmStdlibModule by tasks.registering(Exec::class) {
3829
workingDir = rootDir
3930
executable = "${project.name}/docker-build-incremental-cache.sh"
4031

41-
val outputDir = outputLambdaCacheDir
32+
val outputDir = composeWasmStdlibTypeInfo.map { it.asFile.parentFile }
4233

43-
outputs.dir(outputDir.map { it.dir(cachesComposeWasm) })
34+
inputs.file(layout.projectDirectory.file("Dockerfile"))
35+
inputs.file(layout.projectDirectory.file("docker-build-incremental-cache.sh"))
36+
outputs.dir(outputDir)
4437

4538
argumentProviders.add {
4639
listOf(
4740
lambdaPrefix, // baseDir
48-
outputDir.get().asFile.normalize().absolutePath, // targetDir
41+
outputDir.get().normalize().absolutePath, // targetDir
4942
)
5043
}
5144
}
5245

53-
val kotlinComposeWasmIc: Configuration by configurations.creating {
46+
val prepareTypeInfoIntoComposeWasmCache by tasks.registering(Sync::class) {
47+
dependsOn(buildComposeWasmStdlibModule)
48+
from(composeWasmStdlibTypeInfo)
49+
into(cachesComposeWasmFolder)
50+
}
51+
52+
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
5453
isTransitive = false
5554
isCanBeResolved = false
5655
isCanBeConsumed = true
@@ -62,30 +61,16 @@ val kotlinComposeWasmIc: Configuration by configurations.creating {
6261
}
6362
}
6463

65-
kotlinComposeWasmIc.outgoing.variants.create("local") {
64+
kotlinComposeWasmStdlibTypeInfo.outgoing.variants.create("stdlib") {
6665
attributes {
6766
attribute(
6867
CacheAttribute.cacheAttribute,
69-
CacheAttribute.LOCAL
68+
CacheAttribute.STDLIB
7069
)
7170
}
7271

7372
artifact(cachesComposeWasmFolder) {
7473
type = "directory"
75-
builtBy(runTask)
76-
}
77-
}
78-
79-
kotlinComposeWasmIc.outgoing.variants.create("lambda") {
80-
attributes {
81-
attribute(
82-
CacheAttribute.cacheAttribute,
83-
CacheAttribute.LAMBDA
84-
)
85-
}
86-
87-
artifact(outputLambdaCacheDir) {
88-
type = "directory"
89-
builtBy(buildCacheForLambda)
74+
builtBy(prepareTypeInfoIntoComposeWasmCache)
9075
}
9176
}

cache-maker/docker-build-incremental-cache.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
kotlinVersion=$(awk '{ if ($1 == "kotlin") { gsub(/"/, "", $2); print $2; } }' FS=' = ' ./gradle/libs.versions.toml)
3+
kotlinVersion=$(awk '{ if ($1 == "kotlinWasmStdlibCompiler") { gsub(/"/, "", $2); print $2; } }' FS=' = ' ./gradle/libs.versions.toml)
44

55
baseDir=$1
66
targetDir=$2
@@ -15,7 +15,7 @@ docker build . --file cache-maker/Dockerfile --tag $image_tag --build-arg BASE_D
1515

1616
container=$(docker create $image_tag)
1717

18-
docker cp $container:$baseDir/$kotlinVersion-caches-compose-wasm $targetDir
18+
docker cp $container:$baseDir/cache-maker/build/compileSync/wasmJs/main/productionExecutable/kotlin/. $targetDir
1919

2020
docker start $container
2121
docker stop $container

cache-maker/src/main/kotlin/com/compiler/server/cache/CacheBuilder.kt

Lines changed: 0 additions & 55 deletions
This file was deleted.

cache-maker/src/main/kotlin/com/compiler/server/cache/Main.kt

Lines changed: 0 additions & 14 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)