nativeimage.gradle 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. project(":lwjgl3") {
  2. apply plugin: "org.graalvm.buildtools.native"
  3. graalvmNative {
  4. binaries {
  5. main {
  6. imageName = appName
  7. mainClass = project.mainClassName
  8. requiredVersion = '23.0'
  9. buildArgs.add("-march=compatibility")
  10. jvmArgs.addAll("-Dfile.encoding=UTF8")
  11. sharedLibrary = false
  12. resources.autodetect()
  13. }
  14. }
  15. }
  16. run {
  17. doNotTrackState("Running the app should not be affected by Graal.")
  18. }
  19. // Modified from https://lyze.dev/2021/04/29/libGDX-Internal-Assets-List/ ; thanks again, Lyze!
  20. // This creates a resource-config.json file based on the contents of the assets folder (and the libGDX icons).
  21. // This file is used by Graal Native to embed those specific files.
  22. // This has to run before nativeCompile, so it runs at the start of an unrelated resource-handling command.
  23. generateResourcesConfigFile.doFirst {
  24. def assetsFolder = new File("${project.rootDir}/assets/")
  25. def lwjgl3 = project(':lwjgl3')
  26. def resFolder = new File("${lwjgl3.projectDir}/src/main/resources/META-INF/native-image/${lwjgl3.ext.appName}")
  27. resFolder.mkdirs()
  28. def resFile = new File(resFolder, "resource-config.json")
  29. resFile.delete()
  30. resFile.append(
  31. """{
  32. "resources":{
  33. "includes":[
  34. {
  35. "pattern": ".*(""")
  36. // This adds every filename in the assets/ folder to a pattern that adds those files as resources.
  37. fileTree(assetsFolder).each {
  38. // The backslash-Q and backslash-E escape the start and end of a literal string, respectively.
  39. resFile.append("\\\\Q${it.name}\\\\E|")
  40. }
  41. // We also match all of the window icon images this way and the font files that are part of libGDX.
  42. resFile.append(
  43. """libgdx.+\\\\.png|lsans.+)"
  44. }
  45. ]},
  46. "bundles":[]
  47. }"""
  48. )
  49. }
  50. }