Unverified Commit 09d1b61f authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Macos arm (#19)

parent c412e811
...@@ -14,17 +14,27 @@ repositories { ...@@ -14,17 +14,27 @@ repositories {
} }
} }
def os = System.getProperty("os.name") def osName = System.getProperty("os.name")
def target = "" def targetOs = ""
if (os == "Mac OS X") { if (osName == "Mac OS X") {
target = "macos" targetOs = "macos"
} else if (os.startsWith("Win")) { } else if (osName.startsWith("Win")) {
target = "windows" targetOs = "windows"
} else if (os.startsWith("Linux")) { } else if (osName.startsWith("Linux")) {
target = "linux" targetOs = "linux"
} else { } else {
throw Error("Unsupported OS: $target") throw Error("Unsupported OS: $os")
} }
def osArch = System.getProperty("os.arch")
def targetArch = ""
if (osArch == "x86_64") {
targetArch = "x64"
} else if (osArch == "aarch64") {
targetArch = "arm64"
} else {
throw Error("Unsupported arch: $osArch")
}
def target = "${targetOs}_${targetArch}"
def version = "0.1-SNAPSHOT" def version = "0.1-SNAPSHOT"
if (project.hasProperty('skiko.version')) { if (project.hasProperty('skiko.version')) {
......
...@@ -142,11 +142,11 @@ kotlin { ...@@ -142,11 +142,11 @@ kotlin {
withJava() withJava()
} }
val isMingwX64 = hostOs.startsWith("Windows") val nativeTarget = when (targetOs) {
val nativeTarget = when { // TODO: not entirely correct for macOS ARM.
hostOs == "Mac OS X" -> macosX64("native") OS.MacOS -> macosX64("native")
hostOs == "Linux" -> linuxX64("native") OS.Linux -> linuxX64("native")
isMingwX64 -> mingwX64("native") OS.Windows -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.") else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
} }
...@@ -221,8 +221,8 @@ tasks.withType(CppCompile::class.java).configureEach { ...@@ -221,8 +221,8 @@ tasks.withType(CppCompile::class.java).configureEach {
"-DSK_UNICODE_AVAILABLE", "-DSK_UNICODE_AVAILABLE",
"-DNDEBUG" "-DNDEBUG"
)) ))
when (target) { when (targetOs) {
"macos" -> { OS.MacOS -> {
compilerArgs.addAll( compilerArgs.addAll(
listOf( listOf(
"-std=c++14", "-std=c++14",
...@@ -236,7 +236,7 @@ tasks.withType(CppCompile::class.java).configureEach { ...@@ -236,7 +236,7 @@ tasks.withType(CppCompile::class.java).configureEach {
) )
) )
} }
"linux" -> { OS.Linux -> {
compilerArgs.addAll( compilerArgs.addAll(
listOf( listOf(
"-std=c++14", "-std=c++14",
...@@ -249,7 +249,7 @@ tasks.withType(CppCompile::class.java).configureEach { ...@@ -249,7 +249,7 @@ tasks.withType(CppCompile::class.java).configureEach {
) )
) )
} }
"windows" -> { OS.Windows -> {
compilerArgs.addAll( compilerArgs.addAll(
listOf( listOf(
"-I$jdkHome/include/win32", "-I$jdkHome/include/win32",
...@@ -271,7 +271,7 @@ tasks.withType(CppCompile::class.java).configureEach { ...@@ -271,7 +271,7 @@ tasks.withType(CppCompile::class.java).configureEach {
// Very hacky way to compile Objective-C sources and add the // Very hacky way to compile Objective-C sources and add the
// resulting object files into the final library. // resulting object files into the final library.
project.tasks.register<Exec>("objcCompile") { project.tasks.register<Exec>("objcCompile") {
val inputDir = "$projectDir/src/jvmMain/objectiveC/$target" val inputDir = "$projectDir/src/jvmMain/objectiveC/${targetOs.id}"
val outDir = "$buildDir/objc/$target" val outDir = "$buildDir/objc/$target"
val objcSrc = "drawlayer" val objcSrc = "drawlayer"
commandLine = listOf( commandLine = listOf(
...@@ -290,8 +290,8 @@ project.tasks.register<Exec>("objcCompile") { ...@@ -290,8 +290,8 @@ project.tasks.register<Exec>("objcCompile") {
} }
tasks.withType(LinkSharedLibrary::class.java).configureEach { tasks.withType(LinkSharedLibrary::class.java).configureEach {
when (target) { when (targetOs) {
"macos" -> { OS.MacOS -> {
dependsOn(project.tasks.named("objcCompile")) dependsOn(project.tasks.named("objcCompile"))
linkerArgs.addAll( linkerArgs.addAll(
listOf( listOf(
...@@ -308,7 +308,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach { ...@@ -308,7 +308,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach {
) )
) )
} }
"linux" -> { OS.Linux -> {
linkerArgs.addAll( linkerArgs.addAll(
listOf( listOf(
"-lGL", "-lGL",
...@@ -316,7 +316,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach { ...@@ -316,7 +316,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach {
) )
) )
} }
"windows" -> { OS.Windows -> {
linkerArgs.addAll( linkerArgs.addAll(
listOf( listOf(
"gdi32.lib", "gdi32.lib",
...@@ -333,7 +333,7 @@ extensions.configure<CppLibrary> { ...@@ -333,7 +333,7 @@ extensions.configure<CppLibrary> {
source.from( source.from(
skijaDir.map { fileTree(it.resolve("native/src")) }, skijaDir.map { fileTree(it.resolve("native/src")) },
fileTree("$projectDir/src/jvmMain/cpp/common"), fileTree("$projectDir/src/jvmMain/cpp/common"),
fileTree("$projectDir/src/jvmMain/cpp/$target") fileTree("$projectDir/src/jvmMain/cpp/${targetOs.id}")
) )
} }
...@@ -345,8 +345,8 @@ library { ...@@ -345,8 +345,8 @@ library {
dependencies { dependencies {
implementation( implementation(
skiaDir.map { skiaDir.map {
fileTree(it.resolve("out/Release-x64")) fileTree(it.resolve("out/Release-${targetArch.id}"))
.matching { include(if (target == "windows") "**.lib" else "**.a") } .matching { include(if (targetOs.isWindows) "**.lib" else "**.a") }
} }
) )
implementation(fileTree("$buildDir/objc/$target").matching { implementation(fileTree("$buildDir/objc/$target").matching {
...@@ -371,10 +371,10 @@ val skikoJvmJar: Provider<Jar> by tasks.registering(Jar::class) { ...@@ -371,10 +371,10 @@ val skikoJvmJar: Provider<Jar> by tasks.registering(Jar::class) {
} }
val createChecksums by project.tasks.registering(org.gradle.crypto.checksum.Checksum::class) { val createChecksums by project.tasks.registering(org.gradle.crypto.checksum.Checksum::class) {
val linkTask = project.tasks.named("linkRelease${target.capitalize()}") val linkTask = project.tasks.named("linkRelease${targetOs.id.capitalize()}")
dependsOn(linkTask) dependsOn(linkTask)
files = linkTask.get().outputs.files.filter { it.isFile } + files = linkTask.get().outputs.files.filter { it.isFile } +
if (target == "windows") files(skiaDir.map { it.resolve("out/Release-x64/icudtl.dat") }) else files() if (targetOs.isWindows) files(skiaDir.map { it.resolve("out/Release-x64/icudtl.dat") }) else files()
algorithm = Checksum.Algorithm.SHA256 algorithm = Checksum.Algorithm.SHA256
outputDir = file("$buildDir/checksums") outputDir = file("$buildDir/checksums")
} }
...@@ -383,10 +383,10 @@ val skikoJvmRuntimeJar by project.tasks.registering(Jar::class) { ...@@ -383,10 +383,10 @@ val skikoJvmRuntimeJar by project.tasks.registering(Jar::class) {
archiveBaseName.set("skiko-$target") archiveBaseName.set("skiko-$target")
dependsOn(createChecksums) dependsOn(createChecksums)
from(skikoJvmJar.map { zipTree(it.archiveFile) }) from(skikoJvmJar.map { zipTree(it.archiveFile) })
from(project.tasks.named("linkRelease${target.capitalize()}").map { from(project.tasks.named("linkRelease${targetOs.id.capitalize()}").map {
it.outputs.files.filter { it.isFile } it.outputs.files.filter { it.isFile }
}) })
if (target == "windows") { if (targetOs.isWindows) {
from(files(skiaDir.map { it.resolve("out/Release-x64/icudtl.dat") })) from(files(skiaDir.map { it.resolve("out/Release-x64/icudtl.dat") }))
} }
from(createChecksums.get().outputs.files) from(createChecksums.get().outputs.files)
......
import org.gradle.api.Project import org.gradle.api.Project
import java.io.File import java.io.File
val hostOs = System.getProperty("os.name") enum class OS(val id: String) {
val target = when { Linux("linux"),
hostOs == "Mac OS X" -> "macos" Windows("windows"),
hostOs == "Linux" -> "linux" MacOS("macos")
hostOs.startsWith("Win") -> "windows" ;
else -> throw Error("Unknown os $hostOs")
val isWindows
get() = this == Windows
}
enum class Arch(val id: String) {
X64("x64"),
Arm64("arm64")
}
val hostOs by lazy {
val osName = System.getProperty("os.name")
when {
osName == "Mac OS X" -> OS.MacOS
osName == "Linux" -> OS.Linux
osName.startsWith("Win") -> OS.Windows
else -> throw Error("Unknown OS $osName")
}
} }
val hostArch by lazy {
val osArch = System.getProperty("os.arch").also {
println("arch is $it")
}
when (osArch) {
"x86_64" -> Arch.X64
"aarch64" -> Arch.Arm64
else -> throw Error("Unknown arch $osArch")
}
}
val targetOs = hostOs
val targetArch = hostArch
val target = "${targetOs.id}_${targetArch.id}"
val jdkHome = System.getProperty("java.home") ?: error("'java.home' is null") val jdkHome = System.getProperty("java.home") ?: error("'java.home' is null")
class SkikoProperties(private val myProject: Project) { class SkikoProperties(private val myProject: Project) {
...@@ -42,7 +76,8 @@ class SkikoProperties(private val myProject: Project) { ...@@ -42,7 +76,8 @@ class SkikoProperties(private val myProject: Project) {
get() = System.getenv()["SKIJA_DIR"]?.let { File(it) }?.takeIf { it.isDirectory } get() = System.getenv()["SKIJA_DIR"]?.let { File(it) }?.takeIf { it.isDirectory }
val skiaDir: File? val skiaDir: File?
get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir"))?.let { File(it) }?.takeIf { it.isDirectory } get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir"))?.let { File(it) }
?.takeIf { it.isDirectory }
val composeRepoUrl: String val composeRepoUrl: String
get() = System.getenv("COMPOSE_REPO_URL") ?: "https://maven.pkg.jetbrains.space/public/p/compose/dev" get() = System.getenv("COMPOSE_REPO_URL") ?: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
......
...@@ -2,6 +2,7 @@ kotlin.code.style=official ...@@ -2,6 +2,7 @@ kotlin.code.style=official
deploy.version=0.1 deploy.version=0.1
dependencies.skija.git.commit=8fc45764727610bd4b3d228198432f6f327a34ad dependencies.skija.git.commit=8fc45764727610bd4b3d228198432f6f327a34ad
dependencies.skia.windows=m88-59bafeeaa7/Skia-m88-59bafeeaa7-windows-Release-x64 dependencies.skia.windows_x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-windows-Release-x64
dependencies.skia.linux=m88-59bafeeaa7/Skia-m88-59bafeeaa7-linux-Release-x64 dependencies.skia.linux_x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-linux-Release-x64
dependencies.skia.macos=m88-59bafeeaa7/Skia-m88-59bafeeaa7-macos-Release-x64 dependencies.skia.macos_x64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-macos-Release-x64
dependencies.skia.macos_arm64=m88-59bafeeaa7/Skia-m88-59bafeeaa7-macos-Release-arm64
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