Skip to content

Commit 19088f7

Browse files
committed
Adopt #1
1 parent 232c8e5 commit 19088f7

File tree

19 files changed

+114
-136
lines changed

19 files changed

+114
-136
lines changed

build.gradle.kts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ setOf(
6464
}
6565

6666

67-
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
67+
val kotlinComposeWasmStdlibWasmFile: Configuration by configurations.creating {
6868
isTransitive = false
6969
isCanBeResolved = true
7070
isCanBeConsumed = false
@@ -75,7 +75,7 @@ val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
7575
)
7676
attribute(
7777
CacheAttribute.cacheAttribute,
78-
CacheAttribute.TYPEINFO
78+
CacheAttribute.WASM
7979
)
8080
}
8181
}
@@ -106,7 +106,7 @@ dependencies {
106106
}
107107
testImplementation(libs.kotlinx.coroutines.test)
108108

109-
kotlinComposeWasmStdlibTypeInfo(project(":cache-maker"))
109+
kotlinComposeWasmStdlibWasmFile(project(":cache-maker"))
110110
}
111111

112112
fun buildPropertyFile() {
@@ -131,17 +131,16 @@ fun generateProperties(prefix: String = "") = """
131131
libraries.folder.compose-wasm=${prefix + libComposeWasm}
132132
libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPlugins}
133133
libraries.folder.compiler-plugins=${prefix + compilerPluginsForJVM}
134-
caches.folder.compose-wasm=${prefix + cachesComposeWasm}
135134
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
136135
server.compression.enabled=true
137136
server.compression.mime-types=application/json,text/javascript,application/wasm
138137
skiko.version=${libs.versions.skiko.get()}
139138
""".trimIndent()
140139

141140
val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater::class) {
142-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
141+
dependsOn(kotlinComposeWasmStdlibWasmFile)
143142
propertiesPath.set(rootDir.resolve("src/main/resources/${propertyFile}").absolutePath)
144-
typeInfoFile.set(kotlinComposeWasmStdlibTypeInfo.singleFile)
143+
hashableFile.set(kotlinComposeWasmStdlibWasmFile.singleFile)
145144
}
146145

147146
tasks.withType<KotlinCompile> {
@@ -150,7 +149,6 @@ tasks.withType<KotlinCompile> {
150149
}
151150
dependsOn(":executors:jar")
152151
dependsOn(":indexation:run")
153-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
154152
dependsOn(composeWasmPropertiesUpdater)
155153
buildPropertyFile()
156154
}
@@ -187,15 +185,13 @@ val buildLambda by tasks.creating(Zip::class) {
187185
from(libJVMFolder) { into(libJVM) }
188186
from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
189187
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
190-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
191-
from(kotlinComposeWasmStdlibTypeInfo) { into(cachesComposeWasm) }
188+
dependsOn(kotlinComposeWasmStdlibWasmFile)
192189
into("lib") {
193190
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
194191
}
195192
}
196193

197194
tasks.named<Copy>("processResources") {
198-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
199195
dependsOn(composeWasmPropertiesUpdater)
200196
}
201197

buildSrc/src/main/kotlin/CacheAttribute.kt

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

33
enum class CacheAttribute {
44
FULL,
5-
TYPEINFO;
5+
WASM;
66

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

buildSrc/src/main/kotlin/PropertiesUpdater.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class ComposeWasmPropertiesUpdater : DefaultTask() {
1616
abstract val propertiesPath: Property<String>
1717

1818
@get:InputFile
19-
abstract val typeInfoFile: RegularFileProperty
19+
abstract val hashableFile: RegularFileProperty
2020

2121
@get:Input
2222
abstract val propertiesMap: MapProperty<String, String>
@@ -38,7 +38,7 @@ abstract class ComposeWasmPropertiesUpdater : DefaultTask() {
3838
}
3939

4040
file.appendText(
41-
"\ndependencies.compose.wasm=${hashFileContent(typeInfoFile.get().asFile.absolutePath)}"
41+
"\ndependencies.compose.wasm=${hashFileContent(hashableFile.get().asFile.absolutePath)}"
4242
)
4343
}
4444
}

buildSrc/src/main/kotlin/properties.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ val Project.libComposeWasm
2525
get() = "$kotlinVersion-compose-wasm"
2626
val Project.libComposeWasmCompilerPlugins
2727
get() = "$kotlinVersion-compose-wasm-compiler-plugins"
28-
val Project.cachesComposeWasm
29-
get() = "$kotlinVersion-caches-compose-wasm"
3028

3129
val Project.libJVMFolder
3230
get() = rootProject.layout.projectDirectory.dir(libJVM)
@@ -44,7 +42,4 @@ val Project.libComposeWasmFolder
4442
get() = rootProject.layout.projectDirectory.dir(libComposeWasm)
4543

4644
val Project.libComposeWasmCompilerPluginsFolder
47-
get() = rootProject.layout.projectDirectory.dir(libComposeWasmCompilerPlugins)
48-
49-
val Project.cachesComposeWasmFolder
50-
get() = rootProject.layout.projectDirectory.dir(cachesComposeWasm)
45+
get() = rootProject.layout.projectDirectory.dir(libComposeWasmCompilerPlugins)

cache-maker/build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ val buildComposeWasmStdlibModule by tasks.registering(Exec::class) {
4444
args(lambdaPrefix, outputDir.get().asFile.normalize().absolutePath)
4545
}
4646

47-
val prepareTypeInfoIntoComposeWasmCache by tasks.registering(Sync::class) {
48-
dependsOn(buildComposeWasmStdlibModule)
49-
from(composeWasmStdlibTypeInfo)
50-
into(cachesComposeWasmFolder)
51-
}
52-
5347
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
5448
isTransitive = false
5549
isCanBeResolved = false
@@ -79,12 +73,12 @@ kotlinComposeWasmStdlibTypeInfo.outgoing.variants.create("typeinfo") {
7973
attributes {
8074
attribute(
8175
CacheAttribute.cacheAttribute,
82-
CacheAttribute.TYPEINFO
76+
CacheAttribute.WASM
8377
)
8478
}
8579

8680
artifact(composeWasmStdlibTypeInfo) {
87-
builtBy(prepareTypeInfoIntoComposeWasmCache)
81+
builtBy(buildComposeWasmStdlibModule)
8882
}
8983
}
9084

common/src/main/kotlin/com/compiler/server/common/components/CliUtils.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ fun compileWasmArgs(
2929
compilerPlugins: List<String>,
3030
compilerPluginOptions: List<String>,
3131
dependencies: List<String>,
32-
icDir: Path?,
33-
log: (String) -> Unit,
3432
): List<String> {
3533
val compilerPluginsArgs: List<String> = compilerPlugins
3634
.takeIf { it.isNotEmpty() }
@@ -49,11 +47,7 @@ fun compileWasmArgs(
4947
"-libraries=${dependencies.joinToString(PATH_SEPARATOR)}",
5048
"-ir-output-dir=$klibPath",
5149
"-ir-output-name=$moduleName",
52-
).also {
53-
if (icDir != null) {
54-
it.add("-Xwasm-multimodule-mode=slave")
55-
}
56-
} + compilerPluginsArgs
50+
) + compilerPluginsArgs
5751

5852
return filePaths + additionalCompilerArgumentsForKLib
5953
}
@@ -62,7 +56,7 @@ fun linkWasmArgs(
6256
moduleName: String,
6357
klibPath: String,
6458
dependencies: List<String>,
65-
icDir: Path?,
59+
multiModule: Boolean,
6660
outputDir: Path,
6761
debugInfo: Boolean,
6862
): List<String> {
@@ -78,7 +72,7 @@ fun linkWasmArgs(
7872
).also {
7973
if (debugInfo) it.add("-Xwasm-generate-wat")
8074

81-
if (icDir != null) {
75+
if (multiModule) {
8276
it.add("-Xwasm-multimodule-mode=slave")
8377
} else {
8478
it.add("-Xir-dce")

common/src/main/kotlin/com/compiler/server/common/components/KotlinEnvironment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class KotlinEnvironment(
3333
composeWasmCompilerPlugins: List<File>,
3434
val compilerPlugins: List<File> = emptyList(),
3535
composeWasmCompilerPluginsOptions: List<CompilerPluginOption>,
36-
val composeWasmCache: File,
3736
) {
3837
companion object {
3938
/**

common/src/main/kotlin/com/compiler/server/common/components/KotlinEnvironmentConfiguration.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class KotlinEnvironmentConfiguration(
1313
val wasmFile = File("$fileName-wasm")
1414
val composeWasmFile = File("$fileName-compose-wasm")
1515
val composeWasmCompilerPluginsFile = File("$fileName-compose-wasm-compiler-plugins")
16-
val composeWasmCachesFile = File("$fileName-caches-compose-wasm")
1716
val classPath =
1817
listOfNotNull(jvmFile)
1918
.flatMap {
@@ -40,7 +39,6 @@ class KotlinEnvironmentConfiguration(
4039
"false"
4140
),
4241
),
43-
composeWasmCachesFile
4442
)
4543
}
4644
}

resource-server/build.gradle.kts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import org.gradle.kotlin.dsl.support.serviceOf
22
import org.gradle.kotlin.dsl.withType
33
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
4-
import java.nio.file.Files
5-
import kotlin.io.path.createFile
4+
import java.io.FileInputStream
5+
import java.util.Properties
66

77
plugins {
88
alias(libs.plugins.spring.dependency.management)
@@ -32,7 +32,7 @@ val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
3232
)
3333
attribute(
3434
CacheAttribute.cacheAttribute,
35-
CacheAttribute.TYPEINFO
35+
CacheAttribute.WASM
3636
)
3737
}
3838
}
@@ -76,7 +76,7 @@ val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdat
7676

7777
val composeWasmStdlibTypeInfo: FileCollection = kotlinComposeWasmStdlibTypeInfo
7878

79-
typeInfoFile.fileProvider(
79+
hashableFile.fileProvider(
8080
provider {
8181
composeWasmStdlibTypeInfo.singleFile
8282
}
@@ -88,6 +88,8 @@ tasks.withType<KotlinCompile> {
8888
dependsOn(composeWasmPropertiesUpdater)
8989
}
9090

91+
val skikoVersion = libs.versions.skiko
92+
9193
tasks.named<Copy>("processResources") {
9294
dependsOn(kotlinComposeWasmStdlibTypeInfo)
9395
dependsOn(composeWasmPropertiesUpdater)
@@ -96,9 +98,20 @@ tasks.named<Copy>("processResources") {
9698
archiveOperation.zipTree(it)
9799
}) {
98100
into("com/compiler/server")
101+
rename("skiko\\.(.*)", "skiko-${skikoVersion.get()}.\$1")
99102
}
103+
104+
val propertiesFile = composeWasmPropertiesUpdater.flatMap { it.updatedPropertiesFile }
105+
100106
from(kotlinComposeWasmStdlib) {
101107
into("com/compiler/server")
108+
val properties = FileInputStream(propertiesFile.get().asFile).use {
109+
Properties().apply {
110+
load(it)
111+
}
112+
}
113+
114+
rename("stdlib_master\\.(.*)", "stdlib-${properties["dependencies.compose.wasm"]}.\$1")
102115
}
103116
}
104117

resource-server/src/main/kotlin/com/compiler/server/controllers/ResourceRestController.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,23 @@ class ResourceRestController(
2020
@Suppress("unused")
2121
@GetMapping("/skiko-{version}.mjs")
2222
fun getSkikoMjs(@PathVariable version: String): ResponseEntity<Resource> {
23-
if (version != skikoVersion) {
24-
throw IllegalArgumentException("Unexpected skiko version")
25-
}
26-
return cacheableResource("/com/compiler/server/skiko.mjs", MediaType("text", "javascript"))
23+
return cacheableResource("/com/compiler/server/skiko-$version.mjs", MediaType("text", "javascript"))
2724
}
2825

2926
@Suppress("unused")
3027
@GetMapping("/skiko-{version}.wasm")
3128
fun getSkikoWasm(@PathVariable version: String): ResponseEntity<Resource> {
32-
if (version != skikoVersion) {
33-
throw IllegalArgumentException("Unexpected skiko version")
34-
}
35-
return cacheableResource("/com/compiler/server/skiko.wasm", MediaType("application", "wasm"))
29+
return cacheableResource("/com/compiler/server/skiko-$version.wasm", MediaType("application", "wasm"))
3630
}
3731

3832
@GetMapping("/stdlib-{hash}.mjs")
3933
fun getStdlibMjs(@PathVariable hash: String): ResponseEntity<Resource> {
40-
if (hash != dependenciesComposeWasm) {
41-
throw IllegalArgumentException("Unexpected stdlib")
42-
}
43-
return cacheableResource("/com/compiler/server/stdlib_master.uninstantiated.mjs", MediaType("text", "javascript"))
34+
return cacheableResource("/com/compiler/server/stdlib-$hash.uninstantiated.mjs", MediaType("text", "javascript"))
4435
}
4536

4637
@GetMapping("/stdlib-{hash}.wasm")
4738
fun getStdlibWasm(@PathVariable hash: String): ResponseEntity<Resource> {
48-
if (hash != dependenciesComposeWasm) {
49-
throw IllegalArgumentException("Unexpected stdlib")
50-
}
51-
return cacheableResource("/com/compiler/server/stdlib_master.wasm", MediaType("application", "wasm"))
39+
return cacheableResource("/com/compiler/server/stdlib-$hash.wasm", MediaType("application", "wasm"))
5240
}
5341

5442
private fun cacheableResource(path: String, mediaType: MediaType): ResponseEntity<Resource> {

0 commit comments

Comments
 (0)