| ... | ... | @@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const path = std.fs.path; |
| 5 | 5 | const assert = std.debug.assert; |
| 6 | const Module = @import("Package/Module.zig"); |
| 6 | 7 | |
| 7 | 8 | const Compilation = @import("Compilation.zig"); |
| 8 | 9 | const build_options = @import("build_options"); |
| ... | ... | @@ -190,41 +191,70 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 190 | 191 | return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items); |
| 191 | 192 | }, |
| 192 | 193 | .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; |
| 194 | 211 | const arch_define = try std.fmt.allocPrint(arena, "-DARCH_{s}", .{ |
| 195 | 212 | @tagName(target.cpu.arch), |
| 196 | 213 | }); |
| 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 } |
| 199 | 216 | 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 | }); |
| 201 | 244 | |
| 202 | 245 | const sub_compilation = try Compilation.create(comp.gpa, .{ |
| 203 | 246 | .local_cache_directory = comp.global_cache_directory, |
| 204 | 247 | .global_cache_directory = comp.global_cache_directory, |
| 205 | | .cache_mode = .whole, |
| 206 | 248 | .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, |
| 212 | 253 | .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" }, |
| 223 | 257 | .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, |
| 228 | 258 | .verbose_cc = comp.verbose_cc, |
| 229 | 259 | .verbose_link = comp.verbose_link, |
| 230 | 260 | .verbose_air = comp.verbose_air, |
| ... | ... | @@ -233,9 +263,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 233 | 263 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 234 | 264 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 235 | 265 | .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" }) }, |
| 237 | 267 | }, |
| 238 | | .clang_argv = clang_argv, |
| 268 | .cc_argv = cc_argv, |
| 239 | 269 | .skip_linker_dependencies = true, |
| 240 | 270 | .soname = "libc.so", |
| 241 | 271 | }); |
| ... | ... | @@ -249,8 +279,8 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr |
| 249 | 279 | errdefer comp.gpa.free(basename); |
| 250 | 280 | |
| 251 | 281 | 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, |
| 254 | 284 | }), |
| 255 | 285 | .lock = sub_compilation.bin_file.toOwnedLock(), |
| 256 | 286 | }); |