xmake.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package("sentencepiece")
  2. set_homepage("https://github.com/google/sentencepiece")
  3. set_description("Unsupervised text tokenizer for Neural Network-based text generation. .")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/google/sentencepiece/archive/$(version).tar.gz",
  6. "https://github.com/google/sentencepiece.git")
  7. add_versions("v0.1.97", "41c3a07f315e3ac87605460c8bb8d739955bc8e7f478caec4017ef9b7d78669b")
  8. add_deps("cmake", "gperftools")
  9. add_configs("external_abseil", {description = "Use external abseil.", default = false, type = "boolean"})
  10. add_configs("builtin_protobuf", {description = "Use built-in protobuf.", default = true, type = "boolean"})
  11. if is_plat("windows") then
  12. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  13. add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MT", readonly = true})
  14. end
  15. on_load("windows", "linux", "macosx",function (package)
  16. if package:config("external_abseil") then
  17. package:add("deps", "abseil")
  18. end
  19. if not package:config("builtin_protobuf") then
  20. package:add("deps", "protobuf-cpp")
  21. end
  22. end)
  23. on_install("windows", "linux", "macosx", function (package)
  24. local configs = {}
  25. table.insert(configs, "-DSPM_ENABLE_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  26. table.insert(configs, "-DSPM_USE_EXTERNAL_ABSL=" .. (package:config("external_abseil") and "ON" or "OFF"))
  27. table.insert(configs, "-DSPM_USE_BUILTIN_PROTOBUF=" .. (package:config("builtin_protobuf") and "ON" or "OFF"))
  28. import("package.tools.cmake").install(package, configs)
  29. end)
  30. on_test(function (package)
  31. assert(package:check_cxxsnippets({test = [[
  32. #include <iostream>
  33. void test(int args, char** argv) {
  34. sentencepiece::SentencePieceProcessor processor;
  35. const auto status = processor.Load("//path/to/model.model");
  36. if (!status.ok()) {
  37. std::cerr << status.ToString() << std::endl;
  38. }
  39. }
  40. ]]}, {configs = {languages = "c++17"}, includes = "sentencepiece_processor.h"}))
  41. end)