authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-06-18 10:54:11+02:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-06-18 10:54:11+02:00
log46a750a006d90120feddcf0f0b9a0b5db9e222be
tree798cf02fbeea50d6f22cc01523ff60a29febaf91
parentea73defb5c5424a4b59c6508483ad8fcbe6dbeb7
parenta851256a988f01e8fd9a6c84a9bac499e81f407d

Merge pull request 'mingw: Only preprocess .def.in files' (#35829) from squeek502/zig:mingw-def-followup into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35829 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

3 files changed, 23 insertions(+), 22 deletions(-)

src/libs/mingw.zig+21-16
......@@ -226,6 +226,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
226226 },
227227 else => |e| return e,
228228 };
229 // Only .def.in files need preprocessing
230 const def_needs_preprocessing = mem.endsWith(u8, def_file_path, ".def.in");
229231
230232 const target = comp.getTarget();
231233
......@@ -292,22 +294,25 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
292294 }
293295
294296 const members = members: {
295 const input = pp: {
296 var aw: Io.Writer.Allocating = .init(gpa);
297 errdefer aw.deinit();
298
299 var pp_arena = std.heap.ArenaAllocator.init(gpa);
300 defer pp_arena.deinit();
301 var pp: Preprocessor = .{
302 .io = io,
303 .arena = pp_arena.allocator(),
304 .include_dir = include_dir,
305 .target = target,
306 };
307 try pp.preprocess(def_file_path);
308 try pp.prettyPrintTokens(&aw.writer);
309
310 break :pp try aw.toOwnedSliceSentinel(0);
297 const input = switch (def_needs_preprocessing) {
298 true => pp: {
299 var aw: Io.Writer.Allocating = .init(gpa);
300 errdefer aw.deinit();
301
302 var pp_arena = std.heap.ArenaAllocator.init(gpa);
303 defer pp_arena.deinit();
304 var pp: Preprocessor = .{
305 .io = io,
306 .arena = pp_arena.allocator(),
307 .include_dir = include_dir,
308 .target = target,
309 };
310 try pp.preprocess(def_file_path);
311 try pp.prettyPrintTokens(&aw.writer);
312
313 break :pp try aw.toOwnedSliceSentinel(0);
314 },
315 false => try Io.Dir.cwd().readFileAllocOptions(io, def_file_path, gpa, .unlimited, .of(u8), 0),
311316 };
312317 defer gpa.free(input);
313318
src/libs/mingw/Tokenizer.zig-6
......@@ -254,12 +254,6 @@ pub fn nextNoWS(self: *Tokenizer) Token {
254254 return tok;
255255}
256256
257pub fn nextNoWSComments(self: *Tokenizer) Token {
258 var tok = self.next();
259 while (tok.id == .whitespace) tok = self.next();
260 return tok;
261}
262
263257fn expectToken(expected: Token.Id, actual: Token) !void {
264258 try std.testing.expectEqual(expected, actual.id);
265259}
tools/check_mingw.zig+2
......@@ -28,6 +28,8 @@ pub fn main(init: std.process.Init) !void {
2828
2929 while (try walker.next(io)) |entry| {
3030 if (entry.kind != .file) continue;
31 // Only .def.in files need preprocessing
32 if (!std.mem.endsWith(u8, entry.basename, ".def.in")) continue;
3133
3234 var fail = false;
3335 for (&targets) |*target| {