-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
163 lines (142 loc) · 4.82 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
plugins {
alias(libs.plugins.org.jetbrains.kotlin.multiplatform)
alias(libs.plugins.org.jetbrains.compose)
}
buildscript {
dependencies {
classpath(libs.org.jetbrains.kotlinx.atomicfu.gradle.plugin)
}
}
apply(plugin = "kotlinx-atomicfu")
group = "com.example"
version = "0.0-SNAPSHOT"
val useJs = System.getProperty("application.useJs") == "true"
val optimizeAggressively = System.getProperty("application.optimize") == "true"
kotlin {
val jdkVersion = project.property("local.jdk.version").toString().toInt()
jvmToolchain(jdkVersion)
jvm {
compilations.configureEach {
kotlinOptions.freeCompilerArgs += listOf("-Xjdk-release=$jdkVersion")
}
}
jvm {
withJava()
}
js {
moduleName = "app"
binaries.executable()
browser {
useCommonJs()
commonWebpackConfig {
outputFileName = "$moduleName.js"
}
}
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
moduleName = "app"
binaries.executable()
browser {
commonWebpackConfig {
outputFileName = "$moduleName.js"
devServer =
(devServer ?: KotlinWebpackConfig.DevServer()).copy(
port = 8081,
static =
(devServer?.static ?: mutableListOf()).apply {
// Serve sources to debug inside browser
add(project.rootDir.path)
}
)
}
}
applyBinaryen {
binaryenArgs =
mutableListOf(
"--enable-nontrapping-float-to-int",
"--enable-gc",
"--enable-reference-types",
"--enable-exception-handling",
"--enable-bulk-memory",
"--inline-functions-with-loops",
"--traps-never-happen",
"--fast-math"
)
binaryenArgs +=
if (optimizeAggressively) {
listOf(
"--closed-world",
// "--metrics",
"-O3",
"--gufa", // "--metrics",
"-O3",
"--gufa", // "--metrics",
"-O3",
"--gufa" // "--metrics"
)
} else {
listOf(
"-O1",
"-c" // Run passes while binary size decreases
)
}
}
}
sourceSets {
all {
languageSettings {
progressiveMode = true
optIn("kotlin.RequiresOptIn")
}
}
val commonMain by getting {
dependencies {
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material)
implementation(libs.org.jetbrains.kotlinx.atomicfu)
implementation(libs.org.jetbrains.kotlinx.kotlinx.datetime)
}
}
val jvmMain by getting {
dependencies {
implementation(compose.desktop.currentOs)
}
}
val jsMain by getting {
dependencies {
@Suppress("DEPRECATION")
implementation(compose.web.core) // Required for Compose Web/Canvas on JS
}
}
}
}
compose {
providers.gradleProperty("local.compose.kotlinCompilerPlugin").orNull?.let { composeKotlinCompilerPlugin ->
kotlinCompilerPlugin.set(composeKotlinCompilerPlugin)
val kotlinVersion = "${libs.plugins.org.jetbrains.kotlin.multiplatform.get().version}"
kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=$kotlinVersion")
}
// kotlinCompilerPluginArgs.add("reportsDestination=${layout.buildDirectory.file("reports")}")
desktop.application.mainClass = "MainKt"
experimental {
web.application {}
}
}
// Hack to use kotlinx-datetime with Wasm
rootProject.tasks {
val hackNodeModuleImports by registering(Copy::class) {
group = "kotlin browser"
mustRunAfter("kotlinNpmInstall")
from(layout.buildDirectory.file("js/node_modules/@js-joda"))
into(layout.buildDirectory.file("js/packages/app/kotlin/@js-joda"))
}
for (dependent in listOf("wasmJsBrowserProductionRun", "wasmJsBrowserDevelopmentRun")) {
named(dependent) {
dependsOn(hackNodeModuleImports)
}
}
}