| author | |
| committer | |
| log | 5b8bee462a63538083e7b2e16f1dae7b39c8529b |
| tree | f7f86646f4c2130e57d7379f74b3b6d480c3147e |
| parent | 5a6c3aaedfef1ff242317f622252e0c7eebf0159 |
- better reporting of cache checking failure
- fix not using Path properly
- fix not using Path properly in Preprocessor code3 files changed, 51 insertions(+), 47 deletions(-)
src/Compilation.zig+2-1| ... | ... | @@ -5351,6 +5351,7 @@ fn buildMingwCrtFile(comp: *Compilation, crt_file: mingw.CrtFile, prog_node: std |
| 5351 | 5351 | |
| 5352 | 5352 | fn buildMingwImportLib(comp: *Compilation, lib_name: []const u8, is_prelink: bool, prog_node: std.Progress.Node) void { |
| 5353 | 5353 | const crt_file_path = mingw.buildImportLib(comp, lib_name, prog_node) catch |err| switch (err) { |
| 5354 | error.AlreadyReported => return, | |
| 5354 | 5355 | // TODO: This isn't actually true for self-hosted |
| 5355 | 5356 | // In the non-prelink case we will end up putting foo.lib onto the linker line and letting the linker |
| 5356 | 5357 | // use its library paths to look for libraries and report any problems. |
| ... | ... | @@ -5364,7 +5365,7 @@ fn buildMingwImportLib(comp: *Compilation, lib_name: []const u8, is_prelink: boo |
| 5364 | 5365 | // TODO Surface more error details. |
| 5365 | 5366 | else => |e| return comp.lockAndSetMiscFailure( |
| 5366 | 5367 | .windows_import_lib, |
| 5367 | "unable to generate mingw DLL import .lib file for {s}: {t}", | |
| 5368 | "generating mingw DLL import .lib file for {s} failed: {t}", | |
| 5368 | 5369 | .{ lib_name, e }, |
| 5369 | 5370 | ), |
| 5370 | 5371 | }; |
src/libs/mingw.zig+37-24| ... | ... | @@ -215,12 +215,15 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P |
| 215 | 215 | defer arena_allocator.deinit(); |
| 216 | 216 | const arena = arena_allocator.allocator(); |
| 217 | 217 | |
| 218 | const def_file_path = findDef(arena, io, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) { | |
| 219 | error.FileNotFound => return error.DefNotFound, | |
| 220 | else => |e| return e, | |
| 218 | const def_file_path: Cache.Path = .{ | |
| 219 | .root_dir = comp.dirs.zig_lib, | |
| 220 | .sub_path = findDef(arena, io, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) { | |
| 221 | error.FileNotFound => return error.DefNotFound, | |
| 222 | else => |e| return e, | |
| 223 | }, | |
| 221 | 224 | }; |
| 222 | 225 | // Only .def.in files need preprocessing |
| 223 | const def_needs_preprocessing = mem.endsWith(u8, def_file_path, ".def.in"); | |
| 226 | const def_needs_preprocessing = mem.endsWith(u8, def_file_path.sub_path, ".def.in"); | |
| 224 | 227 | |
| 225 | 228 | const target = comp.getTarget(); |
| 226 | 229 | |
| ... | ... | @@ -243,15 +246,34 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P |
| 243 | 246 | var man = cache.obtain(); |
| 244 | 247 | defer man.deinit(); |
| 245 | 248 | |
| 246 | _ = try man.addFilePath(.{ | |
| 247 | .root_dir = comp.dirs.zig_lib, | |
| 248 | .sub_path = def_file_path, | |
| 249 | }, null); | |
| 249 | _ = try man.addFilePath(def_file_path, null); | |
| 250 | 250 | |
| 251 | 251 | const final_lib_basename = try std.fmt.allocPrint(gpa, "{s}.lib", .{lib_name}); |
| 252 | 252 | errdefer gpa.free(final_lib_basename); |
| 253 | 253 | |
| 254 | if (try man.hit(prog_node)) { | |
| 254 | const is_hit = man.hit(prog_node) catch |err| switch (err) { | |
| 255 | error.CacheCheckFailed => switch (man.diagnostic) { | |
| 256 | .none => unreachable, | |
| 257 | .manifest_create, .manifest_read, .manifest_lock => |e| { | |
| 258 | comp.setMiscFailure(.windows_import_lib, "checking cache failed: {t} {t}", .{ man.diagnostic, e }); | |
| 259 | return error.AlreadyReported; | |
| 260 | }, | |
| 261 | .file_open, .file_stat, .file_read, .file_hash => |op| { | |
| 262 | const pp = man.files.keys()[op.file_index].prefixed_path; | |
| 263 | const prefix = man.cache.prefixes()[pp.prefix]; | |
| 264 | comp.setMiscFailure(.windows_import_lib, "checking cache failed: {f}{s} {t} {t}", .{ | |
| 265 | prefix, pp.sub_path, man.diagnostic, op.err, | |
| 266 | }); | |
| 267 | return error.AlreadyReported; | |
| 268 | }, | |
| 269 | }, | |
| 270 | error.OutOfMemory, error.Canceled => |e| return e, | |
| 271 | error.InvalidFormat => { | |
| 272 | comp.setMiscFailure(.windows_import_lib, "checking cache failed: invalid manifest file format", .{}); | |
| 273 | return error.AlreadyReported; | |
| 274 | }, | |
| 275 | }; | |
| 276 | if (is_hit) { | |
| 255 | 277 | const digest = man.final(); |
| 256 | 278 | const sub_path = try std.fs.path.join(gpa, &.{ "o", &digest, final_lib_basename }); |
| 257 | 279 | errdefer gpa.free(sub_path); |
| ... | ... | @@ -276,20 +298,11 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P |
| 276 | 298 | var o_dir = try comp.dirs.global_cache.handle.createDirPathOpen(io, o_sub_path, .{}); |
| 277 | 299 | defer o_dir.close(io); |
| 278 | 300 | |
| 279 | const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" }); | |
| 280 | ||
| 281 | if (comp.verbose_cc) { | |
| 282 | var buffer: [256]u8 = undefined; | |
| 283 | const stderr = try io.lockStderr(&buffer, null); | |
| 284 | defer io.unlockStderr(); | |
| 285 | const w = &stderr.file_writer.interface; | |
| 286 | w.print("def file: {s}\n", .{def_file_path}) catch |err| switch (err) { | |
| 287 | error.WriteFailed => return stderr.file_writer.err.?, | |
| 288 | }; | |
| 289 | w.print("include dir: {s}\n", .{include_dir}) catch |err| switch (err) { | |
| 290 | error.WriteFailed => return stderr.file_writer.err.?, | |
| 291 | }; | |
| 292 | } | |
| 301 | const sep = path.sep_str; | |
| 302 | const include_dir: Cache.Path = .{ | |
| 303 | .root_dir = comp.dirs.zig_lib, | |
| 304 | .sub_path = "libc" ++ sep ++ "mingw" ++ sep ++ "def-include", | |
| 305 | }; | |
| 293 | 306 | |
| 294 | 307 | const members = members: { |
| 295 | 308 | const members_node = sub_node.start("Members", 0); |
| ... | ... | @@ -313,7 +326,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8, prog_node: std.P |
| 313 | 326 | |
| 314 | 327 | break :pp try aw.toOwnedSliceSentinel(0); |
| 315 | 328 | }, |
| 316 | false => try Io.Dir.cwd().readFileAllocOptions(io, def_file_path, gpa, .unlimited, .of(u8), 0), | |
| 329 | false => try def_file_path.root_dir.handle.readFileAllocOptions(io, def_file_path.sub_path, gpa, .unlimited, .of(u8), 0), | |
| 317 | 330 | }; |
| 318 | 331 | defer gpa.free(input); |
| 319 | 332 |
src/libs/mingw/Preprocessor.zig+12-22| ... | ... | @@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator; |
| 4 | 4 | const Token = Tokenizer.Token; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | const assert = std.debug.assert; |
| 7 | const Path = std.Build.Cache.Path; | |
| 7 | 8 | |
| 8 | 9 | test { |
| 9 | 10 | _ = Tokenizer; |
| ... | ... | @@ -25,15 +26,15 @@ pub const Source = struct { |
| 25 | 26 | pub const generated: Source.Id = std.math.maxInt(usize); |
| 26 | 27 | pub const Id = usize; |
| 27 | 28 | id: Id = generated, |
| 28 | path: []const u8, | |
| 29 | path: Path, | |
| 29 | 30 | buf: []const u8, |
| 30 | 31 | }; |
| 31 | 32 | |
| 32 | sources: std.array_hash_map.String(Source) = .empty, | |
| 33 | sources: std.array_hash_map.Custom(Path, Source, Path.TableAdapter, false) = .empty, | |
| 33 | 34 | |
| 34 | 35 | arena: Allocator, |
| 35 | 36 | io: std.Io, |
| 36 | include_dir: []const u8, | |
| 37 | include_dir: Path, | |
| 37 | 38 | |
| 38 | 39 | top_expansion_buf: ExpandBuf = .empty, |
| 39 | 40 | add_expansion_nl: usize = 0, |
| ... | ... | @@ -132,7 +133,7 @@ fn defineBuiltin(pp: *Preprocessor, name: []const u8) !void { |
| 132 | 133 | }); |
| 133 | 134 | } |
| 134 | 135 | |
| 135 | pub fn preprocess(pp: *Preprocessor, file_path: []const u8) !void { | |
| 136 | pub fn preprocess(pp: *Preprocessor, file_path: Path) !void { | |
| 136 | 137 | const source = try pp.addSourceFromPath(file_path); |
| 137 | 138 | try pp.preprocessFile(source); |
| 138 | 139 | } |
| ... | ... | @@ -789,13 +790,9 @@ fn makeGeneratedToken( |
| 789 | 790 | return pasted_token; |
| 790 | 791 | } |
| 791 | 792 | |
| 792 | fn findInclude( | |
| 793 | pp: *Preprocessor, | |
| 794 | filename: []const u8, | |
| 795 | includer_token: Token, | |
| 796 | ) !?Source { | |
| 793 | fn findInclude(pp: *Preprocessor, filename: []const u8, includer_token: Token) !?Source { | |
| 797 | 794 | const other_file = pp.sources.values()[includer_token.source].path; |
| 798 | const dir = std.fs.path.dirname(other_file) orelse "."; | |
| 795 | const dir: Path = other_file.dirname() orelse .cwd(); | |
| 799 | 796 | if (try pp.checkIncludeDir(filename, dir)) |res| return res; |
| 800 | 797 | |
| 801 | 798 | return pp.checkIncludeDir(filename, pp.include_dir); |
| ... | ... | @@ -804,31 +801,24 @@ fn findInclude( |
| 804 | 801 | fn checkIncludeDir( |
| 805 | 802 | pp: *Preprocessor, |
| 806 | 803 | include_path: []const u8, |
| 807 | include_dir: []const u8, | |
| 804 | include_dir: Path, | |
| 808 | 805 | ) !?Source { |
| 809 | const format = "{s}{c}{s}"; | |
| 810 | 806 | var bfa_buf: [1024]u8 = undefined; |
| 811 | 807 | var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.arena); |
| 812 | 808 | const bfa = bfa_state.allocator(); |
| 813 | const header_path = try std.fmt.allocPrint(bfa, format, .{ | |
| 814 | include_dir, | |
| 815 | std.fs.path.sep, | |
| 816 | include_path, | |
| 817 | }); | |
| 818 | defer bfa.free(header_path); | |
| 819 | ||
| 809 | const header_path = try include_dir.join(bfa, include_path); | |
| 820 | 810 | return pp.addSourceFromPath(header_path) catch |err| switch (err) { |
| 821 | 811 | error.OutOfMemory => |e| return e, |
| 822 | 812 | else => return null, |
| 823 | 813 | }; |
| 824 | 814 | } |
| 825 | 815 | |
| 826 | pub fn addSourceFromPath(pp: *Preprocessor, path: []const u8) !Source { | |
| 816 | pub fn addSourceFromPath(pp: *Preprocessor, path: Path) !Source { | |
| 827 | 817 | if (pp.sources.get(path)) |src| return src; |
| 828 | 818 | try pp.sources.ensureUnusedCapacity(pp.arena, 1); |
| 829 | 819 | |
| 830 | const contents = try std.Io.Dir.cwd().readFileAlloc(pp.io, path, pp.arena, .limited(std.math.maxInt(u32))); | |
| 831 | const duped_path = try pp.arena.dupe(u8, path); | |
| 820 | const contents = try path.root_dir.handle.readFileAlloc(pp.io, path.sub_path, pp.arena, .limited(std.math.maxInt(u32))); | |
| 821 | const duped_path = try path.clone(pp.arena); | |
| 832 | 822 | |
| 833 | 823 | const src: Source = .{ |
| 834 | 824 | .buf = contents, |