From 92b54e50c85488459df0c6579086494e31d9d52a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 15 Dec 2023 14:43:39 -0700 Subject: [PATCH] glibc: update to new Compilation API --- src/Compilation.zig | 2 ++ src/glibc.zig | 72 +++++++++++++++++++++++++++++++-------------- src/libcxx.zig | 2 ++ src/libtsan.zig | 1 + src/libunwind.zig | 1 + src/musl.zig | 1 + 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 2a2ef3e329..7b7e85d0f7 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6158,6 +6158,7 @@ fn buildOutputFromZig( }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = comp.compilerRtStrip(), .stack_check = false, .stack_protector = 0, @@ -6269,6 +6270,7 @@ pub fn build_crt_file( }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = comp.compilerRtStrip(), .stack_check = false, .stack_protector = 0, diff --git a/src/glibc.zig b/src/glibc.zig index d719dab491..0502bc3799 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -12,7 +12,7 @@ const Compilation = @import("Compilation.zig"); const build_options = @import("build_options"); const trace = @import("tracy.zig").trace; const Cache = std.Build.Cache; -const Package = @import("Package.zig"); +const Module = @import("Package/Module.zig"); pub const Lib = struct { name: []const u8, @@ -1067,34 +1067,62 @@ fn buildSharedLib( .src_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, asm_file_basename }), }, }; + + 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, + }); + + 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 = .{ + .resolved_target = comp.root_mod.resolved_target, + .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, + .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 = zig_cache_directory, .global_cache_directory = comp.global_cache_directory, .zig_lib_directory = comp.zig_lib_directory, - .cache_mode = .whole, - .target = comp.getTarget(), - .root_name = lib.name, - .main_mod = null, - .output_mode = .Lib, - .link_mode = .Dynamic, .thread_pool = comp.thread_pool, - .libc_installation = comp.bin_file.options.libc_installation, - .emit_bin = emit_bin, - .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, - .emit_h = null, - .strip = comp.compilerRtStrip(), - .is_native_os = false, - .is_native_abi = false, .self_exe_path = comp.self_exe_path, + .cache_mode = .whole, + .config = config, + .root_mod = root_mod, + .root_name = lib.name, + .libc_installation = comp.libc_installation, + .emit_bin = emit_bin, + .emit_h = null, .verbose_cc = comp.verbose_cc, - .verbose_link = comp.bin_file.options.verbose_link, + .verbose_link = comp.verbose_link, .verbose_air = comp.verbose_air, .verbose_llvm_ir = comp.verbose_llvm_ir, .verbose_llvm_bc = comp.verbose_llvm_bc, diff --git a/src/libcxx.zig b/src/libcxx.zig index 1f78b867a3..0625d033bf 100644 --- a/src/libcxx.zig +++ b/src/libcxx.zig @@ -251,6 +251,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void { }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = strip, .stack_check = false, .stack_protector = 0, @@ -439,6 +440,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void { }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = strip, .stack_check = false, .stack_protector = 0, diff --git a/src/libtsan.zig b/src/libtsan.zig index 745a947153..6220f00e8f 100644 --- a/src/libtsan.zig +++ b/src/libtsan.zig @@ -219,6 +219,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void { }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = strip, .stack_check = false, .stack_protector = 0, diff --git a/src/libunwind.zig b/src/libunwind.zig index baf24d8508..5b963c96c9 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -40,6 +40,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void { }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = comp.compilerRtStrip(), .stack_check = false, .stack_protector = 0, diff --git a/src/musl.zig b/src/musl.zig index 249753d415..953c5687e9 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -222,6 +222,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr }, .fully_qualified_name = "root", .inherited = .{ + .resolved_target = comp.root_mod.resolved_target, .strip = strip, .stack_check = false, .stack_protector = 0,