Skip to content

Commit f8907a2

Browse files
ilgonmicdkrasnoff
authored andcommitted
First version with typeinfo
1 parent 44a201c commit f8907a2

File tree

14 files changed

+159
-183
lines changed

14 files changed

+159
-183
lines changed

build.gradle.kts

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

4141

42-
val kotlinComposeWasmIcLocalCache: Configuration by configurations.creating {
42+
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
4343
isTransitive = false
4444
isCanBeResolved = true
4545
isCanBeConsumed = false
@@ -50,23 +50,7 @@ val kotlinComposeWasmIcLocalCache: Configuration by configurations.creating {
5050
)
5151
attribute(
5252
CacheAttribute.cacheAttribute,
53-
CacheAttribute.LOCAL
54-
)
55-
}
56-
}
57-
58-
val kotlinComposeWasmIcLambdaCache: Configuration by configurations.creating {
59-
isTransitive = false
60-
isCanBeResolved = true
61-
isCanBeConsumed = false
62-
attributes {
63-
attribute(
64-
Category.CATEGORY_ATTRIBUTE,
65-
objects.categoryComposeCache
66-
)
67-
attribute(
68-
CacheAttribute.cacheAttribute,
69-
CacheAttribute.LAMBDA
53+
CacheAttribute.STDLIB
7054
)
7155
}
7256
}
@@ -99,8 +83,7 @@ dependencies {
9983

10084
resourceDependency(libs.skiko.js.wasm.runtime)
10185

102-
kotlinComposeWasmIcLocalCache(project(":cache-maker"))
103-
kotlinComposeWasmIcLambdaCache(project(":cache-maker"))
86+
kotlinComposeWasmStdlibTypeInfo(project(":cache-maker"))
10487
}
10588

10689
fun buildPropertyFile() {
@@ -138,7 +121,7 @@ tasks.withType<KotlinCompile> {
138121
}
139122
dependsOn(":executors:jar")
140123
dependsOn(":indexation:run")
141-
dependsOn(kotlinComposeWasmIcLocalCache)
124+
dependsOn(kotlinComposeWasmStdlibTypeInfo)
142125
buildPropertyFile()
143126
}
144127
println("Using Kotlin compiler ${libs.versions.kotlin.get()}")
@@ -171,7 +154,7 @@ val buildLambda by tasks.creating(Zip::class) {
171154
from(libJVMFolder) { into(libJVM) }
172155
from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
173156
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
174-
from(kotlinComposeWasmIcLambdaCache)
157+
from(kotlinComposeWasmStdlibTypeInfo) { into(cachesComposeWasm) }
175158
into("lib") {
176159
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
177160
}

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)