Unverified Commit e2bf12b9 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

Preserve profiling information in skiko.wasm with an extra build flag (#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.
parent c479fc9b
......@@ -610,6 +610,8 @@ project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().config
tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository")
?.dependsOn("publishWasmJsPublicationToComposeRepoRepository")
tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal")
?.dependsOn("publishWasmJsPublicationToMavenLocal")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {
......
......@@ -126,7 +126,8 @@ class SkikoProperties(private val myProject: Project) {
val deployVersion: String
get() {
val main = if (isRelease) planeDeployVersion else "$planeDeployVersion-SNAPSHOT"
val metadata = if (buildType == SkiaBuildType.DEBUG) "+debug" else ""
var metadata = if (buildType == SkiaBuildType.DEBUG) "+debug" else ""
metadata += if (isWasmBuildWithProfiling) "+profiling" else ""
return main + metadata
}
......@@ -136,6 +137,9 @@ class SkikoProperties(private val myProject: Project) {
val buildType: SkiaBuildType
get() = if (myProject.findProperty("skiko.debug") == "true") SkiaBuildType.DEBUG else SkiaBuildType.RELEASE
val isWasmBuildWithProfiling: Boolean
get() = myProject.findProperty("skiko.wasm.withProfiling") == "true"
val targetArch: Arch
get() = myProject.findProperty("skiko.arch")?.toString()?.let(Arch::byName) ?: hostArch
......
......@@ -96,9 +96,10 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
"-DSK_BUILD_FOR_LINUX",
"-D_GLIBCXX_USE_CXX11_ABI=0"
)
OS.Wasm -> listOf(
"-DSKIKO_WASM"
)
OS.Wasm -> mutableListOf<String>().apply {
add("-DSKIKO_WASM")
// add("-sSUPPORT_LONGJMP=wasm") // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
}
OS.Android -> listOf(
"-DSK_BUILD_FOR_ANDROID"
)
......
......@@ -56,12 +56,13 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
includeHeadersNonRecursive(skiaHeadersDirs(skiaWasmDir.get()))
flags.set(
listOf(
*skiaPreprocessorFlags(OS.Wasm, buildType),
*buildType.clangFlags,
"-fno-rtti",
"-fno-exceptions",
)
mutableListOf<String?>().apply {
addAll(skiaPreprocessorFlags(OS.Wasm, buildType))
addAll(buildType.clangFlags)
add("-fno-rtti")
add("-fno-exceptions")
if (skiko.isWasmBuildWithProfiling) add("--profiling")
}
)
}
......@@ -103,7 +104,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
)
@OptIn(kotlin.ExperimentalStdlibApi::class)
flags.set(buildList {
flags.set(mutableListOf<String?>().apply {
addAll(
listOf(
"-l", "GL",
......@@ -117,6 +118,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
"-O2"
)
)
// addAll(listOf("-s", "SUPPORT_LONGJMP=wasm")) // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
if (outputES6) {
addAll(
listOf(
......@@ -128,6 +130,8 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
)
)
}
if (skiko.isWasmBuildWithProfiling) add("--profiling")
})
doLast {
......@@ -136,11 +140,16 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
val jsFiles = outDir.asFile.get().walk()
.filter { it.isFile && (it.name.endsWith(".js") || it.name.endsWith(".mjs")) }
val isEnvironmentNodeCheckRegex = Regex(
// spaces are different in release and debug builds
"""if\s*\(ENVIRONMENT_IS_NODE\)\s*\{"""
)
for (jsFile in jsFiles) {
val originalContent = jsFile.readText()
val newContent = originalContent.replace("_org_jetbrains", "org_jetbrains")
.replace("skikomjs.wasm", "skiko.wasm")
.replace("if(ENVIRONMENT_IS_NODE){", "if (false) {") // to make webpack erase this part
.replace(isEnvironmentNodeCheckRegex, "if (false) {") // to make webpack erase this part
jsFile.writeText(newContent)
if (outputES6) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment