xmake.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package("ndk")
  2. set_kind("toolchain")
  3. set_homepage("https://developer.android.com/ndk")
  4. set_description("Android NDK toolchain.")
  5. if is_host("windows", "linux", "macosx") then
  6. set_urls("https://dl.google.com/android/repository/android-ndk-$(version).zip", {version = function(version)
  7. -- 27.3 -> r27d-linux
  8. local minor = ''
  9. local suffix = ''
  10. local host = os.host()
  11. if version:minor() > 0 then
  12. minor = string.char(97 + version:minor())
  13. end
  14. if version:major() < 23 then
  15. suffix = '-x86_64'
  16. end
  17. if host == "macosx" then
  18. host = "darwin"
  19. end
  20. return ("r%s%s-%s%s"):format(version:major(), minor, host, suffix)
  21. end})
  22. end
  23. if is_host("windows") then
  24. add_versionfiles("versions/windows.txt")
  25. elseif is_host("linux") then
  26. add_versionfiles("versions/linux.txt")
  27. elseif is_host("macosx") then
  28. add_versionfiles("versions/macosx.txt")
  29. end
  30. on_load(function (package)
  31. package:mark_as_pathenv("ANDROID_NDK_ROOT")
  32. package:mark_as_pathenv("ANDROID_NDK_HOME")
  33. package:setenv("ANDROID_NDK_ROOT", ".")
  34. package:setenv("ANDROID_NDK_HOME", ".")
  35. end)
  36. on_check("@macosx|arm64", function(package)
  37. assert(package:version():gt("23.0"), "package(ndk <=23.0): unsupported architecture, please increase the NDK version.")
  38. end)
  39. on_install("@windows|x64", "@msys|x86_64", "@linux|x86_64", "@macosx", function (package)
  40. os.vcp("*", package:installdir())
  41. end)
  42. on_test(function (package)
  43. local host = os.host()
  44. if host == "macosx" then
  45. host = "darwin"
  46. end
  47. os.vrunv(path.join(package:installdir(), "toolchains/llvm/prebuilt", host .. "-x86_64", "bin/clang"), {"--version"})
  48. end)