authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-13 13:31:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
log1642c003b4bab4a53b6094b42d10f6934896801e
treeaf4fa7412a6cac37a98c84cb72068c0f88e85a6b
parentf5ddef1e45fb5e6defcad21e50736c6e0f63c089

update libunwind references to bin_file.options


3 files changed, 62 insertions(+), 46 deletions(-)

src/Compilation.zig+1-1
......@@ -6212,9 +6212,9 @@ fn buildOutputFromZig(
62126212 .local_cache_directory = comp.global_cache_directory,
62136213 .zig_lib_directory = comp.zig_lib_directory,
62146214 .resolved = config,
6215 .root_mod = root_mod,
62156216 .cache_mode = .whole,
62166217 .root_name = root_name,
6217 .root_mod = root_mod,
62186218 .thread_pool = comp.thread_pool,
62196219 .libc_installation = comp.bin_file.options.libc_installation,
62206220 .emit_bin = emit_bin,
src/libunwind.zig+46-28
......@@ -4,6 +4,7 @@ const assert = std.debug.assert;
44
55const target_util = @import("target.zig");
66const Compilation = @import("Compilation.zig");
7const Module = @import("Package/Module.zig");
78const build_options = @import("build_options");
89const trace = @import("tracy.zig").trace;
910
......@@ -19,10 +20,44 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
1920 defer arena_allocator.deinit();
2021 const arena = arena_allocator.allocator();
2122
22 const root_name = "unwind";
2323 const output_mode = .Lib;
24 const config = try Compilation.Config.resolve(.{
25 .output_mode = .Lib,
26 .resolved_target = comp.root_mod.resolved_target,
27 .is_test = false,
28 .have_zcu = false,
29 .emit_bin = true,
30 .root_optimize_mode = comp.compilerRtOptMode(),
31 .link_libc = true,
32 // Disable LTO to avoid https://github.com/llvm/llvm-project/issues/56825
33 .lto = false,
34 });
35 const root_mod = Module.create(.{
36 .paths = .{
37 .root = .{ .root_dir = comp.zig_lib_directory },
38 .root_src_path = "",
39 },
40 .fully_qualified_name = "root",
41 .inherited = .{
42 .strip = comp.compilerRtStrip(),
43 .stack_check = false,
44 .stack_protector = 0,
45 .red_zone = comp.root_mod.red_zone,
46 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
47 .valgrind = false,
48 .sanitize_c = false,
49 .sanitize_thread = false,
50 .unwind_tables = false,
51 .pic = comp.root_mod.pic,
52 .optimize_mode = comp.compilerRtOptMode(),
53 },
54 .global = config,
55 .cc_argv = &.{},
56 });
57
58 const root_name = "unwind";
2459 const link_mode = .Static;
25 const target = comp.getTarget();
60 const target = comp.root_mod.resolved_target.result;
2661 const basename = try std.zig.binNameAlloc(arena, .{
2762 .root_name = root_name,
2863 .target = target,
......@@ -64,7 +99,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
6499 // defines will be correct.
65100 try cflags.append("-D_LIBUNWIND_IS_NATIVE_ONLY");
66101
67 if (comp.bin_file.options.optimize_mode == .Debug) {
102 if (comp.root_mod.optimize_mode == .Debug) {
68103 try cflags.append("-D_DEBUG");
69104 }
70105 if (!comp.config.any_non_single_threaded) {
......@@ -83,46 +118,29 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
83118 };
84119 }
85120 const sub_compilation = try Compilation.create(comp.gpa, .{
121 .self_exe_path = comp.self_exe_path,
86122 .local_cache_directory = comp.global_cache_directory,
87123 .global_cache_directory = comp.global_cache_directory,
88124 .zig_lib_directory = comp.zig_lib_directory,
125 .resolved = config,
126 .root_mod = root_mod,
89127 .cache_mode = .whole,
90 .target = target,
91128 .root_name = root_name,
92129 .main_mod = null,
93 .output_mode = output_mode,
94130 .thread_pool = comp.thread_pool,
95 .libc_installation = comp.bin_file.options.libc_installation,
131 .libc_installation = comp.libc_installation,
96132 .emit_bin = emit_bin,
97 .optimize_mode = comp.compilerRtOptMode(),
98133 .link_mode = link_mode,
99 .want_sanitize_c = false,
100 .want_stack_check = false,
101 .want_stack_protector = 0,
102 .want_red_zone = comp.bin_file.options.red_zone,
103 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
104 .want_valgrind = false,
105 .want_tsan = false,
106 .want_pic = comp.bin_file.options.pic,
107 .want_pie = null,
108 // Disable LTO to avoid https://github.com/llvm/llvm-project/issues/56825
109 .want_lto = false,
110 .function_sections = comp.bin_file.options.function_sections,
111 .emit_h = null,
112 .strip = comp.compilerRtStrip(),
113 .is_native_os = comp.bin_file.options.is_native_os,
114 .is_native_abi = comp.bin_file.options.is_native_abi,
115 .self_exe_path = comp.self_exe_path,
134 .function_sections = comp.bin_file.function_sections,
116135 .c_source_files = &c_source_files,
117136 .verbose_cc = comp.verbose_cc,
118 .verbose_link = comp.bin_file.options.verbose_link,
137 .verbose_link = comp.verbose_link,
119138 .verbose_air = comp.verbose_air,
120139 .verbose_llvm_ir = comp.verbose_llvm_ir,
121140 .verbose_llvm_bc = comp.verbose_llvm_bc,
122141 .verbose_cimport = comp.verbose_cimport,
123142 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
124143 .clang_passthrough_mode = comp.clang_passthrough_mode,
125 .link_libc = true,
126144 .skip_linker_dependencies = true,
127145 });
128146 defer sub_compilation.destroy();
......@@ -132,8 +150,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
132150 assert(comp.libunwind_static_lib == null);
133151
134152 comp.libunwind_static_lib = Compilation.CRTFile{
135 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{
136 sub_compilation.bin_file.options.emit.?.sub_path,
153 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
154 sub_compilation.bin_file.?.emit.sub_path,
137155 }),
138156 .lock = sub_compilation.bin_file.toOwnedLock(),
139157 };
src/main.zig+15-17
......@@ -3552,7 +3552,7 @@ fn buildOutputType(
35523552 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
35533553 // Default to using `zig run` to execute the produced .c code from `zig test`.
35543554 const c_code_loc = emit_bin_loc orelse break :default_exec_args;
3555 const c_code_directory = c_code_loc.directory orelse comp.bin_file.options.emit.?.directory;
3555 const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.directory;
35563556 const c_code_path = try fs.path.join(arena, &[_][]const u8{
35573557 c_code_directory.path orelse ".", c_code_loc.basename,
35583558 });
......@@ -3921,7 +3921,7 @@ fn serve(
39213921 continue;
39223922 }
39233923
3924 if (comp.bin_file.options.output_mode == .Exe) {
3924 if (comp.config.output_mode == .Exe) {
39253925 try comp.makeBinFileWritable();
39263926 }
39273927
......@@ -3971,7 +3971,7 @@ fn serve(
39713971 try comp.hotCodeSwap(main_progress_node, pid);
39723972 try serveUpdateResults(&server, comp);
39733973 } else {
3974 if (comp.bin_file.options.output_mode == .Exe) {
3974 if (comp.config.output_mode == .Exe) {
39753975 try comp.makeBinFileWritable();
39763976 }
39773977 try comp.update(main_progress_node);
......@@ -4067,13 +4067,14 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
40674067 // system depends on that fact. So, until the protocol is changed to
40684068 // reflect this, this logic only needs to ensure that emit_bin_path is
40694069 // emitted for at least one thing, if there are any artifacts.
4070 if (comp.bin_file.options.emit) |emit| {
4070 if (comp.bin_file) |lf| {
4071 const emit = lf.emit;
40714072 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
40724073 defer gpa.free(full_path);
40734074 try s.serveEmitBinPath(full_path, .{
40744075 .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
40754076 });
4076 } else if (comp.bin_file.options.docs_emit) |emit| {
4077 } else if (comp.docs_emit) |emit| {
40774078 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
40784079 defer gpa.free(full_path);
40794080 try s.serveEmitBinPath(full_path, .{
......@@ -4148,11 +4149,11 @@ fn runOrTest(
41484149 runtime_args_start: ?usize,
41494150 link_libc: bool,
41504151) !void {
4151 const exe_emit = comp.bin_file.options.emit orelse return;
4152 const lf = comp.bin_file orelse return;
41524153 // A naive `directory.join` here will indeed get the correct path to the binary,
41534154 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
41544155 const exe_path = try fs.path.join(arena, &[_][]const u8{
4155 exe_emit.directory.path orelse ".", exe_emit.sub_path,
4156 lf.emit.directory.path orelse ".", lf.emit.sub_path,
41564157 });
41574158
41584159 var argv = std.ArrayList([]const u8).init(gpa);
......@@ -4244,7 +4245,7 @@ fn runOrTestHotSwap(
42444245 all_args: []const []const u8,
42454246 runtime_args_start: ?usize,
42464247) !std.ChildProcess.Id {
4247 const exe_emit = comp.bin_file.options.emit.?;
4248 const lf = comp.bin_file.?;
42484249
42494250 const exe_path = switch (builtin.target.os.tag) {
42504251 // On Windows it seems impossible to perform an atomic rename of a file that is currently
......@@ -4252,16 +4253,16 @@ fn runOrTestHotSwap(
42524253 // tmp zig-cache and use it to spawn the child process. This way we are free to update
42534254 // the binary with each requested hot update.
42544255 .windows => blk: {
4255 try exe_emit.directory.handle.copyFile(exe_emit.sub_path, comp.local_cache_directory.handle, exe_emit.sub_path, .{});
4256 try lf.emit.directory.handle.copyFile(lf.emit.sub_path, comp.local_cache_directory.handle, lf.emit.sub_path, .{});
42564257 break :blk try fs.path.join(gpa, &[_][]const u8{
4257 comp.local_cache_directory.path orelse ".", exe_emit.sub_path,
4258 comp.local_cache_directory.path orelse ".", lf.emit.sub_path,
42584259 });
42594260 },
42604261
42614262 // A naive `directory.join` here will indeed get the correct path to the binary,
42624263 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
42634264 else => try fs.path.join(gpa, &[_][]const u8{
4264 exe_emit.directory.path orelse ".", exe_emit.sub_path,
4265 lf.emit.directory.path orelse ".", lf.emit.sub_path,
42654266 }),
42664267 };
42674268 defer gpa.free(exe_path);
......@@ -4367,7 +4368,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
43674368 assert(comp.c_source_files.len == 1);
43684369 const c_source_file = comp.c_source_files[0];
43694370
4370 const translated_zig_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{comp.bin_file.options.root_name});
4371 const translated_zig_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{comp.root_name});
43714372
43724373 var man: Cache.Manifest = comp.obtainCObjectCacheManifest();
43734374 man.want_shared_lock = false;
......@@ -5450,11 +5451,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
54505451 };
54515452 try comp.makeBinFileExecutable();
54525453
5453 const emit = comp.bin_file.options.emit.?;
5454 child_argv.items[argv_index_exe] = try emit.directory.join(
5455 arena,
5456 &[_][]const u8{emit.sub_path},
5457 );
5454 const emit = comp.bin_file.?.emit;
5455 child_argv.items[argv_index_exe] = try emit.directory.join(arena, &.{emit.sub_path});
54585456
54595457 break :argv child_argv.items;
54605458 };