Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions jme3-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,147 @@ task runExamples(dependsOn: 'build', type: JavaExec) {
}
}

def umuLauncherDownloadUrl = 'https://github.com/Open-Wine-Components/umu-launcher/releases/download/1.4.0/umu-launcher-1.4.0-zipapp.tar'
def umuLauncherArchive = layout.buildDirectory.file('tmp/umu-launcher-1.4.0-zipapp.tar')
def umuLauncherExtractDir = layout.buildDirectory.dir('tools/umu-launcher')
def protonToolchainVersion = java.toolchain.languageVersion.get().asInt()
def protonJdkDownloadUrl = "https://api.adoptium.net/v3/binary/latest/${protonToolchainVersion}/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk"
def protonJdkArchive = layout.buildDirectory.file("tmp/proton-jdk-${protonToolchainVersion}-windows.zip")
def protonJdkExtractDir = layout.buildDirectory.dir('tools/proton-jdk')

task downloadProtonRuntime {
description = 'Download and extract Proton runtime launcher into jme3-examples/build/tools/umu-launcher.'
outputs.dir(umuLauncherExtractDir)
Comment thread
riccardobl marked this conversation as resolved.
inputs.property("url", umuLauncherDownloadUrl)

doLast {
def archiveFile = umuLauncherArchive.get().asFile
archiveFile.parentFile.mkdirs()

logger.lifecycle("Downloading umu-launcher from ${umuLauncherDownloadUrl}")

new URL(umuLauncherDownloadUrl).withInputStream { input ->
archiveFile.withOutputStream { output ->
output << input
}
}
Comment thread
riccardobl marked this conversation as resolved.

def extractRoot = umuLauncherExtractDir.get().asFile
extractRoot.deleteDir()
extractRoot.mkdirs()

copy {
from tarTree(archiveFile)
into extractRoot
}

def extractedEntries = extractRoot.listFiles()
if (extractedEntries == null || extractedEntries.length == 0) {
throw new GradleException('umu-launcher archive extraction failed: build/tools/umu-launcher is empty')
}

logger.lifecycle("umu-launcher extracted to ${extractRoot.absolutePath}")
}
}

task downloadProtonJdk {
description = "Download and extract the Adoptium Java ${protonToolchainVersion} Windows JDK used to bootstrap Gradle inside Proton."
outputs.dir(protonJdkExtractDir)
Comment thread
riccardobl marked this conversation as resolved.
inputs.property("url", protonJdkDownloadUrl)

doLast {
def archiveFile = protonJdkArchive.get().asFile
archiveFile.parentFile.mkdirs()

logger.lifecycle("Downloading Windows JDK from ${protonJdkDownloadUrl}")

new URL(protonJdkDownloadUrl).withInputStream { input ->
archiveFile.withOutputStream { output ->
output << input
}
}
Comment thread
riccardobl marked this conversation as resolved.

def extractRoot = protonJdkExtractDir.get().asFile
extractRoot.deleteDir()
extractRoot.mkdirs()

copy {
from zipTree(archiveFile)
into extractRoot
}

def extractedEntries = extractRoot.listFiles()
if (extractedEntries == null || extractedEntries.length == 0) {
throw new GradleException('Windows JDK extraction failed: build/tools/proton-jdk is empty')
}

logger.lifecycle("Windows JDK extracted to ${extractRoot.absolutePath}")
}
}

task runExamplesWithProton(dependsOn: ['build', 'downloadProtonRuntime', 'downloadProtonJdk'], type: Exec) {
description = 'Run jme3 examples under Proton using the downloaded runtime launcher and Windows JDK.'
workingDir = rootProject.projectDir

doFirst {
def extractRoot = umuLauncherExtractDir.get().asFile
def umuRunScript = new File(extractRoot, 'umu-run')
if (!umuRunScript.exists()) {
def nestedUmuRun = extractRoot.listFiles()?.find { it.isDirectory() }?.toPath()?.resolve('umu-run')?.toFile()
if (nestedUmuRun != null && nestedUmuRun.exists()) {
umuRunScript = nestedUmuRun
}
}
if (!umuRunScript.exists()) {
throw new GradleException("Could not find umu-run script at ${umuRunScript.absolutePath}")
}
Comment thread
riccardobl marked this conversation as resolved.

def protonJdkRoot = protonJdkExtractDir.get().asFile
def protonJdkDir = fileTree(protonJdkRoot).find { it.name == 'java.exe' }?.parentFile?.parentFile

def winePrefix = "${buildDir}/umu/wineprefix"
def gameId = 'jme3-examples'
def store = 'none'
def protonJavaHome = "Z:${protonJdkDir.absolutePath.replace('/', '\\\\')}"
def protonJavaExe = "${protonJavaHome}\\\\bin\\\\java.exe"
def exampleClass = project.findProperty('example')?.toString() ?: mainClassName
def runtimeClasspathFiles = sourceSets.main.runtimeClasspath.files as LinkedHashSet
def relevantRuntimeEntries = runtimeClasspathFiles.findAll { file ->
def name = file.name.toLowerCase()
name.contains('angle') || name.contains('saferalloc')
}
logger.lifecycle("Proton runtime entries: ${relevantRuntimeEntries*.name}")

def runtimeClasspath = runtimeClasspathFiles.collect { file ->
"Z:${file.absolutePath.replace('/', '\\\\')}"
}.join(';')
def jvmArgs = []

if (assertions == 'true') {
jvmArgs << '-ea'
}

if (System.properties['java.util.logging.config.file'] != null) {
def loggingConfig = System.properties['java.util.logging.config.file'].replace('/', '\\\\')
jvmArgs << "-Djava.util.logging.config.file=Z:${loggingConfig}"
}

executable = umuRunScript.absolutePath
args protonJavaExe
args jvmArgs
args '-cp', runtimeClasspath, exampleClass

environment 'WINEPREFIX', winePrefix
environment 'GAMEID', gameId
environment 'STORE', store
environment 'JAVA_HOME', protonJavaHome
environment 'JDK_HOME', protonJavaHome
environment 'PROTON_VERB', 'waitforexitandrun'

logger.lifecycle("Running ${exampleClass} with Proton via ${protonJavaExe}")
}
}

dependencies {
implementation project(':jme3-core')
implementation project(':jme3-desktop')
Expand Down