xmake.lua 14 KB

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