xmake.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package("tracy")
  2. set_homepage("https://github.com/wolfpld/tracy")
  3. set_description("C++ frame profiler")
  4. add_urls("https://github.com/wolfpld/tracy/archive/refs/tags/$(version).tar.gz",
  5. "https://github.com/wolfpld/tracy.git")
  6. add_versions("v0.11.1", "2c11ca816f2b756be2730f86b0092920419f3dabc7a7173829ffd897d91888a1")
  7. add_versions("v0.11.0", "b591ef2820c5575ccbf17e2e7a1dc1f6b9a2708f65bfd00f4ebefad2a1ccf830")
  8. add_versions("v0.10", "a76017d928f3f2727540fb950edd3b736caa97b12dbb4e5edce66542cbea6600")
  9. add_versions("v0.9.1", "c2de9f35ab2a516a9689ff18f5b62a55b73b93b66514bd09ba013d7957993cd7")
  10. add_versions("v0.9", "93a91544e3d88f3bc4c405bad3dbc916ba951cdaadd5fcec1139af6fa56e6bfc")
  11. add_versions("v0.8.2", "4784eddd89c17a5fa030d408392992b3da3c503c872800e9d3746d985cfcc92a")
  12. add_configs("cmake", {description = "Use cmake buildsystem", default = false, type = "boolean"})
  13. add_configs("tracy_enable", {type = "boolean", default = true, description = "Enable profiling"})
  14. add_configs("on_demand", {type = "boolean", default = false, description = "On-demand profiling"})
  15. add_configs("enforce_callstack", {type = "boolean", default = false, description = "Enfore callstack collection for tracy regions"})
  16. add_configs("callstack", {type = "boolean", default = false, description = "Enable all callstack related functionality"})
  17. add_configs("callstack_inlines", {type = "boolean", default = false, description = "Enable the inline functions in callstacks"})
  18. add_configs("only_localhost", {type = "boolean", default = false, description = "Only listen on the localhost interface"})
  19. add_configs("broadcast", {type = "boolean", default = false, description = "Enable client discovery by broadcast to local network"})
  20. add_configs("only_ipv4", {type = "boolean", default = false, description = "Tracy will only accept connections on IPv4 addresses (disable IPv6)"})
  21. add_configs("code_transfer", {type = "boolean", default = false, description = "Enable collection of source code"})
  22. add_configs("context_switch", {type = "boolean", default = false, description = "Enable capture of context switches"})
  23. add_configs("exit", {type = "boolean", default = false, description = "Client executable does not exit until all profile data is sent to server"})
  24. add_configs("sampling", {type = "boolean", default = false, description = "Enable call stack sampling"})
  25. add_configs("verify", {type = "boolean", default = false, description = "Enable zone validation for C API"})
  26. add_configs("vsync_capture", {type = "boolean", default = false, description = "Enable capture of hardware Vsync events"})
  27. add_configs("frame_image", {type = "boolean", default = false, description = "Enable the frame image support and its thread"})
  28. add_configs("system_tracing", {type = "boolean", default = false, description = "Enable systrace sampling"})
  29. add_configs("patchable_nopsleds", {type = "boolean", default = false, description = "Enable nopsleds for efficient patching by system-level tools (e.g. rr)"})
  30. add_configs("timer_fallback", {type = "boolean", default = false, description = "Use lower resolution timers"})
  31. add_configs("libunwind_backtrace", {type = "boolean", default = false, description = "Use libunwind backtracing where supported"})
  32. add_configs("symbol_offline_resolve", {type = "boolean", default = false, description = "Instead of full runtime symbol resolution, only resolve the image path and offset to enable offline symbol resolution"})
  33. add_configs("libbacktrace_elf_dynload_support", {type = "boolean", default = false, description = "Enable libbacktrace to support dynamically loaded elfs in symbol resolution resolution after the first symbol resolve operation"})
  34. add_configs("delayed_init", {type = "boolean", default = false, description = "Enable delayed initialization of the library (init on first call)"})
  35. add_configs("manual_lifetime", {type = "boolean", default = false, description = "Enable the manual lifetime management of the profile"})
  36. add_configs("fibers", {type = "boolean", default = true, description = "Enable fibers support"})
  37. add_configs("crash_handler", {type = "boolean", default = false, description = "Enable crash handling"})
  38. add_configs("verb", {type = "boolean", default = false, description = "Enable verbose logging"})
  39. if is_plat("windows", "mingw") then
  40. add_syslinks("ws2_32", "dbghelp")
  41. elseif is_plat("linux") then
  42. add_syslinks("pthread")
  43. elseif is_plat("bsd") then
  44. add_syslinks("pthread", "execinfo")
  45. end
  46. on_load(function (package)
  47. if package:config("cmake") then
  48. package:add("deps", "cmake")
  49. end
  50. end)
  51. on_install(function (package)
  52. if package:config("cmake") then
  53. local configs = {}
  54. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  55. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  56. table.insert(configs, "-DTRACY_ON_DEMAND=" .. (package:config("on_demand") and "ON" or "OFF"))
  57. table.insert(configs, "-DTRACY_CALLSTACK=" .. (package:config("enforce_callstack") and "ON" or "OFF"))
  58. table.insert(configs, "-DTRACY_NO_CALLSTACK=" .. (package:config("callstack") and "OFF" or "ON"))
  59. table.insert(configs, "-DTRACY_NO_CALLSTACK_INLINES=" .. (package:config("callstack_inlines") and "OFF" or "ON"))
  60. table.insert(configs, "-DTRACY_ONLY_LOCALHOST=" .. (package:config("only_localhost") and "ON" or "OFF"))
  61. table.insert(configs, "-DTRACY_NO_BROADCAST=" .. (package:config("broadcast") and "OFF" or "ON"))
  62. table.insert(configs, "-DTRACY_ONLY_IPV4=" .. (package:config("only_ipv4") and "ON" or "OFF"))
  63. table.insert(configs, "-DTRACY_NO_CODE_TRANSFER=" .. (package:config("code_transfer") and "OFF" or "ON"))
  64. table.insert(configs, "-DTRACY_NO_CONTEXT_SWITCH=" .. (package:config("context_switch") and "OFF" or "ON"))
  65. table.insert(configs, "-DTRACY_NO_EXIT=" .. (package:config("exit") and "OFF" or "ON"))
  66. table.insert(configs, "-DTRACY_NO_SAMPLING=" .. (package:config("sampling") and "OFF" or "ON"))
  67. table.insert(configs, "-DTRACY_NO_VERIFY=" .. (package:config("verify") and "OFF" or "ON"))
  68. table.insert(configs, "-DTRACY_NO_VSYNC_CAPTURE=" .. (package:config("vsync_capture") and "OFF" or "ON"))
  69. table.insert(configs, "-DTRACY_NO_FRAME_IMAGE=" .. (package:config("frame_image") and "OFF" or "ON"))
  70. table.insert(configs, "-DTRACY_NO_SYSTEM_TRACING=" .. (package:config("system_tracing") and "OFF" or "ON"))
  71. table.insert(configs, "-DTRACY_PATCHABLE_NOPSLEDS=" .. (package:config("patchable_nopsleds") and "ON" or "OFF"))
  72. table.insert(configs, "-DTRACY_DELAYED_INIT=" .. (package:config("delayed_init") and "ON" or "OFF"))
  73. table.insert(configs, "-DTRACY_MANUAL_LIFETIME=" .. (package:config("manual_lifetime") and "ON" or "OFF"))
  74. table.insert(configs, "-DTRACY_FIBERS=" .. (package:config("fibers") and "ON" or "OFF"))
  75. table.insert(configs, "-DTRACY_NO_CRASH_HANDLER=" .. (package:config("crash_handler") and "OFF" or "ON"))
  76. table.insert(configs, "-DTRACY_TIMER_FALLBACK=" .. (package:config("timer_fallback") and "ON" or "OFF"))
  77. table.insert(configs, "-DTRACY_LIBUNWIND_BACKTRACE=" .. (package:config("libunwind_backtrace") and "ON" or "OFF"))
  78. table.insert(configs, "-DTRACY_SYMBOL_OFFLINE_RESOLVE=" .. (package:config("symbol_offline_resolve") and "ON" or "OFF"))
  79. table.insert(configs, "-DTRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT=" .. (package:config("libbacktrace_elf_dynload_support") and "ON" or "OFF"))
  80. -- collect tracy defines from cmake configs
  81. for _, config in ipairs(configs) do
  82. local define, value = config:match("-D(TRACY_%S+)=(.*)")
  83. if define and value and value == "ON" then
  84. package:add("defines", define)
  85. end
  86. end
  87. import("package.tools.cmake").install(package, configs)
  88. else
  89. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  90. local configs = {
  91. tracy_enable = package:config("tracy_enable"),
  92. on_demand = package:config("on_demand"),
  93. enforce_callstack = package:config("enforce_callstack"),
  94. callstack = not package:config("callstack"),
  95. callstack_inlines = not package:config("callstack_inlines"),
  96. only_localhost = package:config("only_localhost"),
  97. broadcast = not package:config("broadcast"),
  98. only_ipv4 = package:config("only_ipv4"),
  99. code_transfer = not package:config("code_transfer"),
  100. context_switch = not package:config("context_switch"),
  101. exit = not package:config("exit"),
  102. sampling = not package:config("sampling"),
  103. verify = not package:config("verify"),
  104. vsync_capture = not package:config("vsync_capture"),
  105. frame_image = not package:config("frame_image"),
  106. system_tracing = not package:config("system_tracing"),
  107. patchable_nopsleds = package:config("patchable_nopsleds"),
  108. timer_fallback = package:config("timer_fallback"),
  109. libunwind_backtrace = package:config("libunwind_backtrace"),
  110. symbol_offline_resolve = package:config("symbol_offline_resolve"),
  111. libbacktrace_elf_dynload_support = package:config("libbacktrace_elf_dynload_support"),
  112. delayed_init = package:config("delayed_init"),
  113. manual_lifetime = package:config("manual_lifetime"),
  114. fibers = package:config("fibers"),
  115. crash_handler = not package:config("crash_handler"),
  116. verb = package:config("verb"),
  117. }
  118. import("package.tools.xmake").install(package, configs)
  119. local defines = {
  120. tracy_enable = "TRACY_ENABLE",
  121. on_demand = "TRACY_ON_DEMAND",
  122. enforce_callstack = "TRACY_ENABLE_CALLSTACK",
  123. callstack = { define = "TRACY_NO_CALLSTACK", invert = true },
  124. callstack_inlines = { define = "TRACY_NO_CALLSTACK_INLINES", invert = true },
  125. only_localhost = "TRACY_ONLY_LOCALHOST",
  126. broadcast = { define = "TRACY_NO_BROADCAST", invert = true },
  127. only_ipv4 = "TRACY_ONLY_IPV4",
  128. code_transfer = { define = "TRACY_NO_CODE_TRANSFER", invert = true },
  129. context_switch = { define = "TRACY_NO_CONTEXT_SWITCH", invert = true },
  130. exit = { define = "TRACY_NO_EXIT", invert = true },
  131. sampling = { define = "TRACY_NO_SAMPLING", invert = true },
  132. verify = { define = "TRACY_NO_VERIFY", invert = true },
  133. vsync_capture = { define = "TRACY_NO_VSYNC_CAPTURE", invert = true },
  134. frame_image = { define = "TRACY_NO_FRAME_IMAGE", invert = true },
  135. system_tracing = { define = "TRACY_NO_SYSTEM_TRACING", invert = true },
  136. patchable_nopsleds = "TRACY_PATCHABLE_NOPSLEDS",
  137. timer_fallback = "TRACY_TIMER_FALLBACK",
  138. libunwind_backtrace = "TRACY_LIBUNWIND_BACKTRACE",
  139. symbol_offline_resolve = "TRACY_SYMBOL_OFFLINE_RESOLVE",
  140. libbacktrace_elf_dynload_support = "TRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT",
  141. delayed_init = "TRACY_DELAYED_INIT",
  142. manual_lifetime = "TRACY_MANUAL_LIFETIME",
  143. fibers = "TRACY_FIBERS",
  144. crash_handler = { define = "TRACY_NO_CRASH_HANDLER", invert = true },
  145. verb = "TRACY_VERBOSE"
  146. }
  147. for name, def in pairs(defines) do
  148. local define, invert
  149. if type(def) == "table" then
  150. define = def.define
  151. invert = def.invert
  152. else
  153. define = def
  154. invert = false
  155. end
  156. local value = package:config(name)
  157. if value ~= nil then
  158. if invert then
  159. value = not value
  160. end
  161. if value then
  162. package:add("defines", define)
  163. end
  164. end
  165. end
  166. end
  167. end)
  168. on_test(function (package)
  169. if package:config("tracy_enable") then
  170. assert(package:check_cxxsnippets({test = [[
  171. #include <tracy/Tracy.hpp>
  172. void test() {
  173. TracyPlotConfig("PlotConfig", tracy::PlotFormatType::Number, true, true, 0);
  174. }
  175. ]]}, {configs = {languages = "c++14"}}))
  176. end
  177. if package:config("fibers") then
  178. assert(package:check_cxxsnippets({test = [[
  179. #include <tracy/Tracy.hpp>
  180. void test() {
  181. TracyFiberEnter("Fiber");
  182. }
  183. ]]}, {configs = {languages = "c++14"}}))
  184. end
  185. end)