aboutsummaryrefslogtreecommitdiff
path: root/src/libunwind.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-04-29 15:42:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-05-08 19:37:29 -0700
commit2c317b2cbafe4f91fca66ee20f45197bbbd26353 (patch)
tree6bece787765a43382efc03849234ef0e9ec9670c /src/libunwind.zig
parentb018f2bae189cbcf2476b4147b108b815af149bc (diff)
downloadzig-2c317b2cbafe4f91fca66ee20f45197bbbd26353.tar.gz
zig-2c317b2cbafe4f91fca66ee20f45197bbbd26353.zip
libcxx, libtsan, libunwind: fix error reporting
use a consistent error set to avoid failure when bootstrapping from zig1
Diffstat (limited to 'src/libunwind.zig')
-rw-r--r--src/libunwind.zig53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/libunwind.zig b/src/libunwind.zig
index 90144c4bd5..808ea298ab 100644
--- a/src/libunwind.zig
+++ b/src/libunwind.zig
@@ -8,7 +8,13 @@ const Module = @import("Package/Module.zig");
const build_options = @import("build_options");
const trace = @import("tracy.zig").trace;
-pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
+pub const BuildError = error{
+ OutOfMemory,
+ SubCompilationFailed,
+ ZigCompilerNotBuiltWithLLVMExtensions,
+};
+
+pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) BuildError!void {
if (!build_options.have_llvm) {
return error.ZigCompilerNotBuiltWithLLVMExtensions;
}
@@ -21,7 +27,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
const arena = arena_allocator.allocator();
const output_mode = .Lib;
- const config = try Compilation.Config.resolve(.{
+ const config = Compilation.Config.resolve(.{
.output_mode = .Lib,
.resolved_target = comp.root_mod.resolved_target,
.is_test = false,
@@ -32,8 +38,15 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
.link_libc = true,
// Disable LTO to avoid https://github.com/llvm/llvm-project/issues/56825
.lto = false,
- });
- const root_mod = try Module.create(arena, .{
+ }) catch |err| {
+ comp.setMiscFailure(
+ .libunwind,
+ "unable to build libunwind: resolving configuration failed: {s}",
+ .{@errorName(err)},
+ );
+ return error.SubCompilationFailed;
+ };
+ const root_mod = Module.create(arena, .{
.global_cache_directory = comp.global_cache_directory,
.paths = .{
.root = .{ .root_dir = comp.zig_lib_directory },
@@ -59,7 +72,14 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
.parent = null,
.builtin_mod = null,
.builtin_modules = null, // there is only one module in this compilation
- });
+ }) catch |err| {
+ comp.setMiscFailure(
+ .libunwind,
+ "unable to build libunwind: creating module failed: {s}",
+ .{@errorName(err)},
+ );
+ return error.SubCompilationFailed;
+ };
const root_name = "unwind";
const link_mode = .static;
@@ -124,7 +144,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
.owner = root_mod,
};
}
- const sub_compilation = try Compilation.create(comp.gpa, arena, .{
+ const sub_compilation = Compilation.create(comp.gpa, arena, .{
.self_exe_path = comp.self_exe_path,
.local_cache_directory = comp.global_cache_directory,
.global_cache_directory = comp.global_cache_directory,
@@ -148,10 +168,27 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
.clang_passthrough_mode = comp.clang_passthrough_mode,
.skip_linker_dependencies = true,
- });
+ }) catch |err| {
+ comp.setMiscFailure(
+ .libunwind,
+ "unable to build libunwind: create compilation failed: {s}",
+ .{@errorName(err)},
+ );
+ return error.SubCompilationFailed;
+ };
defer sub_compilation.destroy();
- try comp.updateSubCompilation(sub_compilation, .libunwind, prog_node);
+ comp.updateSubCompilation(sub_compilation, .libunwind, prog_node) catch |err| switch (err) {
+ error.SubCompilationFailed => return error.SubCompilationFailed,
+ else => |e| {
+ comp.setMiscFailure(
+ .libunwind,
+ "unable to build libunwind: compilation failed: {s}",
+ .{@errorName(e)},
+ );
+ return error.SubCompilationFailed;
+ },
+ };
assert(comp.libunwind_static_lib == null);
comp.libunwind_static_lib = try sub_compilation.toCrtFile();