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 ...@@ -610,6 +610,8 @@ project.tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().config
tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository") tasks.findByName("publishSkikoWasmRuntimePublicationToComposeRepoRepository")
?.dependsOn("publishWasmJsPublicationToComposeRepoRepository") ?.dependsOn("publishWasmJsPublicationToComposeRepoRepository")
tasks.findByName("publishSkikoWasmRuntimePublicationToMavenLocal")
?.dependsOn("publishWasmJsPublicationToMavenLocal")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach { tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {
......
...@@ -126,7 +126,8 @@ class SkikoProperties(private val myProject: Project) { ...@@ -126,7 +126,8 @@ class SkikoProperties(private val myProject: Project) {
val deployVersion: String val deployVersion: String
get() { get() {
val main = if (isRelease) planeDeployVersion else "$planeDeployVersion-SNAPSHOT" 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 return main + metadata
} }
...@@ -136,6 +137,9 @@ class SkikoProperties(private val myProject: Project) { ...@@ -136,6 +137,9 @@ class SkikoProperties(private val myProject: Project) {
val buildType: SkiaBuildType val buildType: SkiaBuildType
get() = if (myProject.findProperty("skiko.debug") == "true") SkiaBuildType.DEBUG else SkiaBuildType.RELEASE 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 val targetArch: Arch
get() = myProject.findProperty("skiko.arch")?.toString()?.let(Arch::byName) ?: hostArch get() = myProject.findProperty("skiko.arch")?.toString()?.let(Arch::byName) ?: hostArch
......
...@@ -96,9 +96,10 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> { ...@@ -96,9 +96,10 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
"-DSK_BUILD_FOR_LINUX", "-DSK_BUILD_FOR_LINUX",
"-D_GLIBCXX_USE_CXX11_ABI=0" "-D_GLIBCXX_USE_CXX11_ABI=0"
) )
OS.Wasm -> listOf( OS.Wasm -> mutableListOf<String>().apply {
"-DSKIKO_WASM" add("-DSKIKO_WASM")
) // add("-sSUPPORT_LONGJMP=wasm") // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
}
OS.Android -> listOf( OS.Android -> listOf(
"-DSK_BUILD_FOR_ANDROID" "-DSK_BUILD_FOR_ANDROID"
) )
......
...@@ -56,12 +56,13 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project ...@@ -56,12 +56,13 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
includeHeadersNonRecursive(skiaHeadersDirs(skiaWasmDir.get())) includeHeadersNonRecursive(skiaHeadersDirs(skiaWasmDir.get()))
flags.set( flags.set(
listOf( mutableListOf<String?>().apply {
*skiaPreprocessorFlags(OS.Wasm, buildType), addAll(skiaPreprocessorFlags(OS.Wasm, buildType))
*buildType.clangFlags, addAll(buildType.clangFlags)
"-fno-rtti", add("-fno-rtti")
"-fno-exceptions", add("-fno-exceptions")
) if (skiko.isWasmBuildWithProfiling) add("--profiling")
}
) )
} }
...@@ -103,7 +104,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project ...@@ -103,7 +104,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
) )
@OptIn(kotlin.ExperimentalStdlibApi::class) @OptIn(kotlin.ExperimentalStdlibApi::class)
flags.set(buildList { flags.set(mutableListOf<String?>().apply {
addAll( addAll(
listOf( listOf(
"-l", "GL", "-l", "GL",
...@@ -117,6 +118,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project ...@@ -117,6 +118,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
"-O2" "-O2"
) )
) )
// addAll(listOf("-s", "SUPPORT_LONGJMP=wasm")) // TODO(o.karpovich): enable when skia is built with this flag (CMP-6628)
if (outputES6) { if (outputES6) {
addAll( addAll(
listOf( listOf(
...@@ -128,6 +130,8 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project ...@@ -128,6 +130,8 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
) )
) )
} }
if (skiko.isWasmBuildWithProfiling) add("--profiling")
}) })
doLast { doLast {
...@@ -136,11 +140,16 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project ...@@ -136,11 +140,16 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
val jsFiles = outDir.asFile.get().walk() val jsFiles = outDir.asFile.get().walk()
.filter { it.isFile && (it.name.endsWith(".js") || it.name.endsWith(".mjs")) } .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) { for (jsFile in jsFiles) {
val originalContent = jsFile.readText() val originalContent = jsFile.readText()
val newContent = originalContent.replace("_org_jetbrains", "org_jetbrains") val newContent = originalContent.replace("_org_jetbrains", "org_jetbrains")
.replace("skikomjs.wasm", "skiko.wasm") .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) jsFile.writeText(newContent)
if (outputES6) { 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