Skip to content

Commit

Permalink
Download jextract before build
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Sep 20, 2024
1 parent bf580de commit 16ff712
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.gradle
/buildSrc/.gradle/
/build/
/buildSrc/build/
/bin/
/lua/src/*.o
/lua/src/liblua.so
Expand Down
22 changes: 20 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ testing {
}
}

task downloadJextract(type: DownloadTask) {
OperatingSystem currentOs = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem
def os = ""
if(currentOs.isMacOsX()){
os="macos"
} else if(currentOs.isLinux()) {
os="linux"
}
def arch = "x64"
sourceUrl = "https://download.java.net/java/early_access/jextract/22/5/openjdk-22-jextract+5-33_${os}-${arch}_bin.tar.gz"
target = file("${project.buildDir}/jextract.tar.gz")
}

task unpackJextract(type: Copy, dependsOn: [tasks.downloadJextract]) {
from tarTree(resources.gzip(tasks.downloadJextract.outputs.files[0]))
into file("${project.buildDir}/jextract/")
}

task buildLua(type: Exec) {
def luaSrc = "${projectDir}/lua"
Expand All @@ -47,10 +64,11 @@ task buildLua(type: Exec) {
outputs.dir(installDir)
}

task generateNativeInterface(type: Exec, dependsOn: [tasks.buildLua]) {
task generateNativeInterface(type: Exec, dependsOn: [tasks.buildLua, tasks.unpackJextract]) {
def jextractBinary = "${tasks.unpackJextract.outputs.files[0]}/jextract-22/bin/jextract"
def installDir = tasks.buildLua.outputs.files[0]
def generatedSrc = "${project.buildDir}/generated/sources/jextract/"
commandLine 'jextract',
commandLine jextractBinary,
'--include-dir', "$installDir/include",
'--output', generatedSrc,
'--target-package', 'org.itsallcode.jlua.ffi',
Expand Down
18 changes: 18 additions & 0 deletions buildSrc/src/main/groovy/DownloadTask.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

class DownloadTask extends DefaultTask {
@Input
String sourceUrl

@OutputFile
File target

@TaskAction
void download() {
logger.info("Downloading file ${sourceUrl} to ${target}...")
getAnt().get(src: sourceUrl, dest: target)
}
}

0 comments on commit 16ff712

Please sign in to comment.