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 {...@@ -853,14 +853,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
853 break :blk false;853 break :blk false;
854 };854 };
855855
856 const sysroot = blk: {
857 if (options.sysroot) |sysroot| {
858 break :blk sysroot;
859 } else {
860 break :blk null;
861 }
862 };
863
864 const lto = blk: {856 const lto = blk: {
865 if (options.want_lto) |explicit| {857 if (options.want_lto) |explicit| {
866 if (!use_lld and !options.target.isDarwin())858 if (!use_lld and !options.target.isDarwin())
...@@ -946,6 +938,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -946,6 +938,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
946 options.libc_installation,938 options.libc_installation,
947 );939 );
948940
941 const sysroot = options.sysroot orelse libc_dirs.sysroot;
942
949 const must_pie = target_util.requiresPIE(options.target);943 const must_pie = target_util.requiresPIE(options.target);
950 const pie: bool = if (options.want_pie) |explicit| pie: {944 const pie: bool = if (options.want_pie) |explicit| pie: {
951 if (!explicit and must_pie) {945 if (!explicit and must_pie) {
...@@ -4828,6 +4822,7 @@ const LibCDirs = struct {...@@ -4828,6 +4822,7 @@ const LibCDirs = struct {
4828 libc_include_dir_list: []const []const u8,4822 libc_include_dir_list: []const []const u8,
4829 libc_installation: ?*const LibCInstallation,4823 libc_installation: ?*const LibCInstallation,
4830 libc_framework_dir_list: []const []const u8,4824 libc_framework_dir_list: []const []const u8,
4825 sysroot: ?[]const u8,
4831};4826};
48324827
4833fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs {4828fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs {
...@@ -4859,6 +4854,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8,...@@ -4859,6 +4854,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8,
4859 .libc_include_dir_list = list,4854 .libc_include_dir_list = list,
4860 .libc_installation = null,4855 .libc_installation = null,
4861 .libc_framework_dir_list = &.{},4856 .libc_framework_dir_list = &.{},
4857 .sysroot = null,
4862 };4858 };
4863}4859}
48644860
...@@ -4875,6 +4871,7 @@ fn detectLibCIncludeDirs(...@@ -4875,6 +4871,7 @@ fn detectLibCIncludeDirs(
4875 .libc_include_dir_list = &[0][]u8{},4871 .libc_include_dir_list = &[0][]u8{},
4876 .libc_installation = null,4872 .libc_installation = null,
4877 .libc_framework_dir_list = &.{},4873 .libc_framework_dir_list = &.{},
4874 .sysroot = null,
4878 };4875 };
4879 }4876 }
48804877
...@@ -4931,6 +4928,7 @@ fn detectLibCIncludeDirs(...@@ -4931,6 +4928,7 @@ fn detectLibCIncludeDirs(
4931 .libc_include_dir_list = &[0][]u8{},4928 .libc_include_dir_list = &[0][]u8{},
4932 .libc_installation = null,4929 .libc_installation = null,
4933 .libc_framework_dir_list = &.{},4930 .libc_framework_dir_list = &.{},
4931 .sysroot = null,
4934 };4932 };
4935}4933}
49364934
...@@ -4964,16 +4962,20 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const...@@ -4964,16 +4962,20 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const
4964 list.appendAssumeCapacity(config_dir);4962 list.appendAssumeCapacity(config_dir);
4965 }4963 }
49664964
4965 var sysroot: ?[]const u8 = null;
4966
4967 if (target.isDarwin()) d: {4967 if (target.isDarwin()) d: {
4968 const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;4968 const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
4969 const down2 = std.fs.path.dirname(down1) orelse break :d;4969 const down2 = std.fs.path.dirname(down1) orelse break :d;
4970 try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));4970 try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
4971 sysroot = down2;
4971 }4972 }
49724973
4973 return LibCDirs{4974 return LibCDirs{
4974 .libc_include_dir_list = list.items,4975 .libc_include_dir_list = list.items,
4975 .libc_installation = lci,4976 .libc_installation = lci,
4976 .libc_framework_dir_list = framework_list.items,4977 .libc_framework_dir_list = framework_list.items,
4978 .sysroot = sysroot,
4977 };4979 };
4978}4980}
49794981
...@@ -5034,6 +5036,7 @@ fn detectLibCFromBuilding(...@@ -5034,6 +5036,7 @@ fn detectLibCFromBuilding(
5034 .libc_include_dir_list = list,5036 .libc_include_dir_list = list,
5035 .libc_installation = null,5037 .libc_installation = null,
5036 .libc_framework_dir_list = &.{},5038 .libc_framework_dir_list = &.{},
5039 .sysroot = null,
5037 };5040 };
5038}5041}
50395042