| ... | @@ -22,7 +22,7 @@ sys_include_dir: ?[]const u8 = null, | ... | @@ -22,7 +22,7 @@ sys_include_dir: ?[]const u8 = null, |
| 22 | crt_dir: ?[]const u8 = null, | 22 | crt_dir: ?[]const u8 = null, |
| 23 | msvc_lib_dir: ?[]const u8 = null, | 23 | msvc_lib_dir: ?[]const u8 = null, |
| 24 | kernel32_lib_dir: ?[]const u8 = null, | 24 | kernel32_lib_dir: ?[]const u8 = null, |
| 25 | gcc_dir: ?[]const u8 = null, | 25 | cc_dir: ?[]const u8 = null, |
| 26 | | 26 | |
| 27 | pub const FindError = error{ | 27 | pub const FindError = error{ |
| 28 | OutOfMemory, | 28 | OutOfMemory, |
| ... | @@ -67,7 +67,10 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const | ... | @@ -67,7 +67,10 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 67 | const name = line_it.first(); | 67 | const name = line_it.first(); |
| 68 | const value = line_it.rest(); | 68 | const value = line_it.rest(); |
| 69 | inline for (field_names, 0..) |field_name, i| { | 69 | inline for (field_names, 0..) |field_name, i| { |
| 70 | if (std.mem.eql(u8, name, field_name)) { | 70 | // Allow `gcc_dir` as an alias for `cc_dir` for compatibility with older files. |
| | 71 | if (std.mem.eql(u8, name, field_name) or |
| | 72 | (std.mem.eql(u8, name, "gcc_dir") and std.mem.eql(u8, field_name, "cc_dir"))) |
| | 73 | { |
| 71 | found_keys[i].found = true; | 74 | found_keys[i].found = true; |
| 72 | if (value.len == 0) { | 75 | if (value.len == 0) { |
| 73 | @field(self, field_name) = null; | 76 | @field(self, field_name) = null; |
| ... | @@ -95,6 +98,12 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const | ... | @@ -95,6 +98,12 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 95 | } | 98 | } |
| 96 | | 99 | |
| 97 | const os_tag = target.os.tag; | 100 | const os_tag = target.os.tag; |
| | 101 | |
| | 102 | if (self.cc_dir == null and (os_tag == .haiku or os_tag == .serenity or os_tag == .linux)) { |
| | 103 | log.err("cc_dir may not be empty for {s}", .{@tagName(os_tag)}); |
| | 104 | return error.ParseError; |
| | 105 | } |
| | 106 | |
| 98 | if (self.crt_dir == null and !target.os.tag.isDarwin()) { | 107 | if (self.crt_dir == null and !target.os.tag.isDarwin()) { |
| 99 | log.err("crt_dir may not be empty for {s}", .{@tagName(os_tag)}); | 108 | log.err("crt_dir may not be empty for {s}", .{@tagName(os_tag)}); |
| 100 | return error.ParseError; | 109 | return error.ParseError; |
| ... | @@ -115,11 +124,6 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const | ... | @@ -115,11 +124,6 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 115 | return error.ParseError; | 124 | return error.ParseError; |
| 116 | } | 125 | } |
| 117 | | 126 | |
| 118 | if (self.gcc_dir == null and (os_tag == .haiku or os_tag == .serenity)) { | | |
| 119 | log.err("gcc_dir may not be empty for {s}", .{@tagName(os_tag)}); | | |
| 120 | return error.ParseError; | | |
| 121 | } | | |
| 122 | | | |
| 123 | return self; | 127 | return self; |
| 124 | } | 128 | } |
| 125 | | 129 | |
| ... | @@ -130,21 +134,26 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void { | ... | @@ -130,21 +134,26 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void { |
| 130 | const crt_dir = self.crt_dir orelse ""; | 134 | const crt_dir = self.crt_dir orelse ""; |
| 131 | const msvc_lib_dir = self.msvc_lib_dir orelse ""; | 135 | const msvc_lib_dir = self.msvc_lib_dir orelse ""; |
| 132 | const kernel32_lib_dir = self.kernel32_lib_dir orelse ""; | 136 | const kernel32_lib_dir = self.kernel32_lib_dir orelse ""; |
| 133 | const gcc_dir = self.gcc_dir orelse ""; | 137 | const cc_dir = self.cc_dir orelse ""; |
| 134 | | 138 | |
| 135 | try out.print( | 139 | try out.print( |
| 136 | \\# The directory that contains `stdlib.h`. | 140 | \\# The directory that contains `stdlib.h`. |
| 137 | \\# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null` | 141 | \\# On POSIX, can be found with: `cc -E -Wp,-v -xc /dev/null` |
| 138 | \\include_dir={s} | 142 | \\include_dir={s} |
| 139 | \\ | 143 | \\ |
| 140 | \\# The system-specific include directory. May be the same as `include_dir`. | 144 | \\# The system-specific include directory. May be the same as `include_dir`. |
| 141 | \\# On Windows it's the directory that includes `vcruntime.h`. | 145 | \\# On Windows, it's the directory that includes `vcruntime.h`. |
| 142 | \\# On POSIX it's the directory that includes `sys/errno.h`. | 146 | \\# On POSIX, it's the directory that includes `sys/errno.h`. |
| 143 | \\sys_include_dir={s} | 147 | \\sys_include_dir={s} |
| 144 | \\ | 148 | \\ |
| | 149 | \\# The directory that contains `crtbegin.o` and `crtend.o`. May be the same as `crt_dir`. |
| | 150 | \\# On POSIX, can be found with `cc -print-file-name=crtbegin.o`. |
| | 151 | \\# Only needed when targeting Haiku, Linux, or SerenityOS. |
| | 152 | \\cc_dir={s} |
| | 153 | \\ |
| 145 | \\# The directory that contains `crt1.o` or `crt2.o`. | 154 | \\# The directory that contains `crt1.o` or `crt2.o`. |
| 146 | \\# On POSIX, can be found with `cc -print-file-name=crt1.o`. | 155 | \\# On POSIX, can be found with `cc -print-file-name=crt1.o`. |
| 147 | \\# Not needed when targeting MacOS. | 156 | \\# Not needed when targeting macOS. |
| 148 | \\crt_dir={s} | 157 | \\crt_dir={s} |
| 149 | \\ | 158 | \\ |
| 150 | \\# The directory that contains `vcruntime.lib`. | 159 | \\# The directory that contains `vcruntime.lib`. |
| ... | @@ -155,17 +164,13 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void { | ... | @@ -155,17 +164,13 @@ pub fn render(self: LibCInstallation, out: *std.Io.Writer) !void { |
| 155 | \\# Only needed when targeting MSVC on Windows. | 164 | \\# Only needed when targeting MSVC on Windows. |
| 156 | \\kernel32_lib_dir={s} | 165 | \\kernel32_lib_dir={s} |
| 157 | \\ | 166 | \\ |
| 158 | \\# The directory that contains `crtbeginS.o` and `crtendS.o` | | |
| 159 | \\# Only needed when targeting Haiku. | | |
| 160 | \\gcc_dir={s} | | |
| 161 | \\ | | |
| 162 | , .{ | 167 | , .{ |
| 163 | include_dir, | 168 | include_dir, |
| 164 | sys_include_dir, | 169 | sys_include_dir, |
| 165 | crt_dir, | 170 | crt_dir, |
| 166 | msvc_lib_dir, | 171 | msvc_lib_dir, |
| 167 | kernel32_lib_dir, | 172 | kernel32_lib_dir, |
| 168 | gcc_dir, | 173 | cc_dir, |
| 169 | }); | 174 | }); |
| 170 | } | 175 | } |
| 171 | | 176 | |
| ... | @@ -467,7 +472,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args: | ... | @@ -467,7 +472,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args: |
| 467 | } | 472 | } |
| 468 | | 473 | |
| 469 | fn findNativeGccDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void { | 474 | fn findNativeGccDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void { |
| 470 | self.gcc_dir = try ccPrintFileName(gpa, io, .{ | 475 | self.cc_dir = try ccPrintFileName(gpa, io, .{ |
| 471 | .environ_map = args.environ_map, | 476 | .environ_map = args.environ_map, |
| 472 | .search_basename = "crtbeginS.o", | 477 | .search_basename = "crtbeginS.o", |
| 473 | .want_dirname = .only_dir, | 478 | .want_dirname = .only_dir, |
| ... | @@ -1002,7 +1007,7 @@ pub fn resolveCrtPaths( | ... | @@ -1002,7 +1007,7 @@ pub fn resolveCrtPaths( |
| 1002 | arena: Allocator, | 1007 | arena: Allocator, |
| 1003 | crt_basenames: CrtBasenames, | 1008 | crt_basenames: CrtBasenames, |
| 1004 | target: *const std.Target, | 1009 | target: *const std.Target, |
| 1005 | ) error{ OutOfMemory, LibCInstallationMissingCrtDir }!CrtPaths { | 1010 | ) error{ OutOfMemory, LibCInstallationMissingCcDir, LibCInstallationMissingCrtDir }!CrtPaths { |
| 1006 | const crt_dir_path: Path = .{ | 1011 | const crt_dir_path: Path = .{ |
| 1007 | .root_dir = Cache.Directory.cwd(), | 1012 | .root_dir = Cache.Directory.cwd(), |
| 1008 | .sub_path = lci.crt_dir orelse return error.LibCInstallationMissingCrtDir, | 1013 | .sub_path = lci.crt_dir orelse return error.LibCInstallationMissingCrtDir, |
| ... | @@ -1030,15 +1035,15 @@ pub fn resolveCrtPaths( | ... | @@ -1030,15 +1035,15 @@ pub fn resolveCrtPaths( |
| 1030 | }; | 1035 | }; |
| 1031 | }, | 1036 | }, |
| 1032 | .haiku, .serenity, .linux => { | 1037 | .haiku, .serenity, .linux => { |
| 1033 | const gcc_dir_path: Path = .{ | 1038 | const cc_dir_path: Path = .{ |
| 1034 | .root_dir = Cache.Directory.cwd(), | 1039 | .root_dir = Cache.Directory.cwd(), |
| 1035 | .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir, | 1040 | .sub_path = lci.cc_dir orelse return error.LibCInstallationMissingCcDir, |
| 1036 | }; | 1041 | }; |
| 1037 | return .{ | 1042 | return .{ |
| 1038 | .crt0 = if (crt_basenames.crt0) |basename| try crt_dir_path.join(arena, basename) else null, | 1043 | .crt0 = if (crt_basenames.crt0) |basename| try crt_dir_path.join(arena, basename) else null, |
| 1039 | .crti = if (crt_basenames.crti) |basename| try crt_dir_path.join(arena, basename) else null, | 1044 | .crti = if (crt_basenames.crti) |basename| try crt_dir_path.join(arena, basename) else null, |
| 1040 | .crtbegin = if (crt_basenames.crtbegin) |basename| try gcc_dir_path.join(arena, basename) else null, | 1045 | .crtbegin = if (crt_basenames.crtbegin) |basename| try cc_dir_path.join(arena, basename) else null, |
| 1041 | .crtend = if (crt_basenames.crtend) |basename| try gcc_dir_path.join(arena, basename) else null, | 1046 | .crtend = if (crt_basenames.crtend) |basename| try cc_dir_path.join(arena, basename) else null, |
| 1042 | .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null, | 1047 | .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null, |
| 1043 | }; | 1048 | }; |
| 1044 | }, | 1049 | }, |