diff --git a/.gitignore b/.gitignore index a70b27e..6a66007 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /.gradle +/buildSrc/.gradle/ /build/ +/buildSrc/build/ /bin/ /lua/src/*.o /lua/src/liblua.so diff --git a/build.gradle b/build.gradle index cc4fd2d..777ebd7 100644 --- a/build.gradle +++ b/build.gradle @@ -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" @@ -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', diff --git a/buildSrc/src/main/groovy/DownloadTask.groovy b/buildSrc/src/main/groovy/DownloadTask.groovy new file mode 100644 index 0000000..443b9d3 --- /dev/null +++ b/buildSrc/src/main/groovy/DownloadTask.groovy @@ -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) + } +}