Skip to content

Commit cad4b53

Browse files
authored
Add support for EGL on Linux Arm64 (#1052)
Requires skia-pack version update before merging: JetBrains/skia-pack#68 Required for my linuxArm64 device which only support EGL. https://youtrack.jetbrains.com/issue/SKIKO-918
1 parent 3af0752 commit cad4b53

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

skiko/build-with-local-skia.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
####### Variables you can edit to change build config, or set same environment variables before script execution #######
3-
SKIA_VERSION="${SKIA_VERSION:="m138-80d088a-1"}" # Version of Skia m###-commit-sha-#. This commit sha will be cloned from repository https://github.com/JetBrains/skia
3+
SKIA_VERSION="${SKIA_VERSION:="m138-80d088a-2"}" # Version of Skia m###-commit-sha-#. This commit sha will be cloned from repository https://github.com/JetBrains/skia
44
SKIA_DEBUG_MODE="${SKIA_DEBUG_MODE:="false"}" # in debug mode Skiko will be published with postix "+debug", for example "0.0.0-SNAPSHOT+debug"
55
SKIA_TARGET="${SKIA_TARGET:="iosSim"}" # possible values: "ios", "iosSim", "macos", "windows", "linux", "wasm", "android", "tvos", "tvosSim"
66
# For M1 Mac use "iosSim" to build for simulator, and ios to build for device.

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,32 @@ fun SkikoProjectContext.createLinkJvmBindings(
271271
)
272272
}
273273
OS.Linux -> {
274-
osFlags = arrayOf(
275-
"-shared",
276-
// `libstdc++.so.6.*` binaries are forward-compatible and used from GCC 3.4 to 16+,
277-
// so do not use `-static-libstdc++` to avoid issues with complex setup.
278-
"-static-libgcc",
279-
"-lGL",
280-
"-lX11",
281-
"-lfontconfig",
282-
// Enforce immediate symbol resolution at library load time to prevent
283-
// lazy-binding issues and make GOT read-only afterwards.
284-
"-Wl,-z,relro,-z,now",
285-
// Hack to fix problem with linker not always finding certain declarations.
286-
"$skiaBinDir/libsksg.a",
287-
"$skiaBinDir/libskia.a",
288-
"$skiaBinDir/libskunicode_core.a",
289-
"$skiaBinDir/libskunicode_icu.a",
290-
"$skiaBinDir/libskshaper.a",
291-
"$skiaBinDir/libjsonreader.a",
292-
293-
)
274+
osFlags = mutableListOf<String>().apply {
275+
addAll(
276+
arrayOf(
277+
"-shared",
278+
// `libstdc++.so.6.*` binaries are forward-compatible and used from GCC 3.4 to 16+,
279+
// so do not use `-static-libstdc++` to avoid issues with complex setup.
280+
"-static-libgcc",
281+
"-lGL",
282+
"-lX11",
283+
"-lfontconfig",
284+
// Enforce immediate symbol resolution at library load time to prevent
285+
// lazy-binding issues and make GOT read-only afterwards.
286+
"-Wl,-z,relro,-z,now",
287+
// Hack to fix problem with linker not always finding certain declarations.
288+
"$skiaBinDir/libsksg.a",
289+
"$skiaBinDir/libskia.a",
290+
"$skiaBinDir/libskunicode_core.a",
291+
"$skiaBinDir/libskunicode_icu.a",
292+
"$skiaBinDir/libskshaper.a",
293+
"$skiaBinDir/libjsonreader.a"
294+
)
295+
)
296+
if (targetArch == Arch.Arm64) {
297+
add("-lEGL")
298+
}
299+
}.toTypedArray()
294300
}
295301
OS.Windows -> {
296302
libDirs.set(windowsSdkPaths.libDirs)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ fun SkikoProjectContext.configureNativeTarget(os: OS, arch: Arch, target: Kotlin
266266
"$skiaBinDir/libskunicode_icu.a",
267267
"$skiaBinDir/libskia.a"
268268
)
269+
if (arch == Arch.Arm64) {
270+
options.add("-lEGL")
271+
}
269272
// When cross-compiling for ARM64 from x64, use the ARM toolchain sysroot
270273
if (arch == Arch.Arm64 && hostArch != Arch.Arm64) {
271274
// ARM GNU toolchain sysroot paths

skiko/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ kotlin.mpp.enableCInteropCommonization=true
77
deploy.version=0.0.0
88

99
# a tag from https://github.com/JetBrains/skia-pack
10-
dependencies.skia=m138-80d088a-1
10+
dependencies.skia=m138-80d088a-2
1111

1212
# a tag from https://github.com/JetBrains/angle-pack
1313
dependencies.angle=ec4d8f8e4d

skiko/src/commonTest/kotlin/org/jetbrains/skia/DirectContextTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class DirectContextNativeTest {
88

99
@Test
1010
fun resourceCacheLimitTest() {
11-
if (!TestGlContext.isAvailabale()) return
11+
if (!TestGlContext.isAvailable()) return
1212

1313
TestGlContext.run {
1414
DirectContext.makeGL().useContext { context ->

skiko/src/commonTest/kotlin/org/jetbrains/skia/SurfaceTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package org.jetbrains.skia
22

33
import org.jetbrains.skia.impl.interopScope
44
import org.jetbrains.skia.impl.use
5+
import org.jetbrains.skiko.Arch
6+
import org.jetbrains.skiko.KotlinBackend
7+
import org.jetbrains.skiko.OS
8+
import org.jetbrains.skiko.hostArch
9+
import org.jetbrains.skiko.hostOs
10+
import org.jetbrains.skiko.kotlinBackend
511
import org.jetbrains.skiko.tests.TestGlContext
612
import org.jetbrains.skiko.tests.allocateBytesForPixels
713
import org.jetbrains.skiko.tests.runTest
@@ -105,8 +111,12 @@ class SurfaceTest {
105111

106112
@Test
107113
fun canMakeRenderTarget() {
108-
if (!TestGlContext.isAvailabale()) return
114+
if (!TestGlContext.isAvailable()) return
109115

116+
if (hostOs == OS.Linux && kotlinBackend == KotlinBackend.Native && hostArch == Arch.Arm64) {
117+
// TODO: fix test on Linux arm64 using EGL
118+
return
119+
}
110120
val pixels = TestGlContext.run {
111121
DirectContext.makeGL().useContext { ctx ->
112122
val imageInfo = ImageInfo.makeN32Premul(16, 16)

skiko/src/commonTest/kotlin/org/jetbrains/skiko/tests/TestHelpers.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package org.jetbrains.skiko.tests
22

33
import org.jetbrains.skia.*
44
import org.jetbrains.skia.impl.*
5-
import org.jetbrains.skiko.Arch
65
import org.jetbrains.skiko.KotlinBackend
76
import org.jetbrains.skiko.OS
8-
import org.jetbrains.skiko.hostArch
97
import org.jetbrains.skiko.hostOs
108
import org.jetbrains.skiko.kotlinBackend
119

@@ -24,20 +22,16 @@ internal class TestGlContext : Managed(TestGlContext_nCreate(), FinalizerHolder.
2422

2523
companion object {
2624

27-
fun isAvailabale(): Boolean {
25+
fun isAvailable(): Boolean {
2826
if (hostOs != OS.Linux || kotlinBackend != KotlinBackend.Native) {
2927
// TODO implement for other platforms and render targets
3028
return false
3129
}
32-
if (hostArch == Arch.Arm64) {
33-
// TODO implement and test EGL on arm64
34-
return false
35-
}
3630
return true
3731
}
3832

3933
inline fun <T> run(block: TestGlContext.() -> T): T {
40-
check(isAvailabale()) { "TestGlContext is not available" }
34+
check(isAvailable()) { "TestGlContext is not available" }
4135
return TestGlContext().use {
4236
it.makeCurrent()
4337
val result = it.block()

0 commit comments

Comments
 (0)