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(...@@ -6212,9 +6212,9 @@ fn buildOutputFromZig(
6212 .local_cache_directory = comp.global_cache_directory,6212 .local_cache_directory = comp.global_cache_directory,
6213 .zig_lib_directory = comp.zig_lib_directory,6213 .zig_lib_directory = comp.zig_lib_directory,
6214 .resolved = config,6214 .resolved = config,
6215 .root_mod = root_mod,
6215 .cache_mode = .whole,6216 .cache_mode = .whole,
6216 .root_name = root_name,6217 .root_name = root_name,
6217 .root_mod = root_mod,
6218 .thread_pool = comp.thread_pool,6218 .thread_pool = comp.thread_pool,
6219 .libc_installation = comp.bin_file.options.libc_installation,6219 .libc_installation = comp.bin_file.options.libc_installation,
6220 .emit_bin = emit_bin,6220 .emit_bin = emit_bin,
src/libunwind.zig+46-28
...@@ -4,6 +4,7 @@ const assert = std.debug.assert;...@@ -4,6 +4,7 @@ const assert = std.debug.assert;
44
5const target_util = @import("target.zig");5const target_util = @import("target.zig");
6const Compilation = @import("Compilation.zig");6const Compilation = @import("Compilation.zig");
7const Module = @import("Package/Module.zig");
7const build_options = @import("build_options");8const build_options = @import("build_options");
8const trace = @import("tracy.zig").trace;9const trace = @import("tracy.zig").trace;
910
...@@ -19,10 +20,44 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -19,10 +20,44 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
19 defer arena_allocator.deinit();20 defer arena_allocator.deinit();
20 const arena = arena_allocator.allocator();21 const arena = arena_allocator.allocator();
2122
22 const root_name = "unwind";
23 const output_mode = .Lib;23 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";
24 const link_mode = .Static;59 const link_mode = .Static;
25 const target = comp.getTarget();60 const target = comp.root_mod.resolved_target.result;
26 const basename = try std.zig.binNameAlloc(arena, .{61 const basename = try std.zig.binNameAlloc(arena, .{
27 .root_name = root_name,62 .root_name = root_name,
28 .target = target,63 .target = target,
...@@ -64,7 +99,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -64,7 +99,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
64 // defines will be correct.99 // defines will be correct.
65 try cflags.append("-D_LIBUNWIND_IS_NATIVE_ONLY");100 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) {
68 try cflags.append("-D_DEBUG");103 try cflags.append("-D_DEBUG");
69 }104 }
70 if (!comp.config.any_non_single_threaded) {105 if (!comp.config.any_non_single_threaded) {
...@@ -83,46 +118,29 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -83,46 +118,29 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
83 };118 };
84 }119 }
85 const sub_compilation = try Compilation.create(comp.gpa, .{120 const sub_compilation = try Compilation.create(comp.gpa, .{
121 .self_exe_path = comp.self_exe_path,
86 .local_cache_directory = comp.global_cache_directory,122 .local_cache_directory = comp.global_cache_directory,
87 .global_cache_directory = comp.global_cache_directory,123 .global_cache_directory = comp.global_cache_directory,
88 .zig_lib_directory = comp.zig_lib_directory,124 .zig_lib_directory = comp.zig_lib_directory,
125 .resolved = config,
126 .root_mod = root_mod,
89 .cache_mode = .whole,127 .cache_mode = .whole,
90 .target = target,
91 .root_name = root_name,128 .root_name = root_name,
92 .main_mod = null,129 .main_mod = null,
93 .output_mode = output_mode,
94 .thread_pool = comp.thread_pool,130 .thread_pool = comp.thread_pool,
95 .libc_installation = comp.bin_file.options.libc_installation,131 .libc_installation = comp.libc_installation,
96 .emit_bin = emit_bin,132 .emit_bin = emit_bin,
97 .optimize_mode = comp.compilerRtOptMode(),
98 .link_mode = link_mode,133 .link_mode = link_mode,
99 .want_sanitize_c = false,134 .function_sections = comp.bin_file.function_sections,
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,
116 .c_source_files = &c_source_files,135 .c_source_files = &c_source_files,
117 .verbose_cc = comp.verbose_cc,136 .verbose_cc = comp.verbose_cc,
118 .verbose_link = comp.bin_file.options.verbose_link,137 .verbose_link = comp.verbose_link,
119 .verbose_air = comp.verbose_air,138 .verbose_air = comp.verbose_air,
120 .verbose_llvm_ir = comp.verbose_llvm_ir,139 .verbose_llvm_ir = comp.verbose_llvm_ir,
121 .verbose_llvm_bc = comp.verbose_llvm_bc,140 .verbose_llvm_bc = comp.verbose_llvm_bc,
122 .verbose_cimport = comp.verbose_cimport,141 .verbose_cimport = comp.verbose_cimport,
123 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,142 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
124 .clang_passthrough_mode = comp.clang_passthrough_mode,143 .clang_passthrough_mode = comp.clang_passthrough_mode,
125 .link_libc = true,
126 .skip_linker_dependencies = true,144 .skip_linker_dependencies = true,
127 });145 });
128 defer sub_compilation.destroy();146 defer sub_compilation.destroy();
...@@ -132,8 +150,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -132,8 +150,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
132 assert(comp.libunwind_static_lib == null);150 assert(comp.libunwind_static_lib == null);
133151
134 comp.libunwind_static_lib = Compilation.CRTFile{152 comp.libunwind_static_lib = Compilation.CRTFile{
135 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{153 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
136 sub_compilation.bin_file.options.emit.?.sub_path,154 sub_compilation.bin_file.?.emit.sub_path,
137 }),155 }),
138 .lock = sub_compilation.bin_file.toOwnedLock(),156 .lock = sub_compilation.bin_file.toOwnedLock(),
139 };157 };
src/main.zig+15-17
...@@ -3552,7 +3552,7 @@ fn buildOutputType(...@@ -3552,7 +3552,7 @@ fn buildOutputType(
3552 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {3552 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
3553 // Default to using `zig run` to execute the produced .c code from `zig test`.3553 // Default to using `zig run` to execute the produced .c code from `zig test`.
3554 const c_code_loc = emit_bin_loc orelse break :default_exec_args;3554 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;
3556 const c_code_path = try fs.path.join(arena, &[_][]const u8{3556 const c_code_path = try fs.path.join(arena, &[_][]const u8{
3557 c_code_directory.path orelse ".", c_code_loc.basename,3557 c_code_directory.path orelse ".", c_code_loc.basename,
3558 });3558 });
...@@ -3921,7 +3921,7 @@ fn serve(...@@ -3921,7 +3921,7 @@ fn serve(
3921 continue;3921 continue;
3922 }3922 }
39233923
3924 if (comp.bin_file.options.output_mode == .Exe) {3924 if (comp.config.output_mode == .Exe) {
3925 try comp.makeBinFileWritable();3925 try comp.makeBinFileWritable();
3926 }3926 }
39273927
...@@ -3971,7 +3971,7 @@ fn serve(...@@ -3971,7 +3971,7 @@ fn serve(
3971 try comp.hotCodeSwap(main_progress_node, pid);3971 try comp.hotCodeSwap(main_progress_node, pid);
3972 try serveUpdateResults(&server, comp);3972 try serveUpdateResults(&server, comp);
3973 } else {3973 } else {
3974 if (comp.bin_file.options.output_mode == .Exe) {3974 if (comp.config.output_mode == .Exe) {
3975 try comp.makeBinFileWritable();3975 try comp.makeBinFileWritable();
3976 }3976 }
3977 try comp.update(main_progress_node);3977 try comp.update(main_progress_node);
...@@ -4067,13 +4067,14 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {...@@ -4067,13 +4067,14 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
4067 // system depends on that fact. So, until the protocol is changed to4067 // system depends on that fact. So, until the protocol is changed to
4068 // reflect this, this logic only needs to ensure that emit_bin_path is4068 // reflect this, this logic only needs to ensure that emit_bin_path is
4069 // emitted for at least one thing, if there are any artifacts.4069 // 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;
4071 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});4072 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
4072 defer gpa.free(full_path);4073 defer gpa.free(full_path);
4073 try s.serveEmitBinPath(full_path, .{4074 try s.serveEmitBinPath(full_path, .{
4074 .flags = .{ .cache_hit = comp.last_update_was_cache_hit },4075 .flags = .{ .cache_hit = comp.last_update_was_cache_hit },
4075 });4076 });
4076 } else if (comp.bin_file.options.docs_emit) |emit| {4077 } else if (comp.docs_emit) |emit| {
4077 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});4078 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
4078 defer gpa.free(full_path);4079 defer gpa.free(full_path);
4079 try s.serveEmitBinPath(full_path, .{4080 try s.serveEmitBinPath(full_path, .{
...@@ -4148,11 +4149,11 @@ fn runOrTest(...@@ -4148,11 +4149,11 @@ fn runOrTest(
4148 runtime_args_start: ?usize,4149 runtime_args_start: ?usize,
4149 link_libc: bool,4150 link_libc: bool,
4150) !void {4151) !void {
4151 const exe_emit = comp.bin_file.options.emit orelse return;4152 const lf = comp.bin_file orelse return;
4152 // A naive `directory.join` here will indeed get the correct path to the binary,4153 // A naive `directory.join` here will indeed get the correct path to the binary,
4153 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.4154 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
4154 const exe_path = try fs.path.join(arena, &[_][]const u8{4155 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,
4156 });4157 });
41574158
4158 var argv = std.ArrayList([]const u8).init(gpa);4159 var argv = std.ArrayList([]const u8).init(gpa);
...@@ -4244,7 +4245,7 @@ fn runOrTestHotSwap(...@@ -4244,7 +4245,7 @@ fn runOrTestHotSwap(
4244 all_args: []const []const u8,4245 all_args: []const []const u8,
4245 runtime_args_start: ?usize,4246 runtime_args_start: ?usize,
4246) !std.ChildProcess.Id {4247) !std.ChildProcess.Id {
4247 const exe_emit = comp.bin_file.options.emit.?;4248 const lf = comp.bin_file.?;
42484249
4249 const exe_path = switch (builtin.target.os.tag) {4250 const exe_path = switch (builtin.target.os.tag) {
4250 // On Windows it seems impossible to perform an atomic rename of a file that is currently4251 // On Windows it seems impossible to perform an atomic rename of a file that is currently
...@@ -4252,16 +4253,16 @@ fn runOrTestHotSwap(...@@ -4252,16 +4253,16 @@ fn runOrTestHotSwap(
4252 // tmp zig-cache and use it to spawn the child process. This way we are free to update4253 // tmp zig-cache and use it to spawn the child process. This way we are free to update
4253 // the binary with each requested hot update.4254 // the binary with each requested hot update.
4254 .windows => blk: {4255 .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, .{});
4256 break :blk try fs.path.join(gpa, &[_][]const u8{4257 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,
4258 });4259 });
4259 },4260 },
42604261
4261 // A naive `directory.join` here will indeed get the correct path to the binary,4262 // A naive `directory.join` here will indeed get the correct path to the binary,
4262 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.4263 // however, in the case of cwd, we actually want `./foo` so that the path can be executed.
4263 else => try fs.path.join(gpa, &[_][]const u8{4264 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,
4265 }),4266 }),
4266 };4267 };
4267 defer gpa.free(exe_path);4268 defer gpa.free(exe_path);
...@@ -4367,7 +4368,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati...@@ -4367,7 +4368,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
4367 assert(comp.c_source_files.len == 1);4368 assert(comp.c_source_files.len == 1);
4368 const c_source_file = comp.c_source_files[0];4369 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
4372 var man: Cache.Manifest = comp.obtainCObjectCacheManifest();4373 var man: Cache.Manifest = comp.obtainCObjectCacheManifest();
4373 man.want_shared_lock = false;4374 man.want_shared_lock = false;
...@@ -5450,11 +5451,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -5450,11 +5451,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
5450 };5451 };
5451 try comp.makeBinFileExecutable();5452 try comp.makeBinFileExecutable();
54525453
5453 const emit = comp.bin_file.options.emit.?;5454 const emit = comp.bin_file.?.emit;
5454 child_argv.items[argv_index_exe] = try emit.directory.join(5455 child_argv.items[argv_index_exe] = try emit.directory.join(arena, &.{emit.sub_path});
5455 arena,
5456 &[_][]const u8{emit.sub_path},
5457 );
54585456
5459 break :argv child_argv.items;5457 break :argv child_argv.items;
5460 };5458 };