Skip to content

Commit

Permalink
Use --profiling instead of -g for our needs
Browse files Browse the repository at this point in the history
  • Loading branch information
eymar committed Sep 4, 2024
1 parent 122e08f commit 484c595
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions skiko/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion skiko/buildSrc/src/main/kotlin/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
)
OS.Wasm -> buildList {
add("-DSKIKO_WASM")
if (buildType == SkiaBuildType.DEBUG) add("-g")
// add("-sSUPPORT_LONGJMP=wasm") // TODO(o.karpovich): enable when skia is built with this flag
}
OS.Android -> listOf(
"-DSK_BUILD_FOR_ANDROID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
buildList {
addAll(skiaPreprocessorFlags(OS.Wasm, buildType))
addAll(buildType.clangFlags)
add("-fno-rtti")
add("-fno-exceptions")
if (skiko.isWasmBuildWithProfiling) add("--profiling")
}
)
}

Expand Down Expand Up @@ -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
if (outputES6) {
addAll(
listOf(
Expand All @@ -129,7 +131,7 @@ fun SkikoProjectContext.createWasmLinkTasks(): LinkWasmTasks = with(this.project
)
}

if (buildType == SkiaBuildType.DEBUG) add("-g")
if (skiko.isWasmBuildWithProfiling) add("--profiling")
})

doLast {
Expand All @@ -138,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) {
Expand Down

0 comments on commit 484c595

Please sign in to comment.