| ... | @@ -21,6 +21,7 @@ pub const LibCInstallation = struct { | ... | @@ -21,6 +21,7 @@ pub const LibCInstallation = struct { |
| 21 | crt_dir: ?[]const u8 = null, | 21 | crt_dir: ?[]const u8 = null, |
| 22 | msvc_lib_dir: ?[]const u8 = null, | 22 | msvc_lib_dir: ?[]const u8 = null, |
| 23 | kernel32_lib_dir: ?[]const u8 = null, | 23 | kernel32_lib_dir: ?[]const u8 = null, |
| | 24 | crtbegin_dir: ?[]const u8 = null, |
| 24 | | 25 | |
| 25 | pub const FindError = error{ | 26 | pub const FindError = error{ |
| 26 | OutOfMemory, | 27 | OutOfMemory, |
| ... | @@ -113,6 +114,10 @@ pub const LibCInstallation = struct { | ... | @@ -113,6 +114,10 @@ pub const LibCInstallation = struct { |
| 113 | }); | 114 | }); |
| 114 | return error.ParseError; | 115 | return error.ParseError; |
| 115 | } | 116 | } |
| | 117 | if (self.crtbegin_dir == null and is_haiku) { |
| | 118 | log.err("crtbegin_dir may not be empty for {s}\n", .{@tagName(Target.current.os.tag)}); |
| | 119 | return error.ParseError; |
| | 120 | } |
| 116 | | 121 | |
| 117 | return self; | 122 | return self; |
| 118 | } | 123 | } |
| ... | @@ -124,6 +129,7 @@ pub const LibCInstallation = struct { | ... | @@ -124,6 +129,7 @@ pub const LibCInstallation = struct { |
| 124 | const crt_dir = self.crt_dir orelse ""; | 129 | const crt_dir = self.crt_dir orelse ""; |
| 125 | const msvc_lib_dir = self.msvc_lib_dir orelse ""; | 130 | const msvc_lib_dir = self.msvc_lib_dir orelse ""; |
| 126 | const kernel32_lib_dir = self.kernel32_lib_dir orelse ""; | 131 | const kernel32_lib_dir = self.kernel32_lib_dir orelse ""; |
| | 132 | const crtbegin_dir = self.crtbegin_dir orelse ""; |
| 127 | | 133 | |
| 128 | try out.print( | 134 | try out.print( |
| 129 | \\# The directory that contains `stdlib.h`. | 135 | \\# The directory that contains `stdlib.h`. |
| ... | @@ -148,12 +154,17 @@ pub const LibCInstallation = struct { | ... | @@ -148,12 +154,17 @@ pub const LibCInstallation = struct { |
| 148 | \\# Only needed when targeting MSVC on Windows. | 154 | \\# Only needed when targeting MSVC on Windows. |
| 149 | \\kernel32_lib_dir={s} | 155 | \\kernel32_lib_dir={s} |
| 150 | \\ | 156 | \\ |
| | 157 | \\# The directory that contains `crtbeginS.o` and `crtendS.o` |
| | 158 | \\# Only needed when targeting Haiku. |
| | 159 | \\crtbegin_dir={s} |
| | 160 | \\ |
| 151 | , .{ | 161 | , .{ |
| 152 | include_dir, | 162 | include_dir, |
| 153 | sys_include_dir, | 163 | sys_include_dir, |
| 154 | crt_dir, | 164 | crt_dir, |
| 155 | msvc_lib_dir, | 165 | msvc_lib_dir, |
| 156 | kernel32_lib_dir, | 166 | kernel32_lib_dir, |
| | 167 | crtbegin_dir, |
| 157 | }); | 168 | }); |
| 158 | } | 169 | } |
| 159 | | 170 | |
| ... | @@ -188,6 +199,15 @@ pub const LibCInstallation = struct { | ... | @@ -188,6 +199,15 @@ pub const LibCInstallation = struct { |
| 188 | .NotFound => return error.WindowsSdkNotFound, | 199 | .NotFound => return error.WindowsSdkNotFound, |
| 189 | .PathTooLong => return error.WindowsSdkNotFound, | 200 | .PathTooLong => return error.WindowsSdkNotFound, |
| 190 | } | 201 | } |
| | 202 | } else if (is_haiku) { |
| | 203 | try blk: { |
| | 204 | var batch = Batch(FindError!void, 2, .auto_async).init(); |
| | 205 | errdefer batch.wait() catch {}; |
| | 206 | batch.add(&async self.findNativeIncludeDirPosix(args)); |
| | 207 | batch.add(&async self.findNativeCrtBeginDirHaiku(args)); |
| | 208 | self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib"); |
| | 209 | break :blk batch.wait(); |
| | 210 | }; |
| 191 | } else { | 211 | } else { |
| 192 | try blk: { | 212 | try blk: { |
| 193 | var batch = Batch(FindError!void, 2, .auto_async).init(); | 213 | var batch = Batch(FindError!void, 2, .auto_async).init(); |
| ... | @@ -196,7 +216,6 @@ pub const LibCInstallation = struct { | ... | @@ -196,7 +216,6 @@ pub const LibCInstallation = struct { |
| 196 | switch (Target.current.os.tag) { | 216 | switch (Target.current.os.tag) { |
| 197 | .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"), | 217 | .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"), |
| 198 | .linux => batch.add(&async self.findNativeCrtDirPosix(args)), | 218 | .linux => batch.add(&async self.findNativeCrtDirPosix(args)), |
| 199 | .haiku => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib"), | | |
| 200 | else => {}, | 219 | else => {}, |
| 201 | } | 220 | } |
| 202 | break :blk batch.wait(); | 221 | break :blk batch.wait(); |
| ... | @@ -422,6 +441,15 @@ pub const LibCInstallation = struct { | ... | @@ -422,6 +441,15 @@ pub const LibCInstallation = struct { |
| 422 | }); | 441 | }); |
| 423 | } | 442 | } |
| 424 | | 443 | |
| | 444 | fn findNativeCrtBeginDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindError!void { |
| | 445 | self.crtbegin_dir = try ccPrintFileName(.{ |
| | 446 | .allocator = args.allocator, |
| | 447 | .search_basename = "crtbeginS.o", |
| | 448 | .want_dirname = .only_dir, |
| | 449 | .verbose = args.verbose, |
| | 450 | }); |
| | 451 | } |
| | 452 | |
| 425 | fn findNativeKernel32LibDir( | 453 | fn findNativeKernel32LibDir( |
| 426 | self: *LibCInstallation, | 454 | self: *LibCInstallation, |
| 427 | args: FindNativeOptions, | 455 | args: FindNativeOptions, |