aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-06 21:29:08 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-10-08 16:54:31 -0700
commitf708c5fafc5087a2518e0dc7acf986b59673dddd (patch)
tree0520ae635c4a0b643ba9b33cb6fcdf1ff08e115e /src/link
parent1c0d6f9c0020188326560e058baf36b8034d76e5 (diff)
downloadzig-f708c5fafc5087a2518e0dc7acf986b59673dddd.tar.gz
zig-f708c5fafc5087a2518e0dc7acf986b59673dddd.zip
CLI: finish updating module API usage
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731. Now the compiler compiles again. Wire up dependency tree fetching code in the CLI for `zig build`. Everything is hooked up except for `createDependenciesModule` is not yet implemented.
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Dwarf.zig18
-rw-r--r--src/link/Elf.zig6
-rw-r--r--src/link/Plan9.zig9
3 files changed, 22 insertions, 11 deletions
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig
index cbf5f350e8..931dbacdb9 100644
--- a/src/link/Dwarf.zig
+++ b/src/link/Dwarf.zig
@@ -1880,7 +1880,7 @@ pub fn writeDbgInfoHeader(self: *Dwarf, module: *Module, low_pc: u64, high_pc: u
},
}
// Write the form for the compile unit, which must match the abbrev table above.
- const name_strp = try self.strtab.insert(self.allocator, module.root_pkg.root_src_path);
+ const name_strp = try self.strtab.insert(self.allocator, module.root_mod.root_src_path);
var compile_unit_dir_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const compile_unit_dir = resolveCompilationDir(module, &compile_unit_dir_buffer);
const comp_dir_strp = try self.strtab.insert(self.allocator, compile_unit_dir);
@@ -1940,9 +1940,17 @@ fn resolveCompilationDir(module: *Module, buffer: *[std.fs.MAX_PATH_BYTES]u8) []
// be very location dependent.
// TODO: the only concern I have with this is WASI as either host or target, should
// we leave the paths as relative then?
- const comp_dir_path = module.root_pkg.root_src_directory.path orelse ".";
- if (std.fs.path.isAbsolute(comp_dir_path)) return comp_dir_path;
- return std.os.realpath(comp_dir_path, buffer) catch comp_dir_path; // If realpath fails, fallback to whatever comp_dir_path was
+ const root_dir_path = module.root_mod.root.root_dir.path orelse ".";
+ const sub_path = module.root_mod.root.sub_path;
+ const realpath = if (std.fs.path.isAbsolute(root_dir_path)) r: {
+ @memcpy(buffer[0..root_dir_path.len], root_dir_path);
+ break :r root_dir_path;
+ } else std.fs.realpath(root_dir_path, buffer) catch return root_dir_path;
+ const len = realpath.len + 1 + sub_path.len;
+ if (buffer.len < len) return root_dir_path;
+ buffer[realpath.len] = '/';
+ @memcpy(buffer[realpath.len + 1 ..][0..sub_path.len], sub_path);
+ return buffer[0..len];
}
fn writeAddrAssumeCapacity(self: *Dwarf, buf: *std.ArrayList(u8), addr: u64) void {
@@ -2664,7 +2672,7 @@ fn genIncludeDirsAndFileNames(self: *Dwarf, arena: Allocator) !struct {
for (self.di_files.keys()) |dif| {
const dir_path = d: {
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
- const dir_path = dif.pkg.root_src_directory.path orelse ".";
+ const dir_path = try dif.mod.root.joinString(arena, dif.mod.root.sub_path);
const abs_dir_path = if (std.fs.path.isAbsolute(dir_path))
dir_path
else
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 24da99aab2..f75047424a 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -929,15 +929,15 @@ pub fn populateMissingMetadata(self: *Elf) !void {
if (self.base.options.module) |module| {
if (self.zig_module_index == null and !self.base.options.use_llvm) {
- const index = @as(File.Index, @intCast(try self.files.addOne(gpa)));
+ const index: File.Index = @intCast(try self.files.addOne(gpa));
self.files.set(index, .{ .zig_module = .{
.index = index,
- .path = module.main_pkg.root_src_path,
+ .path = module.main_mod.root_src_path,
} });
self.zig_module_index = index;
const zig_module = self.file(index).?.zig_module;
- const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_pkg.root_src_path));
+ const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_mod.root_src_path));
const symbol_index = try self.addSymbol();
try zig_module.local_symbols.append(gpa, symbol_index);
const symbol_ptr = self.symbol(symbol_index);
diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig
index b519fdda00..3dcef859ae 100644
--- a/src/link/Plan9.zig
+++ b/src/link/Plan9.zig
@@ -352,9 +352,12 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
// getting the full file path
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
- const dir = file.pkg.root_src_directory.path orelse try std.os.getcwd(&buf);
- const sub_path = try std.fs.path.join(arena, &.{ dir, file.sub_file_path });
- try self.addPathComponents(sub_path, &a);
+ const full_path = try std.fs.path.join(arena, &.{
+ file.mod.root.root_dir.path orelse try std.os.getcwd(&buf),
+ file.mod.root.sub_path,
+ file.sub_file_path,
+ });
+ try self.addPathComponents(full_path, &a);
// null terminate
try a.append(0);