From 7613e5f21139bea17c81027ee7476191b5716c70 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 28 Aug 2024 10:25:34 -0700 Subject: [PATCH] add pkg/breakpad, configure sentry to use breakpad --- build.zig | 2 +- pkg/breakpad/build.zig | 156 +++++++++++++++++++++++++++++++++++++ pkg/breakpad/build.zig.zon | 13 ++++ pkg/sentry/build.zig | 22 ++++-- pkg/sentry/build.zig.zon | 1 + 5 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 pkg/breakpad/build.zig create mode 100644 pkg/breakpad/build.zig.zon diff --git a/build.zig b/build.zig index cc9cbb595..0e7c8b3fa 100644 --- a/build.zig +++ b/build.zig @@ -1004,7 +1004,7 @@ fn addDeps( const sentry_dep = b.dependency("sentry", .{ .target = target, .optimize = optimize, - .backend = .inproc, + .backend = .breakpad, }); const zlib_dep = b.dependency("zlib", .{ .target = target, diff --git a/pkg/breakpad/build.zig b/pkg/breakpad/build.zig new file mode 100644 index 000000000..f4beb4f22 --- /dev/null +++ b/pkg/breakpad/build.zig @@ -0,0 +1,156 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const upstream = b.dependency("breakpad", .{}); + + const lib = b.addStaticLibrary(.{ + .name = "breakpad", + .target = target, + .optimize = optimize, + }); + lib.linkLibCpp(); + lib.addIncludePath(upstream.path("src")); + if (target.result.isDarwin()) { + const apple_sdk = @import("apple_sdk"); + try apple_sdk.addPaths(b, &lib.root_module); + } + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + try flags.appendSlice(&.{}); + + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = common, + .flags = flags.items, + }); + + if (target.result.isDarwin()) { + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = common_apple, + .flags = flags.items, + }); + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = client_apple, + .flags = flags.items, + }); + + switch (target.result.os.tag) { + .macos => { + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = common_mac, + .flags = flags.items, + }); + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = client_mac, + .flags = flags.items, + }); + }, + + .ios => lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = client_ios, + .flags = flags.items, + }), + + else => {}, + } + } + + if (target.result.os.tag == .linux) { + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = common_linux, + .flags = flags.items, + }); + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = client_linux, + .flags = flags.items, + }); + } + + lib.installHeadersDirectory( + upstream.path("src"), + "", + .{ .include_extensions = &.{".h"} }, + ); + + b.installArtifact(lib); +} + +const common: []const []const u8 = &.{ + "src/common/convert_UTF.cc", + "src/common/md5.cc", + "src/common/string_conversion.cc", +}; + +const common_linux: []const []const u8 = &.{ + "src/common/linux/elf_core_dump.cc", + "src/common/linux/elfutils.cc", + "src/common/linux/file_id.cc", + "src/common/linux/guid_creator.cc", + "src/common/linux/linux_libc_support.cc", + "src/common/linux/memory_mapped_file.cc", + "src/common/linux/safe_readlink.cc", + "src/common/linux/scoped_pipe.cc", + "src/common/linux/scoped_tmpfile.cc", + "src/common/linux/breakpad_getcontext.S", +}; + +const common_apple: []const []const u8 = &.{ + "src/common/mac/arch_utilities.cc", + "src/common/mac/file_id.cc", + "src/common/mac/macho_id.cc", + "src/common/mac/macho_utilities.cc", + "src/common/mac/macho_walker.cc", + "src/common/mac/string_utilities.cc", +}; + +const common_mac: []const []const u8 = &.{ + "src/common/mac/MachIPC.mm", + "src/common/mac/bootstrap_compat.cc", +}; + +const client_linux: []const []const u8 = &.{ + "src/client/minidump_file_writer.cc", + "src/client/linux/crash_generation/crash_generation_client.cc", + "src/client/linux/crash_generation/crash_generation_server.cc", + "src/client/linux/dump_writer_common/thread_info.cc", + "src/client/linux/dump_writer_common/ucontext_reader.cc", + "src/client/linux/handler/exception_handler.cc", + "src/client/linux/handler/minidump_descriptor.cc", + "src/client/linux/log/log.cc", + "src/client/linux/microdump_writer/microdump_writer.cc", + "src/client/linux/minidump_writer/linux_core_dumper.cc", + "src/client/linux/minidump_writer/linux_dumper.cc", + "src/client/linux/minidump_writer/linux_ptrace_dumper.cc", + "src/client/linux/minidump_writer/minidump_writer.cc", + "src/client/linux/minidump_writer/pe_file.cc", +}; + +const client_apple: []const []const u8 = &.{ + "src/client/minidump_file_writer.cc", + "src/client/mac/handler/breakpad_nlist_64.cc", + "src/client/mac/handler/dynamic_images.cc", + "src/client/mac/handler/minidump_generator.cc", +}; + +const client_mac: []const []const u8 = &.{ + "src/client/mac/handler/exception_handler.cc", + "src/client/mac/crash_generation/crash_generation_client.cc", +}; + +const client_ios: []const []const u8 = &.{ + "src/client/ios/exception_handler_no_mach.cc", + "src/client/ios/handler/ios_exception_minidump_generator.mm", + "src/client/mac/crash_generation/ConfigFile.mm", + "src/client/mac/handler/protected_memory_allocator.cc", +}; diff --git a/pkg/breakpad/build.zig.zon b/pkg/breakpad/build.zig.zon new file mode 100644 index 000000000..edb36e594 --- /dev/null +++ b/pkg/breakpad/build.zig.zon @@ -0,0 +1,13 @@ +.{ + .name = "breakpad", + .version = "0.1.0", + .paths = .{""}, + .dependencies = .{ + .breakpad = .{ + .url = "https://github.com/getsentry/breakpad/archive/b99f444ba5f6b98cac261cbb391d8766b34a5918.tar.gz", + .hash = "12207fd37bb8251919c112dcdd8f616a491857b34a451f7e4486490077206dc2a1ea", + }, + + .apple_sdk = .{ .path = "../apple-sdk" }, + }, +} diff --git a/pkg/sentry/build.zig b/pkg/sentry/build.zig index 2873e49c4..ece34c7cd 100644 --- a/pkg/sentry/build.zig +++ b/pkg/sentry/build.zig @@ -161,13 +161,21 @@ pub fn build(b: *std.Build) !void { .flags = flags.items, }), - .breakpad => lib.addCSourceFiles(.{ - .root = upstream.path(""), - .files = &.{ - "src/backends/sentry_backend_breakpad.cpp", - }, - .flags = flags.items, - }), + .breakpad => { + lib.addCSourceFiles(.{ + .root = upstream.path(""), + .files = &.{ + "src/backends/sentry_backend_breakpad.cpp", + }, + .flags = flags.items, + }); + + const breakpad_dep = b.dependency("breakpad", .{ + .target = target, + .optimize = optimize, + }); + lib.linkLibrary(breakpad_dep.artifact("breakpad")); + }, .inproc => lib.addCSourceFiles(.{ .root = upstream.path(""), diff --git a/pkg/sentry/build.zig.zon b/pkg/sentry/build.zig.zon index 4f1626b58..385cd69d8 100644 --- a/pkg/sentry/build.zig.zon +++ b/pkg/sentry/build.zig.zon @@ -9,5 +9,6 @@ }, .apple_sdk = .{ .path = "../apple-sdk" }, + .breakpad = .{ .path = "../breakpad" }, }, }