Commit 7e7d5dc958

Andrew Kelley <andrew@ziglang.org>
2023-12-15 03:10:32
musl: update references to bin_file.options
1 parent 6b44bdd
Changed files (2)
src/Compilation.zig
@@ -6241,7 +6241,7 @@ pub fn build_crt_file(
     defer arena_allocator.deinit();
     const arena = arena_allocator.allocator();
 
-    const basename = try std.zig.binNameAlloc(arena, .{
+    const basename = try std.zig.binNameAlloc(gpa, .{
         .root_name = root_name,
         .target = comp.root_mod.resolved_target.result,
         .output_mode = output_mode,
src/musl.zig
@@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
 const mem = std.mem;
 const path = std.fs.path;
 const assert = std.debug.assert;
+const Module = @import("Package/Module.zig");
 
 const Compilation = @import("Compilation.zig");
 const build_options = @import("build_options");
@@ -190,41 +191,70 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
             return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
         },
         .libc_so => {
-            const target = comp.getTarget();
+            const unwind_tables = false;
+            const optimize_mode = comp.compilerRtOptMode();
+            const strip = comp.compilerRtStrip();
+            const config = try Compilation.Config.resolve(.{
+                .output_mode = .Lib,
+                .link_mode = .Dynamic,
+                .resolved_target = comp.root_mod.resolved_target,
+                .is_test = false,
+                .have_zcu = false,
+                .emit_bin = true,
+                .root_optimize_mode = optimize_mode,
+                .root_strip = strip,
+                .link_libc = false,
+                .any_unwind_tables = unwind_tables,
+            });
+
+            const target = comp.root_mod.resolved_target.result;
             const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{
                 @tagName(target.cpu.arch),
             });
-            const clang_argv: []const []const u8 = if (target.ptrBitWidth() == 64)
-                &[_][]const u8{ "-DPTR64", arch_define }
+            const cc_argv: []const []const u8 = if (target.ptrBitWidth() == 64)
+                &.{ "-DPTR64", arch_define }
             else
-                &[_][]const u8{arch_define};
+                &.{arch_define};
+
+            const root_mod = try Module.create(arena, .{
+                .global_cache_directory = comp.global_cache_directory,
+                .paths = .{
+                    .root = .{ .root_dir = comp.zig_lib_directory },
+                    .root_src_path = "",
+                },
+                .fully_qualified_name = "root",
+                .inherited = .{
+                    .strip = strip,
+                    .stack_check = false,
+                    .stack_protector = 0,
+                    .sanitize_c = false,
+                    .sanitize_thread = false,
+                    .red_zone = comp.root_mod.red_zone,
+                    .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
+                    .valgrind = false,
+                    .unwind_tables = unwind_tables,
+                    .optimize_mode = optimize_mode,
+                    .structured_cfg = comp.root_mod.structured_cfg,
+                },
+                .global = config,
+                .cc_argv = &.{},
+                .parent = null,
+                .builtin_mod = null,
+            });
 
             const sub_compilation = try Compilation.create(comp.gpa, .{
                 .local_cache_directory = comp.global_cache_directory,
                 .global_cache_directory = comp.global_cache_directory,
-                .cache_mode = .whole,
                 .zig_lib_directory = comp.zig_lib_directory,
-                .target = target,
-                .root_name = "c",
-                .main_mod = null,
-                .output_mode = .Lib,
-                .link_mode = .Dynamic,
+                .self_exe_path = comp.self_exe_path,
+                .cache_mode = .whole,
+                .config = config,
+                .root_mod = root_mod,
                 .thread_pool = comp.thread_pool,
-                .libc_installation = comp.bin_file.options.libc_installation,
-                .emit_bin = Compilation.EmitLoc{ .directory = null, .basename = "libc.so" },
-                .optimize_mode = comp.compilerRtOptMode(),
-                .want_sanitize_c = false,
-                .want_stack_check = false,
-                .want_stack_protector = 0,
-                .want_red_zone = comp.bin_file.options.red_zone,
-                .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
-                .want_valgrind = false,
-                .want_tsan = false,
+                .root_name = "c",
+                .libc_installation = comp.libc_installation,
+                .emit_bin = .{ .directory = null, .basename = "libc.so" },
                 .emit_h = null,
-                .strip = comp.compilerRtStrip(),
-                .is_native_os = false,
-                .is_native_abi = false,
-                .self_exe_path = comp.self_exe_path,
                 .verbose_cc = comp.verbose_cc,
                 .verbose_link = comp.verbose_link,
                 .verbose_air = comp.verbose_air,
@@ -233,9 +263,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
                 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
                 .clang_passthrough_mode = comp.clang_passthrough_mode,
                 .c_source_files = &[_]Compilation.CSourceFile{
-                    .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "libc.S" }) },
+                    .{ .src_path = try comp.zig_lib_directory.join(arena, &.{ "libc", "musl", "libc.S" }) },
                 },
-                .clang_argv = clang_argv,
+                .cc_argv = cc_argv,
                 .skip_linker_dependencies = true,
                 .soname = "libc.so",
             });
@@ -249,8 +279,8 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
             errdefer comp.gpa.free(basename);
 
             comp.crt_files.putAssumeCapacityNoClobber(basename, .{
-                .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{
-                    sub_compilation.bin_file.options.emit.?.sub_path,
+                .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{
+                    sub_compilation.bin_file.?.emit.sub_path,
                 }),
                 .lock = sub_compilation.bin_file.toOwnedLock(),
             });