Просмотр исходного кода

breakpad: add package (#2722)

* breakpad: add package

* fix mac

* fix mac test

* add dwarf files on non-windows plat

* disable plat
star9029 2 лет назад
Родитель
Сommit
76bdb97f6a
2 измененных файлов с 200 добавлено и 0 удалено
  1. 133 0
      packages/b/breakpad/port/xmake.lua
  2. 67 0
      packages/b/breakpad/xmake.lua

+ 133 - 0
packages/b/breakpad/port/xmake.lua

@@ -0,0 +1,133 @@
+-- ref: https://github.com/microsoft/vcpkg/blob/master/ports/breakpad/CMakeLists.txt
+add_rules("mode.debug", "mode.release")
+
+set_languages("c++17")
+
+add_requires("libdisasm")
+
+target("breakpad")
+    set_kind("$(kind)")
+
+    add_includedirs("src")
+    add_headerfiles("src/(google_breakpad/**.h)")
+    add_packages("libdisasm")
+
+    if is_plat("android") then
+        add_files("android/google_breakpad/Android.mk")
+    else
+        add_files("src/processor/*.cc")
+        remove_files("src/processor/*test*.cc",
+                     "src/processor/microdump_stackwalk.cc",
+                     "src/processor/synth_minidump.cc",
+                     "src/processor/minidump_dump.cc",
+                     "src/processor/minidump_stackwalk.cc")
+        add_headerfiles("src/(processor/*.h)")
+        remove_headerfiles("src/processor/*test*.h", "src/processor/synth_minidump.h")
+
+        add_files("src/common/*.cc", "src/client/*.cc")
+        remove_files("src/common/*test*.cc", "src/client/*test*.cc")
+        add_headerfiles("src/(common/*.h)", "src/(client/*.h)")
+        remove_headerfiles("src/common/*test*.h", "src/client/*test*.h")
+
+        if is_plat("windows") then
+            add_defines("UNICODE",
+                        "WIN32_LEAN_AND_MEAN",
+                        "_CRT_SECURE_NO_WARNINGS",
+                        "_CRT_SECURE_NO_DEPRECATE",
+                        "_CRT_NONSTDC_NO_DEPRECATE")
+            add_files("src/common/windows/*.cc",
+                      "src/client/windows/crash_generation/*.cc",
+                      "src/client/windows/handler/*.cc")
+            remove_files("src/common/windows/*test*.cc",
+                         "src/common/language.cc",
+                         "src/common/path_helper.cc",
+                         "src/common/stabs_to_module.cc",
+                         "src/common/stabs_reader.cc",
+                         "src/common/dwarf*.cc",
+                         "src/client/minidump_file_writer.cc")
+            add_headerfiles("src/(common/windows/*.h)",
+                            "src/(client/windows/common/*.h)",
+                            "src/(client/windows/crash_generation/*.h)",
+                            "src/(client/windows/handler/*.h)")
+            remove_headerfiles("src/common/windows/*test*.h",
+                               "src/common/language.h",
+                               "src/common/path_helper.h",
+                               "src/common/stabs_to_module.h",
+                               "src/common/stabs_reader.h",
+                               "src/common/dwarf*.h",
+                               "src/client/minidump_file_writer.h")
+
+            add_syslinks("wininet", "dbghelp", "imagehlp")
+            if is_kind("shared") then
+                add_rules("utils.symbols.export_all", {export_classes = true})
+            end
+        else
+            add_files("src/common/dwarf/*.cc")
+            remove_files("src/common/dwarf/*test*.cc")
+            add_headerfiles("src/(common/dwarf/*.h)")
+            remove_headerfiles("src/common/dwarf/*test*.h")
+
+            if is_plat("macosx") then
+                add_defines("HAVE_MACH_O_NLIST_H")
+                add_files("src/common/mac/MachIPC.mm",
+                        "src/common/mac/*.cc",
+                        "src/client/mac/crash_generation/*.cc",
+                        "src/client/mac/handler/*.cc")
+                remove_files("src/common/mac/*test*.cc")
+                add_headerfiles("src/(common/mac/*.h)",
+                                "src/(client/mac/crash_generation/*.h)",
+                                "src/(client/mac/handler/*.h)")
+
+                add_frameworks("CoreFoundation")
+            else
+                add_defines("HAVE_A_OUT_H")
+                add_files("src/client/linux/**.cc", "src/common/linux/**.cc")
+                remove_files("src/client/linux/sender/*test*.cc",
+                            "src/client/linux/handler/*test*.cc",
+                            "src/client/linux/microdump_writer/*test*.cc",
+                            "src/client/linux/minidump_writer/*test*.cc")
+                add_headerfiles("src/(client/linux/**.h)", "src/(common/linux/**.h)")
+                add_syslinks("pthread")
+            end
+        end
+    end
+
+    on_config(function (target)
+        if target:is_plat("windows") then
+            local msvc = target:toolchain("msvc")
+            if msvc then
+                local envs = msvc:runenvs()
+                local VSInstallDir = envs and envs.VSInstallDir
+                if VSInstallDir then
+                    local dir = path.join(VSInstallDir, "DIA SDK")
+                    target:add("includedirs", path.join(dir, "include"))
+                    target:add("syslinks", "diaguids")
+                    if os.isdir(dir) then
+                        if target:is_arch("x86") then
+                            target:add("runenvs", path.join(dir, "bin"))
+                            target:add("linkdirs", path.join(dir, "lib"))
+                        else
+                            local arch
+                            if target:is_arch("x64") then
+                                arch = "amd64"
+                            elseif target:is_arch("arm") then
+                                arch = "arm"
+                            elseif target:is_arch("arm64") then
+                                arch = "arm64"
+                            else
+                                raise("Unsupported arch")
+                            end
+                            target:add("runenvs", path.join(dir, "bin", arch))
+                            target:add("linkdirs", path.join(dir, "lib", arch))
+                        end
+                    end
+                end
+            end
+        elseif not target:is_plat("macosx") then
+            if target:has_cfuncs("getcontext", {includes = "ucontext.h"}) then
+                target:add("defines", "HAVE_GETCONTEXT=1")
+            else
+                target:add("files", path.join(os.projectdir(), "src/common/linux/breakpad_getcontext.S"))
+            end
+        end
+    end)

+ 67 - 0
packages/b/breakpad/xmake.lua

@@ -0,0 +1,67 @@
+package("breakpad")
+    set_homepage("https://chromium.googlesource.com/breakpad/breakpad")
+    set_description("Mirror of Google Breakpad project")
+
+    add_urls("https://github.com/google/breakpad/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/google/breakpad.git",
+             "https://chromium.googlesource.com/breakpad/breakpad.git")
+
+    add_versions("v2023.01.27", "f187e8c203bd506689ce4b32596ba821e1e2f034a83b8e07c2c635db4de3cc0b")
+
+    if is_plat("windows") then
+        add_configs("shared", {description = "Build shared binaries.", default = false, type = "boolean", readonly = true})
+    end
+
+    if is_plat("mingw") and is_subhost("msys") then
+        add_extsources("pacman::breakpad")
+    end
+
+    if is_plat("windows") then
+        add_syslinks("wininet", "dbghelp", "imagehlp")
+    elseif is_plat("linux") then
+        add_syslinks("pthread")
+    elseif is_plat("macosx") then
+        add_frameworks("CoreFoundation")
+    end
+
+    add_deps("libdisasm")
+
+    on_install("windows|x64", "windows|x86", function (package)
+        io.replace("src/processor/disassembler_x86.h", "third_party/", "", {plain = true})
+        io.replace("src/processor/exploitability_win.cc", "third_party/", "", {plain = true})
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        local plat
+        local snippets
+        if package:is_plat("windows") then
+            plat = "windows"
+            snippets = [[
+                void test() {
+                    std::wstring dump_path;
+                    google_breakpad::ExceptionHandler handler(dump_path, nullptr, nullptr, nullptr, 0);
+                }
+            ]]
+        elseif package:is_plat("macosx") then
+            plat = "mac"
+            snippets = [[
+                void test() {
+                    std::string dump_path;
+                    google_breakpad::ExceptionHandler handler(
+                        dump_path, nullptr, nullptr, nullptr, false, nullptr);
+                }
+            ]]
+        else
+            plat = "linux"
+            snippets = [[
+                void test() {
+                    google_breakpad::MinidumpDescriptor descriptor("/tmp");
+                }
+            ]]
+        end
+
+        local header = "client/" .. plat .. "/handler/exception_handler.h"
+        assert(package:check_cxxsnippets({test = snippets}, {configs = {languages = "c++11"}, includes = header}))
+    end)