From 0be97b5ae3d32ca9cd7fbb68d5972538b48d8c76 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 16 Dec 2023 01:49:57 -0700 Subject: [PATCH] fix population of builtin.zig not making the parent dir --- src/Builtin.zig | 2 +- src/Compilation.zig | 9 ++++++++- src/Package.zig | 10 ++++++++++ src/Package/Module.zig | 2 +- src/codegen/llvm.zig | 12 ++++++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Builtin.zig b/src/Builtin.zig index 4c8038019c..f80f466302 100644 --- a/src/Builtin.zig +++ b/src/Builtin.zig @@ -276,7 +276,7 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void { } fn writeFile(file: *File, mod: *Module) !void { - var af = try mod.root.atomicFile(mod.root_src_path, .{}); + var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true }); defer af.deinit(); try af.file.writeAll(file.source); try af.finish(); diff --git a/src/Compilation.zig b/src/Compilation.zig index fb6e5a44b0..20e2d1ce53 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1119,6 +1119,11 @@ fn addModuleTableToCacheHash( var i: usize = 0; while (i < seen_table.count()) : (i += 1) { const mod = seen_table.keys()[i]; + if (mod.isBuiltin()) { + // Skip builtin.zig; it is useless as an input, and we don't want to + // have to write it before checking for a cache hit. + continue; + } cache_helpers.addResolvedTarget(hash, mod.resolved_target); hash.add(mod.optimize_mode); @@ -1133,6 +1138,8 @@ fn addModuleTableToCacheHash( hash.add(mod.red_zone); hash.add(mod.sanitize_c); hash.add(mod.sanitize_thread); + hash.add(mod.unwind_tables); + hash.add(mod.structured_cfg); switch (hash_type) { .path_bytes => { @@ -2371,7 +2378,6 @@ pub const link_hash_implementation_version = 10; fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void { const gpa = comp.gpa; - const target = comp.getTarget(); var arena_allocator = std.heap.ArenaAllocator.init(gpa); defer arena_allocator.deinit(); @@ -2432,6 +2438,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes man.hash.add(comp.include_compiler_rt); if (comp.config.link_libc) { man.hash.add(comp.libc_installation != null); + const target = comp.root_mod.resolved_target.result; if (comp.libc_installation) |libc_installation| { man.hash.addOptionalBytes(libc_installation.crt_dir); if (target.abi == .msvc) { diff --git a/src/Package.zig b/src/Package.zig index ab06ca9852..373b46e495 100644 --- a/src/Package.zig +++ b/src/Package.zig @@ -108,6 +108,16 @@ pub const Path = struct { return p.root_dir.handle.access(joined_path, flags); } + pub fn makePath(p: Path, sub_path: []const u8) !void { + var buf: [fs.MAX_PATH_BYTES]u8 = undefined; + const joined_path = if (p.sub_path.len == 0) sub_path else p: { + break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ + p.sub_path, sub_path, + }) catch return error.NameTooLong; + }; + return p.root_dir.handle.makePath(joined_path); + } + pub fn format( self: Path, comptime fmt_string: []const u8, diff --git a/src/Package/Module.zig b/src/Package/Module.zig index 4ce0f0a856..2d54c9296c 100644 --- a/src/Package/Module.zig +++ b/src/Package/Module.zig @@ -40,7 +40,7 @@ builtin_file: ?*File, pub const Deps = std.StringArrayHashMapUnmanaged(*Module); pub fn isBuiltin(m: Module) bool { - return m.file != null; + return m.builtin_file != null; } pub const Tree = struct { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 3a53bddcb8..91c4faffcc 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -898,14 +898,22 @@ pub const Object = struct { // 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? + // TODO: This is totally wrong. In dwarf, paths are encoded as relative to + // a particular directory, and then the directory path is specified elsewhere. + // In the compiler frontend we have it stored correctly in this + // way already, but here we throw all that sweet information + // into the garbage can by converting into absolute paths. What + // a terrible tragedy. const compile_unit_dir_z = blk: { if (comp.module) |zcu| m: { const d = try zcu.root_mod.root.joinStringZ(arena, ""); if (d.len == 0) break :m; if (std.fs.path.isAbsolute(d)) break :blk d; - break :blk std.fs.realpathAlloc(arena, d) catch d; + const realpath = std.fs.realpathAlloc(arena, d) catch break :blk d; + break :blk try arena.dupeZ(u8, realpath); } - break :blk try std.process.getCwdAlloc(arena); + const cwd = try std.process.getCwdAlloc(arena); + break :blk try arena.dupeZ(u8, cwd); }; builder.llvm.di_compile_unit = builder.llvm.di_builder.?.createCompileUnit(