xmake.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package("whisper.cpp")
  2. set_homepage("https://github.com/ggerganov/whisper.cpp")
  3. set_description("Port of OpenAI's Whisper model in C/C++")
  4. set_urls("https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v$(version).tar.gz",
  5. "https://github.com/ggerganov/whisper.cpp.git")
  6. add_versions("1.4.2", "1b988dcc77fca55f188dbc4e472f971a80854c1d44309cf3eaab9d5677f175e1")
  7. add_patches("1.4.2", path.join(os.scriptdir(), "patches", "1.4.2", "fix.patch"), "1330bdbb769aad37f0de6998ac9b0107423ec62385bbfb0a89a98c226daace48")
  8. add_configs("avx", { description = "Enable AVX", default = true, type = "boolean"})
  9. add_configs("avx2", { description = "Enable AVX2", default = true, type = "boolean"})
  10. add_configs("fma", { description = "Enable FMA", default = true, type = "boolean"})
  11. add_configs("f16c", { description = "Enable F16c", default = true, type = "boolean"})
  12. if is_plat("macosx") then
  13. add_configs("accelerate", { description = "Enable Accelerate framework", default = true, type = "boolean"})
  14. add_configs("coreml", { description = "Enable Core ML framework", default = false, type = "boolean"})
  15. add_configs("coreml_allow_fallback", { description = "Allow non-CoreML fallback", default = false, type = "boolean"})
  16. else
  17. add_configs("openblas", { description = "Support for OpenBLAS", default = false, type = "boolean", readonly = true})
  18. add_configs("cublas", { description = "Support for cuBLAS", default = false, type = "boolean", readonly = true})
  19. add_configs("clblast", { description = "use CLBlast", default = false, type = "boolean", readonly = true})
  20. end
  21. add_configs("perf", { description = "Enable perf timings", default = false, type = "boolean"})
  22. add_deps("cmake")
  23. on_install("windows", "linux", "mingw", "msys", "android", "wasm", function (package)
  24. local configs = {"-DWHISPER_BUILD_TESTS=OFF", "-DWHISPER_BUILD_EXAMPLES=OFF"}
  25. table.insert(configs, "-DWHISPER_NO_AVX=" .. (package:config("avx") and "OFF" or "ON"))
  26. table.insert(configs, "-DWHISPER_NO_AVX2=" .. (package:config("avx2") and "OFF" or "ON"))
  27. table.insert(configs, "-DWHISPER_NO_FMA=" .. (package:config("fma") and "OFF" or "ON"))
  28. table.insert(configs, "-DWHISPER_NO_F16C=" .. (package:config("f16c") and "OFF" or "ON"))
  29. if package:is_plat("macosx") then
  30. table.insert(configs, "-DWHISPER_NO_ACCELERATE=" .. (package:config("accelerate") and "OFF" or "ON"))
  31. table.insert(configs, "-DWHISPER_COREML=" .. (package:config("coreml") and "ON" or "OFF"))
  32. table.insert(configs, "-DWHISPER_COREML_ALLOW_FALLBACK=" .. (package:config("coreml_allow_fallback") and "ON" or "OFF"))
  33. else
  34. table.insert(configs, "-DWHISPER_OPENBLAS=" .. (package:config("openblas") and "ON" or "OFF"))
  35. table.insert(configs, "-DWHISPER_CUBLAS=" .. (package:config("cublas") and "ON" or "OFF"))
  36. table.insert(configs, "-DWHISPER_CLBLAST=" .. (package:config("clblast") and "ON" or "OFF"))
  37. end
  38. table.insert(configs, "-DWHISPER_PERF=" .. (package:config("perf") and "ON" or "OFF"))
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  41. import("package.tools.cmake").install(package, configs)
  42. end)
  43. on_test(function (package)
  44. assert(package:check_cxxsnippets({test = [[
  45. void test() {
  46. whisper_context* ctx = whisper_init_from_file("ggml-base.en.bin");
  47. }
  48. ]]}, {includes = {"whisper.h"}}))
  49. end)