authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-14 19:10:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
log7e7d5dc958b08dc0f671cd1b119cd831fc877d16
treec9981ac31ed6e0a816d7a39856b0df743c222e84
parent6b44bddf5dd4a50c79cd1a4d3596cc07d868dd63

musl: update references to bin_file.options


2 files changed, 59 insertions(+), 29 deletions(-)

src/Compilation.zig+1-1
......@@ -6241,7 +6241,7 @@ pub fn build_crt_file(
62416241 defer arena_allocator.deinit();
62426242 const arena = arena_allocator.allocator();
62436243
6244 const basename = try std.zig.binNameAlloc(arena, .{
6244 const basename = try std.zig.binNameAlloc(gpa, .{
62456245 .root_name = root_name,
62466246 .target = comp.root_mod.resolved_target.result,
62476247 .output_mode = output_mode,
src/musl.zig+58-28
......@@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
33const mem = std.mem;
44const path = std.fs.path;
55const assert = std.debug.assert;
6const Module = @import("Package/Module.zig");
67
78const Compilation = @import("Compilation.zig");
89const build_options = @import("build_options");
......@@ -190,41 +191,70 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
190191 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
191192 },
192193 .libc_so => {
193 const target = comp.getTarget();
194 const unwind_tables = false;
195 const optimize_mode = comp.compilerRtOptMode();
196 const strip = comp.compilerRtStrip();
197 const config = try Compilation.Config.resolve(.{
198 .output_mode = .Lib,
199 .link_mode = .Dynamic,
200 .resolved_target = comp.root_mod.resolved_target,
201 .is_test = false,
202 .have_zcu = false,
203 .emit_bin = true,
204 .root_optimize_mode = optimize_mode,
205 .root_strip = strip,
206 .link_libc = false,
207 .any_unwind_tables = unwind_tables,
208 });
209
210 const target = comp.root_mod.resolved_target.result;
194211 const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{
195212 @tagName(target.cpu.arch),
196213 });
197 const clang_argv: []const []const u8 = if (target.ptrBitWidth() == 64)
198 &[_][]const u8{ "-DPTR64", arch_define }
214 const cc_argv: []const []const u8 = if (target.ptrBitWidth() == 64)
215 &.{ "-DPTR64", arch_define }
199216 else
200 &[_][]const u8{arch_define};
217 &.{arch_define};
218
219 const root_mod = try Module.create(arena, .{
220 .global_cache_directory = comp.global_cache_directory,
221 .paths = .{
222 .root = .{ .root_dir = comp.zig_lib_directory },
223 .root_src_path = "",
224 },
225 .fully_qualified_name = "root",
226 .inherited = .{
227 .strip = strip,
228 .stack_check = false,
229 .stack_protector = 0,
230 .sanitize_c = false,
231 .sanitize_thread = false,
232 .red_zone = comp.root_mod.red_zone,
233 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
234 .valgrind = false,
235 .unwind_tables = unwind_tables,
236 .optimize_mode = optimize_mode,
237 .structured_cfg = comp.root_mod.structured_cfg,
238 },
239 .global = config,
240 .cc_argv = &.{},
241 .parent = null,
242 .builtin_mod = null,
243 });
201244
202245 const sub_compilation = try Compilation.create(comp.gpa, .{
203246 .local_cache_directory = comp.global_cache_directory,
204247 .global_cache_directory = comp.global_cache_directory,
205 .cache_mode = .whole,
206248 .zig_lib_directory = comp.zig_lib_directory,
207 .target = target,
208 .root_name = "c",
209 .main_mod = null,
210 .output_mode = .Lib,
211 .link_mode = .Dynamic,
249 .self_exe_path = comp.self_exe_path,
250 .cache_mode = .whole,
251 .config = config,
252 .root_mod = root_mod,
212253 .thread_pool = comp.thread_pool,
213 .libc_installation = comp.bin_file.options.libc_installation,
214 .emit_bin = Compilation.EmitLoc{ .directory = null, .basename = "libc.so" },
215 .optimize_mode = comp.compilerRtOptMode(),
216 .want_sanitize_c = false,
217 .want_stack_check = false,
218 .want_stack_protector = 0,
219 .want_red_zone = comp.bin_file.options.red_zone,
220 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
221 .want_valgrind = false,
222 .want_tsan = false,
254 .root_name = "c",
255 .libc_installation = comp.libc_installation,
256 .emit_bin = .{ .directory = null, .basename = "libc.so" },
223257 .emit_h = null,
224 .strip = comp.compilerRtStrip(),
225 .is_native_os = false,
226 .is_native_abi = false,
227 .self_exe_path = comp.self_exe_path,
228258 .verbose_cc = comp.verbose_cc,
229259 .verbose_link = comp.verbose_link,
230260 .verbose_air = comp.verbose_air,
......@@ -233,9 +263,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
233263 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
234264 .clang_passthrough_mode = comp.clang_passthrough_mode,
235265 .c_source_files = &[_]Compilation.CSourceFile{
236 .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "libc.S" }) },
266 .{ .src_path = try comp.zig_lib_directory.join(arena, &.{ "libc", "musl", "libc.S" }) },
237267 },
238 .clang_argv = clang_argv,
268 .cc_argv = cc_argv,
239269 .skip_linker_dependencies = true,
240270 .soname = "libc.so",
241271 });
......@@ -249,8 +279,8 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
249279 errdefer comp.gpa.free(basename);
250280
251281 comp.crt_files.putAssumeCapacityNoClobber(basename, .{
252 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{
253 sub_compilation.bin_file.options.emit.?.sub_path,
282 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{
283 sub_compilation.bin_file.?.emit.sub_path,
254284 }),
255285 .lock = sub_compilation.bin_file.toOwnedLock(),
256286 });