authorgravatar for 3811822-hoanga@users.noreply.gitlab.comAl Hoang <3811822-hoanga@users.noreply.gitlab.com> 2021-05-22 01:06:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-24 10:39:02-07:00
log5280ea5d22687bf4939dd1807c8a711937239307
tree4e48d441a7343b49155f0d4b632e7271075a018d
parentc4a4330cc7a783ad188daedd05159b725128f69c

update compilation and elf link for haiku case

* for some reason part of the linkable bits for the crt libraries are split in different locations for haiku. this changeset accomodates this situation (crtbegin_dir lookup)

2 files changed, 36 insertions(+), 1 deletions(-)

src/Compilation.zig+7
......@@ -3286,6 +3286,13 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []cons
32863286 return full_path;
32873287}
32883288
3289pub fn get_libc_crtbegin_file(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 {
3290 const lci = comp.bin_file.options.libc_installation orelse return error.LibCInstallationNotAvailable;
3291 const crtbegin_dir_path = lci.crtbegin_dir orelse return error.LibCInstallationMissingCRTDir;
3292 const full_path = try std.fs.path.join(arena, &[_][]const u8{ crtbegin_dir_path, basename });
3293 return full_path;
3294}
3295
32893296fn addBuildingGLibCJobs(comp: *Compilation) !void {
32903297 try comp.work_queue.write(&[_]Job{
32913298 .{ .glibc_crt_file = .crti_o },
src/libc_installation.zig+29-1
......@@ -21,6 +21,7 @@ pub const LibCInstallation = struct {
2121 crt_dir: ?[]const u8 = null,
2222 msvc_lib_dir: ?[]const u8 = null,
2323 kernel32_lib_dir: ?[]const u8 = null,
24 crtbegin_dir: ?[]const u8 = null,
2425
2526 pub const FindError = error{
2627 OutOfMemory,
......@@ -113,6 +114,10 @@ pub const LibCInstallation = struct {
113114 });
114115 return error.ParseError;
115116 }
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 }
116121
117122 return self;
118123 }
......@@ -124,6 +129,7 @@ pub const LibCInstallation = struct {
124129 const crt_dir = self.crt_dir orelse "";
125130 const msvc_lib_dir = self.msvc_lib_dir orelse "";
126131 const kernel32_lib_dir = self.kernel32_lib_dir orelse "";
132 const crtbegin_dir = self.crtbegin_dir orelse "";
127133
128134 try out.print(
129135 \\# The directory that contains `stdlib.h`.
......@@ -148,12 +154,17 @@ pub const LibCInstallation = struct {
148154 \\# Only needed when targeting MSVC on Windows.
149155 \\kernel32_lib_dir={s}
150156 \\
157 \\# The directory that contains `crtbeginS.o` and `crtendS.o`
158 \\# Only needed when targeting Haiku.
159 \\crtbegin_dir={s}
160 \\
151161 , .{
152162 include_dir,
153163 sys_include_dir,
154164 crt_dir,
155165 msvc_lib_dir,
156166 kernel32_lib_dir,
167 crtbegin_dir,
157168 });
158169 }
159170
......@@ -188,6 +199,15 @@ pub const LibCInstallation = struct {
188199 .NotFound => return error.WindowsSdkNotFound,
189200 .PathTooLong => return error.WindowsSdkNotFound,
190201 }
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 };
191211 } else {
192212 try blk: {
193213 var batch = Batch(FindError!void, 2, .auto_async).init();
......@@ -196,7 +216,6 @@ pub const LibCInstallation = struct {
196216 switch (Target.current.os.tag) {
197217 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/usr/lib"),
198218 .linux => batch.add(&async self.findNativeCrtDirPosix(args)),
199 .haiku => self.crt_dir = try std.mem.dupeZ(args.allocator, u8, "/system/develop/lib"),
200219 else => {},
201220 }
202221 break :blk batch.wait();
......@@ -422,6 +441,15 @@ pub const LibCInstallation = struct {
422441 });
423442 }
424443
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
425453 fn findNativeKernel32LibDir(
426454 self: *LibCInstallation,
427455 args: FindNativeOptions,