Unverified Commit a7cb9eb3 authored by dima.avdeev's avatar dima.avdeev Committed by GitHub

Build Skiko with local Skia to mavenLocal (#828)

parent 3aa3db3b
......@@ -7,3 +7,5 @@ dependencies/
# Screenshot test actual files
**/src/**/screenshots/*_actual.png
skia-pack
......@@ -22,6 +22,7 @@ build configuration.
./gradlew publishToMavenLocal -Pskiko.native.enabled=true -Pskiko.wasm.enabled=true -Pskiko.android.enabled=true
```
Use flag `-Pskiko.debug=true` to build with debug build type.
Artifact will be published to mavenLocal with postfix "+debug", for example "0.0.0-SNAPSHOT+debug".
##### Publish to `build/repo` directory
```bash
......
#!/usr/bin/env bash
####### Variables you can edit to change build config, or set same environment variables before script execution #######
SKIA_VERSION="${SKIA_VERSION:="m116-51072f3-1"}" # Version of Skia m###-commit-sha-#. This commit sha will be cloned from repository https://github.com/JetBrains/skia
SKIA_DEBUG_MODE="${SKIA_DEBUG_MODE:="false"}" # in debug mode Skiko will be published with postix "+debug", for example "0.0.0-SNAPSHOT+debug"
SKIA_TARGET="${SKIA_TARGET:="iosSim"}" # possible values: "ios", "iosSim", "macos", "windows", "linux", "wasm", "android", "tvos", "tvosSim"
# For M1 Mac use "iosSim" to build for simulator, and ios to build for device.
# For Intel Mac - use "ios" target to build for iOS x64 simulator.
# For Desktop JVM use "macos", "windows", "linux"
########################################################################################################################
if [[ $SKIA_DEBUG_MODE == "true" ]]; then
skikoBuildType=Debug
else
skikoBuildType=Release
fi
case $SKIA_TARGET in
"ios")
if [[ $(uname -m) == 'arm64' ]]; then
SKIKO_TARGET_FLAGS="-Pskiko.native.ios.arm64.enabled=true -Pskiko.awt.enabled=false"
skikoMachines=("arm64")
else
SKIKO_TARGET_FLAGS="-Pskiko.native.ios.x64.enabled=true -Pskiko.awt.enabled=false"
skikoMachines=("x64")
fi
;;
"iosSim")
if [[ $(uname -m) == 'arm64' ]]; then
SKIKO_TARGET_FLAGS="-Pskiko.native.ios.simulatorArm64.enabled=true -Pskiko.awt.enabled=false"
skikoMachines=("arm64")
else
SKIKO_TARGET_FLAGS="-Pskiko.native.ios.x64.enabled=true -Pskiko.awt.enabled=false"
skikoMachines=("x64")
fi
;;
"macos")
SKIKO_TARGET_FLAGS="-Pskiko.awt.enabled=true"
if [[ $(uname -m) == 'arm64' ]]; then
skikoMachines=("arm64" , "x64") # spaces around comma matters
else
skikoMachines=("x64")
fi
;;
"windows")
SKIKO_TARGET_FLAGS="-Pskiko.awt.enabled=true"
if [[ $(uname -m) == 'arm64' ]]; then
skikoMachines=("arm64")
else
skikoMachines=("x64")
fi
;;
"linux")
SKIKO_TARGET_FLAGS="-Pskiko.awt.enabled=true"
if [[ $(uname -m) == 'arm64' ]]; then
skikoMachines=("arm64")
else
skikoMachines=("x64")
fi
;;
"wasm")
SKIKO_TARGET_FLAGS="-Pskiko.wasm.enabled=true -Pskiko.awt.enabled=false"
if [[ $(uname -m) == 'arm64' ]]; then
skikoMachines=("arm64")
else
skikoMachines=("x64")
fi
;;
*)
echo "can't determine skia target"; exit 1
;;
esac
set -e # fail fast
set -x # print all commands
cd "$(dirname "$0")"
SCRIPT_DIR="$(pwd)"
git clone https://github.com/JetBrains/skia-pack.git || echo "skia-pack exists. You can remove it or update by hands with git pull"
cd skia-pack
[ -d "skia" ] && echo "skip cript/checkout.py, because directory skia-pack/skia already exists"
[ ! -d "skia" ] && python3 script/checkout.py --version "$SKIA_VERSION"
for skikoMachine in ${skikoMachines[@]}; do
python3 script/build.py --target "$SKIA_TARGET" --machine "$skikoMachine" --build-type "$skikoBuildType"
python3 script/archive.py --version "$SKIA_VERSION" --target "$SKIA_TARGET" --machine "$skikoMachine" --build-type "$skikoBuildType"
done
cd "$SCRIPT_DIR"
rm -rf build/classes/kotlin/* # We need to drop old cache. We can do it with ./gradlew clean as well, but it tooks longer time to redownload dependencies dir.
./gradlew publishToMavenLocal $SKIKO_TARGET_FLAGS -Pskia.dir="$(pwd)/skia-pack/skia" -Pskiko.debug=$SKIA_DEBUG_MODE
......@@ -213,9 +213,37 @@ internal val Project.isInIdea: Boolean
return System.getProperty("idea.active")?.toBoolean() == true
}
val Project.supportNative: Boolean
val Project.supportAwt: Boolean
get() = findProperty("skiko.awt.enabled") == "true" || isInIdea
val Project.supportAllNative: Boolean
get() = findProperty("skiko.native.enabled") == "true" || isInIdea
val Project.supportAllNativeIos: Boolean
get() = supportAllNative || findProperty("skiko.native.ios.enabled") == "true" || isInIdea
val Project.supportNativeIosArm64: Boolean
get() = supportAllNativeIos || findProperty("skiko.native.ios.arm64.enabled") == "true" || isInIdea
val Project.supportNativeIosSimulatorArm64: Boolean
get() = supportAllNativeIos || findProperty("skiko.native.ios.simulatorArm64.enabled") == "true" || isInIdea
val Project.supportNativeIosX64: Boolean
get() = supportAllNativeIos || findProperty("skiko.native.ios.x64.enabled") == "true" || isInIdea
val Project.supportAnyNativeIos: Boolean
get() = supportAllNativeIos || supportNativeIosArm64 || supportNativeIosSimulatorArm64 || supportNativeIosX64
val Project.supportNativeMac: Boolean
get() = supportAllNative || findProperty("skiko.native.mac.enabled") == "true" || isInIdea
val Project.supportNativeLinux: Boolean
get() = supportAllNative || findProperty("skiko.native.linux.enabled") == "true" || isInIdea
val Project.supportAnyNative: Boolean
get() = supportAllNative || supportAnyNativeIos || supportNativeMac || supportNativeLinux
val Project.supportWasm: Boolean
get() = findProperty("skiko.wasm.enabled") == "true" || isInIdea
......@@ -223,11 +251,13 @@ val Project.supportAndroid: Boolean
get() = findProperty("skiko.android.enabled") == "true" // || isInIdea
kotlin {
jvm("awt") {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
if (supportAwt) {
jvm("awt") {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
generateVersion(targetOs, targetArch)
}
generateVersion(targetOs, targetArch)
}
if (supportAndroid) {
......@@ -261,14 +291,22 @@ kotlin {
}
}
if (supportNative) {
if (supportNativeMac) {
configureNativeTarget(OS.MacOS, Arch.X64, macosX64())
configureNativeTarget(OS.MacOS, Arch.Arm64, macosArm64())
}
if (supportNativeLinux) {
configureNativeTarget(OS.Linux, Arch.X64, linuxX64())
}
if (supportNativeIosArm64) {
configureNativeTarget(OS.IOS, Arch.Arm64, iosArm64())
configureNativeTarget(OS.IOS, Arch.X64, iosX64())
}
if (supportNativeIosSimulatorArm64) {
configureNativeTarget(OS.IOS, Arch.Arm64, iosSimulatorArm64())
}
if (supportNativeIosX64) {
configureNativeTarget(OS.IOS, Arch.X64, iosX64())
}
sourceSets {
val commonMain by getting {
......@@ -291,9 +329,10 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion")
}
}
val awtMain by getting {
dependsOn(jvmMain)
if (supportAwt) {
val awtMain by getting {
dependsOn(jvmMain)
}
}
if (supportAndroid) {
......@@ -314,8 +353,10 @@ kotlin {
}
}
val awtTest by getting {
dependsOn(jvmTest)
if (supportAwt) {
val awtTest by getting {
dependsOn(jvmTest)
}
}
if (supportAndroid) {
......@@ -324,7 +365,7 @@ kotlin {
}
}
if (supportWasm || supportNative) {
if (supportWasm || supportAnyNative) {
val nativeJsMain by creating {
dependsOn(commonMain)
}
......@@ -347,7 +388,7 @@ kotlin {
}
}
if (supportNative) {
if (supportAnyNative) {
all {
// Really ugly, see https://youtrack.jetbrains.com/issue/KT-46649 why it is required,
// note that setting it per source set still keeps it unset in commonized source sets.
......@@ -363,65 +404,79 @@ kotlin {
val nativeTest by creating {
dependsOn(nativeJsTest)
}
val linuxMain by creating {
dependsOn(nativeMain)
}
val linuxTest by creating {
dependsOn(nativeTest)
}
val linuxX64Main by getting {
dependsOn(linuxMain)
}
val linuxX64Test by getting {
dependsOn(linuxTest)
}
val darwinMain by creating {
dependsOn(nativeMain)
}
val darwinTest by creating {
dependsOn(nativeTest)
}
val macosMain by creating {
dependsOn(darwinMain)
}
val macosTest by creating {
dependsOn(darwinTest)
}
val iosMain by creating {
dependsOn(darwinMain)
}
val iosTest by creating {
dependsOn(darwinTest)
}
val macosX64Main by getting {
dependsOn(macosMain)
}
val macosX64Test by getting {
dependsOn(macosTest)
}
val macosArm64Main by getting {
dependsOn(macosMain)
}
val macosArm64Test by getting {
dependsOn(macosTest)
}
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosX64Test by getting {
dependsOn(iosTest)
}
val iosArm64Main by getting {
dependsOn(iosMain)
}
val iosArm64Test by getting {
dependsOn(iosTest)
}
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
if (supportNativeLinux) {
val linuxMain by creating {
dependsOn(nativeMain)
}
val linuxTest by creating {
dependsOn(nativeTest)
}
val linuxX64Main by getting {
dependsOn(linuxMain)
}
val linuxX64Test by getting {
dependsOn(linuxTest)
}
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
if (supportAnyNativeIos || supportNativeMac) {
val darwinMain by creating {
dependsOn(nativeMain)
}
val darwinTest by creating {
dependsOn(nativeTest)
}
if (supportNativeMac) {
val macosMain by creating {
dependsOn(darwinMain)
}
val macosTest by creating {
dependsOn(darwinTest)
}
val macosX64Main by getting {
dependsOn(macosMain)
}
val macosX64Test by getting {
dependsOn(macosTest)
}
val macosArm64Main by getting {
dependsOn(macosMain)
}
val macosArm64Test by getting {
dependsOn(macosTest)
}
}
if (supportAnyNativeIos) {
val iosMain by creating {
dependsOn(darwinMain)
}
val iosTest by creating {
dependsOn(darwinTest)
}
if (supportNativeIosArm64) {
val iosArm64Main by getting {
dependsOn(iosMain)
}
val iosArm64Test by getting {
dependsOn(iosTest)
}
}
if (supportNativeIosSimulatorArm64) {
val iosSimulatorArm64Main by getting {
dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
dependsOn(iosTest)
}
}
if (supportNativeIosX64) {
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosX64Test by getting {
dependsOn(iosTest)
}
}
}
}
}
}
......@@ -683,14 +738,6 @@ fun skiaStaticLibraries(skiaDir: String, targetString: String): List<String> {
val allJvmRuntimeJars = mutableMapOf<Pair<OS, Arch>, TaskProvider<Jar>>()
val skikoAwtJarForTests by project.tasks.registering(Jar::class) {
archiveBaseName.set("skiko-awt-test")
from(kotlin.jvm("awt").compilations["main"].output.allOutputs)
}
val skikoAwtRuntimeJarForTests = createSkikoJvmJarTask(targetOs, targetArch, skikoAwtJarForTests)
val skikoRuntimeDirForTests = skikoRuntimeDirForTestsTask(targetOs, targetArch, skikoAwtJarForTests, skikoAwtRuntimeJarForTests)
val skikoJarForTests = skikoJarForTestsTask(skikoRuntimeDirForTests)
if (supportAndroid) {
val os = OS.Android
val skikoAndroidJar by project.tasks.registering(Jar::class) {
......@@ -1196,38 +1243,48 @@ fun skikoJarForTestsTask(
archiveFileName.set("skiko-runtime-for-tests.jar")
}
tasks.withType<Test>().configureEach {
dependsOn(skikoRuntimeDirForTests)
dependsOn(skikoJarForTests)
options {
val dir = skikoRuntimeDirForTests.map { it.destinationDir }.get()
systemProperty("skiko.library.path", dir)
val jar = skikoJarForTests.get().outputs.files.files.single { it.name.endsWith(".jar") }
systemProperty("skiko.jar.path", jar.absolutePath)
systemProperty("skiko.test.screenshots.dir", File(project.projectDir, "src/jvmTest/screenshots").absolutePath)
systemProperty("skiko.test.font.dir", File(project.projectDir, "src/commonTest/resources/fonts").absolutePath)
val testingOnCI = System.getProperty("skiko.test.onci", "false").toBoolean()
val canRunPerformanceTests = testingOnCI
val canRunUiTests = testingOnCI || System.getProperty("os.name") != "Mac OS X"
systemProperty(
"skiko.test.performance.enabled",
System.getProperty("skiko.test.performance.enabled", canRunPerformanceTests.toString())
)
systemProperty("skiko.test.ui.enabled", System.getProperty("skiko.test.ui.enabled", canRunUiTests.toString()))
systemProperty("skiko.test.ui.renderApi", System.getProperty("skiko.test.ui.renderApi", "all"))
systemProperty("skiko.test.debug", buildType == SkiaBuildType.DEBUG)
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
if (supportAwt) {
val skikoAwtJarForTests by project.tasks.registering(Jar::class) {
archiveBaseName.set("skiko-awt-test")
from(kotlin.jvm("awt").compilations["main"].output.allOutputs)
}
val skikoAwtRuntimeJarForTests = createSkikoJvmJarTask(targetOs, targetArch, skikoAwtJarForTests)
val skikoRuntimeDirForTests = skikoRuntimeDirForTestsTask(targetOs, targetArch, skikoAwtJarForTests, skikoAwtRuntimeJarForTests)
val skikoJarForTests = skikoJarForTestsTask(skikoRuntimeDirForTests)
tasks.withType<Test>().configureEach {
dependsOn(skikoRuntimeDirForTests)
dependsOn(skikoJarForTests)
options {
val dir = skikoRuntimeDirForTests.map { it.destinationDir }.get()
systemProperty("skiko.library.path", dir)
val jar = skikoJarForTests.get().outputs.files.files.single { it.name.endsWith(".jar") }
systemProperty("skiko.jar.path", jar.absolutePath)
systemProperty("skiko.test.screenshots.dir", File(project.projectDir, "src/jvmTest/screenshots").absolutePath)
systemProperty("skiko.test.font.dir", File(project.projectDir, "src/commonTest/resources/fonts").absolutePath)
val testingOnCI = System.getProperty("skiko.test.onci", "false").toBoolean()
val canRunPerformanceTests = testingOnCI
val canRunUiTests = testingOnCI || System.getProperty("os.name") != "Mac OS X"
systemProperty(
"skiko.test.performance.enabled",
System.getProperty("skiko.test.performance.enabled", canRunPerformanceTests.toString())
)
systemProperty("skiko.test.ui.enabled", System.getProperty("skiko.test.ui.enabled", canRunUiTests.toString()))
systemProperty("skiko.test.ui.renderApi", System.getProperty("skiko.test.ui.renderApi", "all"))
systemProperty("skiko.test.debug", buildType == SkiaBuildType.DEBUG)
// Tests should be deterministic, so disable scaling.
// On MacOs we need the actual scale, otherwise we will have aliased screenshots because of scaling.
if (System.getProperty("os.name") != "Mac OS X") {
systemProperty("sun.java2d.dpiaware", "false")
systemProperty("sun.java2d.uiScale", "1")
}
}
jvmArgs = listOf("--add-opens", "java.desktop/sun.font=ALL-UNNAMED")
jvmArgs = listOf("--add-opens", "java.desktop/sun.font=ALL-UNNAMED")
}
}
afterEvaluate {
......
......@@ -20,3 +20,14 @@ dependencies.skia.android-arm64=m116-51072f3-1
org.gradle.jvmargs=-Xmx3G -XX:MaxMetaspaceSize=512m
kotlin.native.cacheKind.macosX64=none
kotlin.native.cacheKind.iosX64=none
skiko.awt.enabled=true
skiko.wasm.enabled=false
skiko.android.enabled=false
skiko.native.enabled=false
skiko.native.linux.enabled=false
skiko.native.mac.enabled=false
skiko.native.ios.enabled=false
skiko.native.ios.arm64.enabled=false
skiko.native.ios.simulatorArm64.enabled=false
skiko.native.ios.x64.enabled=false
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