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