| ... | ... | @@ -1238,7 +1238,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1238 | 1238 | options.target, |
| 1239 | 1239 | options.is_native_abi, |
| 1240 | 1240 | link_libc, |
| 1241 | | options.system_lib_names.len != 0 or options.frameworks.count() != 0, |
| 1242 | 1241 | options.libc_installation, |
| 1243 | 1242 | options.native_darwin_sdk != null, |
| 1244 | 1243 | ); |
| ... | ... | @@ -4522,7 +4521,6 @@ fn detectLibCIncludeDirs( |
| 4522 | 4521 | target: Target, |
| 4523 | 4522 | is_native_abi: bool, |
| 4524 | 4523 | link_libc: bool, |
| 4525 | | link_system_libs: bool, |
| 4526 | 4524 | libc_installation: ?*const LibCInstallation, |
| 4527 | 4525 | has_macos_sdk: bool, |
| 4528 | 4526 | ) !LibCDirs { |
| ... | ... | @@ -4539,7 +4537,7 @@ fn detectLibCIncludeDirs( |
| 4539 | 4537 | |
| 4540 | 4538 | // If linking system libraries and targeting the native abi, default to |
| 4541 | 4539 | // using the system libc installation. |
| 4542 | | if (link_system_libs and is_native_abi and !target.isMinGW()) { |
| 4540 | if (is_native_abi and !target.isMinGW()) { |
| 4543 | 4541 | if (target.isDarwin()) { |
| 4544 | 4542 | return if (has_macos_sdk) |
| 4545 | 4543 | // For Darwin/macOS, we are all set with getDarwinSDK found earlier. |
| ... | ... | @@ -4551,74 +4549,29 @@ fn detectLibCIncludeDirs( |
| 4551 | 4549 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target); |
| 4552 | 4550 | } |
| 4553 | 4551 | const libc = try arena.create(LibCInstallation); |
| 4554 | | libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true }); |
| 4552 | libc.* = LibCInstallation.findNative(.{ .allocator = arena }) catch |err| switch (err) { |
| 4553 | error.CCompilerExitCode, |
| 4554 | error.CCompilerCrashed, |
| 4555 | error.CCompilerCannotFindHeaders, |
| 4556 | error.UnableToSpawnCCompiler, |
| 4557 | => |e| { |
| 4558 | // We tried to integrate with the native system C compiler, |
| 4559 | // however, it is not installed. So we must rely on our bundled |
| 4560 | // libc files. |
| 4561 | if (target_util.canBuildLibC(target)) { |
| 4562 | return detectLibCFromBuilding(arena, zig_lib_dir, target, has_macos_sdk); |
| 4563 | } |
| 4564 | return e; |
| 4565 | }, |
| 4566 | else => |e| return e, |
| 4567 | }; |
| 4555 | 4568 | return detectLibCFromLibCInstallation(arena, target, libc); |
| 4556 | 4569 | } |
| 4557 | 4570 | |
| 4558 | 4571 | // If not linking system libraries, build and provide our own libc by |
| 4559 | 4572 | // default if possible. |
| 4560 | 4573 | if (target_util.canBuildLibC(target)) { |
| 4561 | | switch (target.os.tag) { |
| 4562 | | .macos => return if (has_macos_sdk) |
| 4563 | | // For Darwin/macOS, we are all set with getDarwinSDK found earlier. |
| 4564 | | LibCDirs{ |
| 4565 | | .libc_include_dir_list = &[0][]u8{}, |
| 4566 | | .libc_installation = null, |
| 4567 | | } |
| 4568 | | else |
| 4569 | | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target), |
| 4570 | | else => { |
| 4571 | | const generic_name = target_util.libCGenericName(target); |
| 4572 | | // Some architectures are handled by the same set of headers. |
| 4573 | | const arch_name = if (target.abi.isMusl()) |
| 4574 | | musl.archName(target.cpu.arch) |
| 4575 | | else if (target.cpu.arch.isThumb()) |
| 4576 | | // ARM headers are valid for Thumb too. |
| 4577 | | switch (target.cpu.arch) { |
| 4578 | | .thumb => "arm", |
| 4579 | | .thumbeb => "armeb", |
| 4580 | | else => unreachable, |
| 4581 | | } |
| 4582 | | else |
| 4583 | | @tagName(target.cpu.arch); |
| 4584 | | const os_name = @tagName(target.os.tag); |
| 4585 | | // Musl's headers are ABI-agnostic and so they all have the "musl" ABI name. |
| 4586 | | const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi); |
| 4587 | | const s = std.fs.path.sep_str; |
| 4588 | | const arch_include_dir = try std.fmt.allocPrint( |
| 4589 | | arena, |
| 4590 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", |
| 4591 | | .{ zig_lib_dir, arch_name, os_name, abi_name }, |
| 4592 | | ); |
| 4593 | | const generic_include_dir = try std.fmt.allocPrint( |
| 4594 | | arena, |
| 4595 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}", |
| 4596 | | .{ zig_lib_dir, generic_name }, |
| 4597 | | ); |
| 4598 | | const generic_arch_name = target_util.osArchName(target); |
| 4599 | | const arch_os_include_dir = try std.fmt.allocPrint( |
| 4600 | | arena, |
| 4601 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any", |
| 4602 | | .{ zig_lib_dir, generic_arch_name, os_name }, |
| 4603 | | ); |
| 4604 | | const generic_os_include_dir = try std.fmt.allocPrint( |
| 4605 | | arena, |
| 4606 | | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", |
| 4607 | | .{ zig_lib_dir, os_name }, |
| 4608 | | ); |
| 4609 | | |
| 4610 | | const list = try arena.alloc([]const u8, 4); |
| 4611 | | list[0] = arch_include_dir; |
| 4612 | | list[1] = generic_include_dir; |
| 4613 | | list[2] = arch_os_include_dir; |
| 4614 | | list[3] = generic_os_include_dir; |
| 4615 | | |
| 4616 | | return LibCDirs{ |
| 4617 | | .libc_include_dir_list = list, |
| 4618 | | .libc_installation = null, |
| 4619 | | }; |
| 4620 | | }, |
| 4621 | | } |
| 4574 | return detectLibCFromBuilding(arena, zig_lib_dir, target, has_macos_sdk); |
| 4622 | 4575 | } |
| 4623 | 4576 | |
| 4624 | 4577 | // If zig can't build the libc for the target and we are targeting the |
| ... | ... | @@ -4677,6 +4630,75 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const |
| 4677 | 4630 | }; |
| 4678 | 4631 | } |
| 4679 | 4632 | |
| 4633 | fn detectLibCFromBuilding( |
| 4634 | arena: Allocator, |
| 4635 | zig_lib_dir: []const u8, |
| 4636 | target: std.Target, |
| 4637 | has_macos_sdk: bool, |
| 4638 | ) !LibCDirs { |
| 4639 | switch (target.os.tag) { |
| 4640 | .macos => return if (has_macos_sdk) |
| 4641 | // For Darwin/macOS, we are all set with getDarwinSDK found earlier. |
| 4642 | LibCDirs{ |
| 4643 | .libc_include_dir_list = &[0][]u8{}, |
| 4644 | .libc_installation = null, |
| 4645 | } |
| 4646 | else |
| 4647 | getZigShippedLibCIncludeDirsDarwin(arena, zig_lib_dir, target), |
| 4648 | else => { |
| 4649 | const generic_name = target_util.libCGenericName(target); |
| 4650 | // Some architectures are handled by the same set of headers. |
| 4651 | const arch_name = if (target.abi.isMusl()) |
| 4652 | musl.archName(target.cpu.arch) |
| 4653 | else if (target.cpu.arch.isThumb()) |
| 4654 | // ARM headers are valid for Thumb too. |
| 4655 | switch (target.cpu.arch) { |
| 4656 | .thumb => "arm", |
| 4657 | .thumbeb => "armeb", |
| 4658 | else => unreachable, |
| 4659 | } |
| 4660 | else |
| 4661 | @tagName(target.cpu.arch); |
| 4662 | const os_name = @tagName(target.os.tag); |
| 4663 | // Musl's headers are ABI-agnostic and so they all have the "musl" ABI name. |
| 4664 | const abi_name = if (target.abi.isMusl()) "musl" else @tagName(target.abi); |
| 4665 | const s = std.fs.path.sep_str; |
| 4666 | const arch_include_dir = try std.fmt.allocPrint( |
| 4667 | arena, |
| 4668 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", |
| 4669 | .{ zig_lib_dir, arch_name, os_name, abi_name }, |
| 4670 | ); |
| 4671 | const generic_include_dir = try std.fmt.allocPrint( |
| 4672 | arena, |
| 4673 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}", |
| 4674 | .{ zig_lib_dir, generic_name }, |
| 4675 | ); |
| 4676 | const generic_arch_name = target_util.osArchName(target); |
| 4677 | const arch_os_include_dir = try std.fmt.allocPrint( |
| 4678 | arena, |
| 4679 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any", |
| 4680 | .{ zig_lib_dir, generic_arch_name, os_name }, |
| 4681 | ); |
| 4682 | const generic_os_include_dir = try std.fmt.allocPrint( |
| 4683 | arena, |
| 4684 | "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "any-{s}-any", |
| 4685 | .{ zig_lib_dir, os_name }, |
| 4686 | ); |
| 4687 | |
| 4688 | const list = try arena.alloc([]const u8, 4); |
| 4689 | list[0] = arch_include_dir; |
| 4690 | list[1] = generic_include_dir; |
| 4691 | list[2] = arch_os_include_dir; |
| 4692 | list[3] = generic_os_include_dir; |
| 4693 | |
| 4694 | return LibCDirs{ |
| 4695 | .libc_include_dir_list = list, |
| 4696 | .libc_installation = null, |
| 4697 | }; |
| 4698 | }, |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4680 | 4702 | pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |
| 4681 | 4703 | if (comp.wantBuildGLibCFromSource() or |
| 4682 | 4704 | comp.wantBuildMuslFromSource() or |