-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports packing macos app with a bundled ARM+x64 JRE (#1946)
- Loading branch information
Showing
8 changed files
with
164 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/SourceSets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package korlibs.korge.gradle.targets | ||
|
||
import korlibs.korge.gradle.* | ||
import org.gradle.api.* | ||
|
||
val Project.exKotlinSourceSetContainer: ExKotlinSourceSetContainer get() = extensionGetOrCreate("exKotlinSourceSetContainer") | ||
|
||
open class ExKotlinSourceSetContainer(val project: Project) { | ||
val kotlin = project.kotlin | ||
val sourceSets = kotlin.sourceSets | ||
|
||
val common by lazy { sourceSets.createPairSourceSet("common") } | ||
val nonJs by lazy { sourceSets.createPairSourceSet("nonJs", common) } | ||
val concurrent by lazy { sourceSets.createPairSourceSet("concurrent", common) } | ||
|
||
// JS | ||
val js by lazy { sourceSets.createPairSourceSet("js", common) } | ||
|
||
// JVM | ||
val jvm by lazy { sourceSets.createPairSourceSet("jvm", concurrent, nonJs) } | ||
|
||
// Native | ||
val native by lazy { sourceSets.createPairSourceSet("native", concurrent, nonJs) } | ||
val posix by lazy { sourceSets.createPairSourceSet("posix", native) } | ||
val darwin by lazy { sourceSets.createPairSourceSet("darwin", posix) } | ||
val darwinMobile by lazy { sourceSets.createPairSourceSet("darwinMobile", darwin) } | ||
val iosTvos by lazy { sourceSets.createPairSourceSet("iosTvos", darwinMobile/*, iosTvosMacos*/) } | ||
val tvos by lazy { sourceSets.createPairSourceSet("tvos", iosTvos) } | ||
val ios by lazy { sourceSets.createPairSourceSet("ios", iosTvos/*, iosMacos*/) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
buildSrc/src/main/kotlin/korlibs/korge/gradle/targets/desktop/DesktopJreBundler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package korlibs.korge.gradle.targets.desktop | ||
|
||
import korlibs.korge.gradle.* | ||
import korlibs.korge.gradle.targets.* | ||
import korlibs.korge.gradle.targets.apple.* | ||
import korlibs.korge.gradle.util.* | ||
import org.gradle.api.* | ||
import java.io.* | ||
import java.net.* | ||
import java.security.* | ||
|
||
// https://stackoverflow.com/questions/13017121/unpacking-tar-gz-into-root-dir-with-gradle | ||
// https://github.com/korlibs/universal-jre/ | ||
object DesktopJreBundler { | ||
// https://github.com/adoptium/temurin21-binaries/releases/tag/jdk-21%2B35 | ||
|
||
data class UrlRef(val url: String, val sha256: String) | ||
|
||
val JRE_MACOS_LAUNCHER = UrlRef( | ||
"https://github.com/korlibs/universal-jre/releases/download/0.0.1/app", | ||
sha256 = "4123b08e24678885781b04125675aa2f7d2af87583a753d16737ad154934bf0b" | ||
) | ||
|
||
val JRE_MACOS_UNIVERSAL = UrlRef( | ||
"https://github.com/korlibs/universal-jre/releases/download/0.0.1/macos-universal-jdk-21+35-jre.tar.gz", | ||
sha256 = "6d2d0a2e35c649fc731f5d3f38d7d7828f7fad4b9b2ea55d4d05f0fd26cf93ca" | ||
) | ||
|
||
val JRE_DIR = File(korgeCacheDir, "jre") | ||
val UNIVERSAL = File(JRE_DIR, "universal") | ||
val UNIVERSAL_JRE = File(UNIVERSAL, "jdk-21+35-jre/Contents/jre") | ||
|
||
fun cachedFile(urlRef: UrlRef): File { | ||
val downloadUrl = URL(urlRef.url) | ||
val localFile = File(JRE_DIR, File(downloadUrl.file).name).ensureParents() | ||
if (!localFile.isFile) { | ||
println("Downloading $downloadUrl...") | ||
val bytes = downloadUrl.readBytes() | ||
val actualSha256 = MessageDigest.getInstance("SHA-256").digest(bytes).hex | ||
val expectedSha256 = urlRef.sha256 | ||
if (actualSha256 != expectedSha256) { | ||
error("URL: ${urlRef.url} expected to have $expectedSha256 but was $actualSha256") | ||
} | ||
localFile.writeBytes(bytes) | ||
} | ||
return localFile | ||
} | ||
|
||
fun createMacosApp(project: Project, fatJar: File) { | ||
if (!UNIVERSAL_JRE.isDirectory) { | ||
project.copy { | ||
it.from(project.tarTree(cachedFile(JRE_MACOS_UNIVERSAL))) | ||
it.into(UNIVERSAL) | ||
} | ||
} | ||
|
||
val gameApp = File(project.buildDir, "platforms/jvm-macos/game.app/Contents").ensureParents() | ||
project.copy { | ||
it.from(UNIVERSAL_JRE) | ||
it.into(File(gameApp, "MacOS/jre")) | ||
} | ||
|
||
val korge = project.korge | ||
File(gameApp, "Resources/${korge.exeBaseName}.icns").ensureParents().writeBytes(IcnsBuilder.build(korge.getIconBytes())) | ||
File(gameApp, "Info.plist").writeText(InfoPlistBuilder.build(korge)) | ||
val exec = File(gameApp, "MacOS/${File(korge.exeBaseName).name}").ensureParents() | ||
exec.writeBytes(cachedFile(JRE_MACOS_LAUNCHER).readBytes()) | ||
exec.setExecutable(true) | ||
project.copy { | ||
it.from(fatJar) | ||
it.into(File(gameApp, "MacOS")) | ||
it.rename { "app.jar" } | ||
it.filePermissions { | ||
it.user.execute = true | ||
it.group.execute = true | ||
it.other.execute = true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters