xmake.lua 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package("winpixevent")
  2. set_homepage("https://devblogs.microsoft.com/pix")
  3. set_description("WinPixEventRuntime + decoder + tests")
  4. set_license("MIT")
  5. add_urls("https://github.com/microsoft/PixEvents.git")
  6. add_versions("2024.03.19", "3a7e70dde7bf54f02f9d2e9dd6d3350c6cfb962f")
  7. add_includedirs("include", "include/WinPixEventRuntime")
  8. on_install("windows|!x86", function(package)
  9. import("package.tools.msbuild")
  10. local runtime = "MultiThreaded"
  11. if package:has_runtime("MDd", "MTd") then
  12. runtime = runtime .. "Debug"
  13. end
  14. if package:has_runtime("MDd", "MD") then
  15. runtime = runtime .. "DLL"
  16. end
  17. io.replace("decoder/lib/PixEventDecoder.lib.vcxproj", "</ClCompile>", "<RuntimeLibrary>" .. runtime .. "</RuntimeLibrary>\n</ClCompile>", {plain = true})
  18. io.replace("runtime/dll/desktop/WinPixEventRuntime.vcxproj", "</ClCompile>", "<RuntimeLibrary>" .. runtime .. "</RuntimeLibrary>\n</ClCompile>", {plain = true})
  19. io.replace("runtime/lib/WinPixEventRuntime.lib.vcxproj", "</ClCompile>", "<RuntimeLibrary>" .. runtime .. "</RuntimeLibrary>\n</ClCompile>", {plain = true})
  20. os.cp("decoder/include", package:installdir())
  21. os.cp("include/*.h", path.join(package:installdir("include", "WinPixEventRuntime")))
  22. local configs = {}
  23. local arch = package:is_arch("x64") and "x64" or "x86"
  24. if package:is_arch("arm64") then
  25. arch = "ARM64"
  26. end
  27. local mode = package:is_debug() and "Debug" or "Release"
  28. table.insert(configs, "/p:Configuration=" .. mode)
  29. table.insert(configs, "/p:Platform=" .. arch)
  30. table.insert(configs, "runtime/lib/WinPixEventRuntime.lib.vcxproj")
  31. msbuild.build(package, configs)
  32. if package:config("shared") then
  33. -- Store only Configuration & Platform
  34. configs = {table.unpack(configs, 1, 2)}
  35. table.insert(configs, "runtime/dll/desktop/WinPixEventRuntime.vcxproj")
  36. -- Workaround for source\pixevents\runtime\lib\IncludePixEtw.h(21,10): error C1083: Cannot open include file: 'PIXETW.h': No such file or directory
  37. -- https://github.com/microsoft/PixEvents/blob/3a7e70dde7bf54f02f9d2e9dd6d3350c6cfb962f/runtime/lib/WinPixEventRuntime.lib.vcxproj#L33
  38. -- Copy from static build generated files out of .man file into root
  39. os.cp("runtime/lib/intermediates/MSG00001.bin", "MSG00001.bin")
  40. os.cp("runtime/lib/intermediates/PixEtw.h", "PixEtw.h")
  41. os.cp("runtime/lib/intermediates/PixEtw.rc", "PixEtw.rc")
  42. os.cp("runtime/lib/intermediates/PixEtwTEMP.BIN", "PixEtwTEMP.BIN")
  43. msbuild.build(package, configs)
  44. end
  45. if package:config("shared") then
  46. os.cp("runtime/dll/desktop/output/*/*/WinPixEventRuntime/WinPixEventRuntime.dll", package:installdir("bin"))
  47. os.cp("runtime/dll/desktop/output/*/*/WinPixEventRuntime/WinPixEventRuntime.lib", package:installdir("lib"))
  48. else
  49. os.cp("runtime/lib/output/*/*/WinPixEventRuntime.lib/WinPixEventRuntime.lib", package:installdir("lib"))
  50. end
  51. -- Store only Configuration & Platform
  52. configs = {table.unpack(configs, 1, 2)}
  53. table.insert(configs, "decoder/lib/PixEventDecoder.lib.vcxproj")
  54. msbuild.build(package, configs)
  55. os.cp("decoder/lib/output/*/*/PixEventDecoder.lib/PixEventDecoder.lib.lib", path.join(package:installdir("lib"), "PixEventDecoder.lib"))
  56. end)
  57. on_test(function (package)
  58. assert(package:has_cxxfuncs("PIXEndCapture", {configs = {languages = "c++17"}, includes = {"windows.h", "pix3.h"}}))
  59. assert(package:check_cxxsnippets({test = [[
  60. using PixEventsLegacy::PIXEventsGraphicsRecordSpaceQwords;
  61. void test() {
  62. UINT64 buffer[PIXEventsGraphicsRecordSpaceQwords];
  63. PixEventsLegacy::EncodeBeginEventForContext(buffer, 0u, "hello %s %d %f", "world", 1, 1.0f);
  64. auto nameAndColor = PixEventDecoder::TryDecodePIXBeginEventOrPIXSetMarkerBlob(buffer, &buffer[PIXEventsGraphicsRecordSpaceQwords - 1]);
  65. }
  66. ]]}, {configs = {languages = "c++17"}, includes = {"windows.h", "PIXEventsLegacy.h", "PixEventDecoder.h"}}))
  67. end)