xmake.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package("zasm")
  2. set_homepage("https://github.com/zyantific/zasm")
  3. set_description("x86-64 Assembler based on Zydis")
  4. set_urls("https://github.com/zyantific/zasm.git")
  5. add_versions("2025.03.02", "c239a78b51c1b0060296193174d78b802f02a618")
  6. add_versions("2024.05.14", "bea8af2c68f0cbe8a02e93ab79a8b5c596d2b232")
  7. add_versions("2023.06.21", "19a642518eccbb1740865642eaf3ce79d5d5b884")
  8. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  9. on_load(function (package)
  10. local map = {
  11. ["2025.03.02"] = "4.1.0",
  12. ["2024.05.14"] = "4.1.0",
  13. ["2023.06.21"] = "4.0.0",
  14. }
  15. local zydis_version = map[package:version()]
  16. if zydis_version then
  17. package:add("deps", "zydis " .. zydis_version)
  18. else
  19. package:add("deps", "zydis")
  20. end
  21. end)
  22. on_install("!wasm and !iphoneos", function (package)
  23. local old_layout = false
  24. local commit = package:commit()
  25. if commit then
  26. local git = import("lib.detect.find_tool")("git")
  27. local result = os.iorunv(git.program, {"rev-list", "bea8af2c68f0cbe8a02e93ab79a8b5c596d2b232" .. ".." .. commit, "--count"}):trim()
  28. if result == "0" then
  29. old_layout = true
  30. end
  31. else
  32. old_layout = (package:version() and package:version():lt("2024.05.14"))
  33. end
  34. local src_include
  35. if old_layout then
  36. src_include = [[
  37. add_files("src/zasm/**.cpp")
  38. add_includedirs("include", "src/zasm/src")
  39. add_headerfiles("include/(**.hpp)")
  40. ]]
  41. else
  42. src_include = [[
  43. add_files("zasm/**.cpp")
  44. add_includedirs("zasm/include")
  45. add_headerfiles("zasm/include/(**.hpp)")
  46. ]]
  47. end
  48. io.writefile("xmake.lua", format([[
  49. add_rules("mode.debug", "mode.release")
  50. add_requires("zydis v4.0.0")
  51. target("zasm")
  52. set_kind("$(kind)")
  53. set_languages("c++17")
  54. %s
  55. if is_plat("windows") then
  56. add_cxxflags("/bigobj", "/MP", "/W3", "/permissive-")
  57. if is_kind("shared") then
  58. add_rules("utils.symbols.export_all", {export_classes = true})
  59. end
  60. end
  61. add_packages("zydis")
  62. ]], src_include))
  63. import("package.tools.xmake").install(package)
  64. end)
  65. on_test(function (package)
  66. assert(package:check_cxxsnippets({test = [[
  67. #include <zasm/serialization/serializer.hpp>
  68. #include <zasm/zasm.hpp>
  69. using namespace zasm;
  70. void test() {
  71. Program program(MachineMode::AMD64);
  72. }
  73. ]]}, {configs = {languages = "c++17"}}))
  74. end)