2
0

xmake.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package("llama.cpp")
  2. set_homepage("https://github.com/ggerganov/llama.cpp")
  3. set_description("Port of Facebook's LLaMA model in C/C++")
  4. set_license("MIT")
  5. add_urls("https://github.com/ggerganov/llama.cpp/archive/refs/tags/b$(version).tar.gz",
  6. "https://github.com/ggerganov/llama.cpp.git")
  7. add_versions("3775", "405bae9d550cb3fbf36d6583377b951a346b548f5850987238fe024a16f45cad")
  8. add_configs("curl", {description = "llama: use libcurl to download model from an URL", default = false, type = "boolean"})
  9. add_configs("openmp", {description = "ggml: use OpenMP", default = false, type = "boolean"})
  10. add_configs("cuda", {description = "ggml: use CUDA", default = false, type = "boolean"})
  11. add_configs("vulkan", {description = "ggml: use Vulkan", default = false, type = "boolean"})
  12. add_configs("blas", {description = "ggml: use BLAS", default = nil, type = "string", values = {"mkl", "openblas"}})
  13. if is_plat("macosx", "iphoneos") then
  14. add_frameworks("Accelerate", "Foundation", "Metal", "MetalKit")
  15. elseif is_plat("linux", "bsd") then
  16. add_syslinks("pthread")
  17. end
  18. add_links("llama", "ggml")
  19. add_deps("cmake")
  20. if on_check then
  21. on_check("android", function (package)
  22. local ndk = package:toolchain("ndk")
  23. local ndkver = ndk:config("ndkver")
  24. local ndk_sdkver = ndk:config("ndk_sdkver")
  25. assert(ndkver and tonumber(ndkver) > 22, "package(llama.cpp) require ndkver > 22")
  26. assert(ndk_sdkver and tonumber(ndk_sdkver) >= 24, "package(llama.cpp) require ndk api >= 24")
  27. end)
  28. on_check("windows", function (package)
  29. if package:is_arch("arm.*") then
  30. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  31. if vs_toolset then
  32. local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
  33. local minor = vs_toolset_ver:minor()
  34. assert(minor and minor >= 30, "package(llama.cpp/arm64) require vs_toolset >= 14.3")
  35. end
  36. end
  37. end)
  38. end
  39. on_load(function (package)
  40. if package:config("shared") then
  41. package:add("defines", "GGML_SHARED", "LLAMA_SHARED")
  42. end
  43. if package:config("curl") then
  44. package:add("deps", "libcurl")
  45. end
  46. if package:config("openmp") then
  47. package:add("deps", "openmp")
  48. end
  49. if package:config("cuda") then
  50. package:add("deps", "cuda")
  51. end
  52. if package:config("vulkan") then
  53. -- requires vulkan-1 and glslc
  54. package:add("deps", "vulkansdk")
  55. package:add("deps", "shaderc", {configs = {binaryonly = true}})
  56. end
  57. if package:config("blas") then
  58. if is_subhost("windows") then
  59. package:add("deps", "pkgconf")
  60. else
  61. package:add("deps", "pkg-config")
  62. end
  63. end
  64. end)
  65. on_install(function (package)
  66. local configs = {
  67. "-DLLAMA_ALL_WARNINGS=OFF",
  68. "-DLLAMA_BUILD_TESTS=OFF",
  69. "-DLLAMA_BUILD_EXAMPLES=OFF",
  70. "-DLLAMA_BUILD_SERVER=OFF",
  71. "-DGGML_ALL_WARNINGS=OFF",
  72. "-DGGML_BUILD_TESTS=OFF",
  73. "-DGGML_BUILD_EXAMPLES=OFF",
  74. "-DGGML_CCACHE=OFF",
  75. }
  76. table.insert(configs, "-DCMAKE_CROSSCOMPILING=" .. (package:is_cross() and "ON" or "OFF"))
  77. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  78. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  79. table.insert(configs, "-DLLAMA_SANITIZE_ADDRESS=" .. (package:config("asan") and "ON" or "OFF"))
  80. table.insert(configs, "-DGGML_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  81. table.insert(configs, "-DGGML_SANITIZE_ADDRESS=" .. (package:config("asan") and "ON" or "OFF"))
  82. table.insert(configs, "-DLLAMA_CURL=" .. (package:config("curl") and "ON" or "OFF"))
  83. table.insert(configs, "-DGGML_OPENMP=" .. (package:config("openmp") and "ON" or "OFF"))
  84. table.insert(configs, "-DGGML_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
  85. table.insert(configs, "-DGGML_VULKAN=" .. (package:config("vulkan") and "ON" or "OFF"))
  86. table.insert(configs, "-DGGML_OPENBLAS=" .. (package:config("blas") and "ON" or "OFF"))
  87. import("package.tools.cmake").install(package, configs)
  88. end)
  89. on_test(function (package)
  90. assert(package:has_cfuncs("ggml_time_us", {includes = "ggml.h"}))
  91. assert(package:has_cfuncs("llama_backend_init", {includes = "llama.h"}))
  92. end)