Skip to content

Commit f2eb7d4

Browse files
ilgonmicdkrasnoff
authored andcommitted
Adopt #1
1 parent 278c883 commit f2eb7d4

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
@@ -37,7 +37,7 @@ allprojects {
3737
}
3838

3939

40-
val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
40+
val kotlinComposeWasmStdlibWasmFile: Configuration by configurations.creating {
4141
isTransitive = false
4242
isCanBeResolved = true
4343
isCanBeConsumed = false
@@ -48,7 +48,7 @@ val kotlinComposeWasmStdlibTypeInfo: Configuration by configurations.creating {
4848
)
4949
attribute(
5050
CacheAttribute.cacheAttribute,
51-
CacheAttribute.TYPEINFO
51+
CacheAttribute.WASM
5252
)
5353
}
5454
}
@@ -79,7 +79,7 @@ dependencies {
7979
}
8080
testImplementation(libs.kotlinx.coroutines.test)
8181

82-
kotlinComposeWasmStdlibTypeInfo(project(":cache-maker"))
82+
kotlinComposeWasmStdlibWasmFile(project(":cache-maker"))
8383
}
8484

8585
fun buildPropertyFile() {
@@ -104,7 +104,6 @@ fun generateProperties(prefix: String = "") = """
104104
libraries.folder.compose-wasm=${prefix + libComposeWasm}
105105
libraries.folder.compose-wasm-compiler-plugins=${prefix + libComposeWasmCompilerPlugins}
106106
libraries.folder.compiler-plugins=${prefix + compilerPluginsForJVM}
107-
caches.folder.compose-wasm=${prefix + cachesComposeWasm}
108107
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
109108
server.compression.enabled=true
110109
server.compression.mime-types=application/json,text/javascript,application/wasm
@@ -113,9 +112,9 @@ fun generateProperties(prefix: String = "") = """
113112
""".trimIndent()
114113

115114
val composeWasmPropertiesUpdater by tasks.registering(ComposeWasmPropertiesUpdater::class) {
116-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
115+
dependsOn(kotlinComposeWasmStdlibWasmFile)
117116
propertiesPath.set(rootDir.resolve("src/main/resources/${propertyFile}").absolutePath)
118-
typeInfoFile.set(kotlinComposeWasmStdlibTypeInfo.singleFile)
117+
hashableFile.set(kotlinComposeWasmStdlibWasmFile.singleFile)
119118
}
120119

121120
tasks.withType<KotlinCompile> {
@@ -124,7 +123,6 @@ tasks.withType<KotlinCompile> {
124123
}
125124
dependsOn(":executors:jar")
126125
dependsOn(":indexation:run")
127-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
128126
dependsOn(composeWasmPropertiesUpdater)
129127
buildPropertyFile()
130128
}
@@ -161,15 +159,13 @@ val buildLambda by tasks.creating(Zip::class) {
161159
from(libJVMFolder) { into(libJVM) }
162160
from(compilerPluginsForJVMFolder) {into(compilerPluginsForJVM)}
163161
from(libComposeWasmCompilerPluginsFolder) { into(libComposeWasmCompilerPlugins) }
164-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
165-
from(kotlinComposeWasmStdlibTypeInfo) { into(cachesComposeWasm) }
162+
dependsOn(kotlinComposeWasmStdlibWasmFile)
166163
into("lib") {
167164
from(configurations.compileClasspath) { exclude("tomcat-embed-*") }
168165
}
169166
}
170167

171168
tasks.named<Copy>("processResources") {
172-
dependsOn(kotlinComposeWasmStdlibTypeInfo)
173169
dependsOn(composeWasmPropertiesUpdater)
174170
}
175171

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
@@ -34,7 +34,6 @@ class KotlinEnvironment(
3434
composeWasmCompilerPlugins: List<File>,
3535
val compilerPlugins: List<File> = emptyList(),
3636
composeWasmCompilerPluginsOptions: List<CompilerPluginOption>,
37-
val composeWasmCache: File,
3837
) {
3938
companion object {
4039
/**

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)