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 {...@@ -226,6 +226,8 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
226 },226 },
227 else => |e| return e,227 else => |e| return e,
228 };228 };
229 // Only .def.in files need preprocessing
230 const def_needs_preprocessing = mem.endsWith(u8, def_file_path, ".def.in");
229231
230 const target = comp.getTarget();232 const target = comp.getTarget();
231233
...@@ -292,22 +294,25 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -292,22 +294,25 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
292 }294 }
293295
294 const members = members: {296 const members = members: {
295 const input = pp: {297 const input = switch (def_needs_preprocessing) {
296 var aw: Io.Writer.Allocating = .init(gpa);298 true => pp: {
297 errdefer aw.deinit();299 var aw: Io.Writer.Allocating = .init(gpa);
298300 errdefer aw.deinit();
299 var pp_arena = std.heap.ArenaAllocator.init(gpa);301
300 defer pp_arena.deinit();302 var pp_arena = std.heap.ArenaAllocator.init(gpa);
301 var pp: Preprocessor = .{303 defer pp_arena.deinit();
302 .io = io,304 var pp: Preprocessor = .{
303 .arena = pp_arena.allocator(),305 .io = io,
304 .include_dir = include_dir,306 .arena = pp_arena.allocator(),
305 .target = target,307 .include_dir = include_dir,
306 };308 .target = target,
307 try pp.preprocess(def_file_path);309 };
308 try pp.prettyPrintTokens(&aw.writer);310 try pp.preprocess(def_file_path);
309311 try pp.prettyPrintTokens(&aw.writer);
310 break :pp try aw.toOwnedSliceSentinel(0);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),
311 };316 };
312 defer gpa.free(input);317 defer gpa.free(input);
313318
src/libs/mingw/Tokenizer.zig-6
...@@ -254,12 +254,6 @@ pub fn nextNoWS(self: *Tokenizer) Token {...@@ -254,12 +254,6 @@ pub fn nextNoWS(self: *Tokenizer) Token {
254 return tok;254 return tok;
255}255}
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
263fn expectToken(expected: Token.Id, actual: Token) !void {257fn expectToken(expected: Token.Id, actual: Token) !void {
264 try std.testing.expectEqual(expected, actual.id);258 try std.testing.expectEqual(expected, actual.id);
265}259}
tools/check_mingw.zig+2
...@@ -28,6 +28,8 @@ pub fn main(init: std.process.Init) !void {...@@ -28,6 +28,8 @@ pub fn main(init: std.process.Init) !void {
2828
29 while (try walker.next(io)) |entry| {29 while (try walker.next(io)) |entry| {
30 if (entry.kind != .file) continue;30 if (entry.kind != .file) continue;
31 // Only .def.in files need preprocessing
32 if (!std.mem.endsWith(u8, entry.basename, ".def.in")) continue;
3133
32 var fail = false;34 var fail = false;
33 for (&targets) |*target| {35 for (&targets) |*target| {