Skip to content

Commit e2bf12b

Browse files
authored
Preserve profiling information in skiko.wasm with an extra build flag (JetBrains#985)
Adding a new flag `-Pskiko.wasm.withProfiling=true` which adds `--profiling` flag to emcc, so it preserves the function names - makes it easier to use the browser profiler. By default, it's disabled.
1 parent c479fc9 commit e2bf12b

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

skiko/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().config
610610

611611
tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository")
612612
?.dependsOn("publishWasmJsPublicationToComposeRepoRepository")
613+
tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal")
614+
?.dependsOn("publishWasmJsPublicationToMavenLocal")
613615

614616

615617
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {

skiko/buildSrc/src/main/kotlin/properties.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class SkikoProperties(private val myProject: Project) {
126126
val deployVersion: String
127127
get() {
128128
val main = if (isRelease) planeDeployVersion else "$planeDeployVersion-SNAPSHOT"
129-
val metadata = if (buildType == SkiaBuildType.DEBUG) "+debug" else ""
129+
var metadata = if (buildType == SkiaBuildType.DEBUG) "+debug" else ""
130+
metadata += if (isWasmBuildWithProfiling) "+profiling" else ""
130131
return main + metadata
131132
}
132133

@@ -136,6 +137,9 @@ class SkikoProperties(private val myProject: Project) {
136137
val buildType: SkiaBuildType
137138
get() = if (myProject.findProperty("skiko.debug") == "true") SkiaBuildType.DEBUG else SkiaBuildType.RELEASE
138139

140+
val isWasmBuildWithProfiling: Boolean
141+
get() = myProject.findProperty("skiko.wasm.withProfiling") == "true"
142+
139143
val targetArch: Arch
140144
get() = myProject.findProperty("skiko.arch")?.toString()?.let(Arch::byName) ?: hostArch
141145

skiko/buildSrc/src/main/kotlin/tasks/configuration/CommonTasksConfiguration.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
9696
"-DSK_BUILD_FOR_LINUX",
9797
"-D_GLIBCXX_USE_CXX11_ABI=0"
9898
)
99-
OS.Wasm -> listOf(
100-
"-DSKIKO_WASM"
101-
)
99+
OS.Wasm -> mutableListOf<String>().apply {
100+
add("-DSKIKO_WASM")
101+
// add("-sSUPPORT_LONGJMP=wasm") // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
102+
}
102103
OS.Android -> listOf(
103104
"-DSK_BUILD_FOR_ANDROID"
104105
)

skiko/buildSrc/src/main/kotlin/tasks/configuration/WasmTasksConfiguration.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
5656
includeHeadersNonRecursive(skiaHeadersDirs(skiaWasmDir.get()))
5757

5858
flags.set(
59-
listOf(
60-
*skiaPreprocessorFlags(OS.Wasm, buildType),
61-
*buildType.clangFlags,
62-
"-fno-rtti",
63-
"-fno-exceptions",
64-
)
59+
mutableListOf<String?>().apply {
60+
addAll(skiaPreprocessorFlags(OS.Wasm, buildType))
61+
addAll(buildType.clangFlags)
62+
add("-fno-rtti")
63+
add("-fno-exceptions")
64+
if (skiko.isWasmBuildWithProfiling) add("--profiling")
65+
}
6566
)
6667
}
6768

@@ -103,7 +104,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
103104
)
104105

105106
@OptIn(kotlin.ExperimentalStdlibApi::class)
106-
flags.set(buildList {
107+
flags.set(mutableListOf<String?>().apply {
107108
addAll(
108109
listOf(
109110
"-l", "GL",
@@ -117,6 +118,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
117118
"-O2"
118119
)
119120
)
121+
// addAll(listOf("-s", "SUPPORT_LONGJMP=wasm")) // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
120122
if (outputES6) {
121123
addAll(
122124
listOf(
@@ -128,6 +130,8 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
128130
)
129131
)
130132
}
133+
134+
if (skiko.isWasmBuildWithProfiling) add("--profiling")
131135
})
132136

133137
doLast {
@@ -136,11 +140,16 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
136140
val jsFiles = outDir.asFile.get().walk()
137141
.filter { it.isFile && (it.name.endsWith(".js") || it.name.endsWith(".mjs")) }
138142

143+
val isEnvironmentNodeCheckRegex = Regex(
144+
// spaces are different in release and debug builds
145+
"""if\s*\(ENVIRONMENT_IS_NODE\)\s*\{"""
146+
)
147+
139148
for (jsFile in jsFiles) {
140149
val originalContent = jsFile.readText()
141150
val newContent = originalContent.replace("_org_jetbrains", "org_jetbrains")
142151
.replace("skikomjs.wasm", "skiko.wasm")
143-
.replace("if(ENVIRONMENT_IS_NODE){", "if (false) {") // to make webpack erase this part
152+
.replace(isEnvironmentNodeCheckRegex, "if (false) {") // to make webpack erase this part
144153
jsFile.writeText(newContent)
145154

146155
if (outputES6) {

0 commit comments

Comments
 (0)