authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-02 22:08:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-03 09:52:15-07:00
log4923e64199d8a16f7e0f376a1839daa70a9dfdf2
treee3a58e5eda43108eaa383f1151ee5dbf40b8ff09
parent4089f96defa7dae169e2b6cdba5e545293e57cb8

Compilation: detect sysroot from libc installation


1 files changed, 11 insertions(+), 8 deletions(-)

src/Compilation.zig+11-8
......@@ -853,14 +853,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
853853 break :blk false;
854854 };
855855
856 const sysroot = blk: {
857 if (options.sysroot) |sysroot| {
858 break :blk sysroot;
859 } else {
860 break :blk null;
861 }
862 };
863
864856 const lto = blk: {
865857 if (options.want_lto) |explicit| {
866858 if (!use_lld and !options.target.isDarwin())
......@@ -946,6 +938,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
946938 options.libc_installation,
947939 );
948940
941 const sysroot = options.sysroot orelse libc_dirs.sysroot;
942
949943 const must_pie = target_util.requiresPIE(options.target);
950944 const pie: bool = if (options.want_pie) |explicit| pie: {
951945 if (!explicit and must_pie) {
......@@ -4828,6 +4822,7 @@ const LibCDirs = struct {
48284822 libc_include_dir_list: []const []const u8,
48294823 libc_installation: ?*const LibCInstallation,
48304824 libc_framework_dir_list: []const []const u8,
4825 sysroot: ?[]const u8,
48314826};
48324827
48334828fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs {
......@@ -4859,6 +4854,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8,
48594854 .libc_include_dir_list = list,
48604855 .libc_installation = null,
48614856 .libc_framework_dir_list = &.{},
4857 .sysroot = null,
48624858 };
48634859}
48644860
......@@ -4875,6 +4871,7 @@ fn detectLibCIncludeDirs(
48754871 .libc_include_dir_list = &[0][]u8{},
48764872 .libc_installation = null,
48774873 .libc_framework_dir_list = &.{},
4874 .sysroot = null,
48784875 };
48794876 }
48804877
......@@ -4931,6 +4928,7 @@ fn detectLibCIncludeDirs(
49314928 .libc_include_dir_list = &[0][]u8{},
49324929 .libc_installation = null,
49334930 .libc_framework_dir_list = &.{},
4931 .sysroot = null,
49344932 };
49354933}
49364934
......@@ -4964,16 +4962,20 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const
49644962 list.appendAssumeCapacity(config_dir);
49654963 }
49664964
4965 var sysroot: ?[]const u8 = null;
4966
49674967 if (target.isDarwin()) d: {
49684968 const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
49694969 const down2 = std.fs.path.dirname(down1) orelse break :d;
49704970 try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
4971 sysroot = down2;
49714972 }
49724973
49734974 return LibCDirs{
49744975 .libc_include_dir_list = list.items,
49754976 .libc_installation = lci,
49764977 .libc_framework_dir_list = framework_list.items,
4978 .sysroot = sysroot,
49774979 };
49784980}
49794981
......@@ -5034,6 +5036,7 @@ fn detectLibCFromBuilding(
50345036 .libc_include_dir_list = list,
50355037 .libc_installation = null,
50365038 .libc_framework_dir_list = &.{},
5039 .sysroot = null,
50375040 };
50385041}
50395042