Skip to content

Commit 2677401

Browse files
committed
update zig to 0.15.2
1 parent ee31390 commit 2677401

File tree

5 files changed

+123
-83
lines changed

5 files changed

+123
-83
lines changed

CompileCheck.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
146146
const source_path = check.source_path.getPath2(b, step);
147147

148148
const result = blk: {
149-
var zig_args: std.ArrayList([]const u8) = .init(b.allocator);
149+
var zig_args: std.array_list.Managed([]const u8) = .init(b.allocator);
150150
defer zig_args.deinit();
151151
try zig_args.append(b.graph.zig_exe);
152152
try zig_args.append(switch (check.kind) {
@@ -185,6 +185,7 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
185185
getGeneratedFilePath(other, "generated_bin", step);
186186
try zig_args.append(full_path_lib);
187187
},
188+
.test_obj => @panic("todo"),
188189
}
189190
},
190191
else => |o| std.debug.panic("todo: handle link object {s}", .{@tagName(o)}),
@@ -248,7 +249,7 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
248249
.undeclared_identifier_count = undeclared_identifier_count,
249250
} };
250251
},
251-
inline else => return step.fail("zig {}", .{fmtTerm(result.term)}),
252+
inline else => return step.fail("zig {f}", .{fmtTerm(result.term)}),
252253
}
253254
}
254255

@@ -267,8 +268,11 @@ fn getGeneratedFilePath(compile: *std.Build.Step.Compile, comptime tag_name: []c
267268
{
268269
std.debug.lockStdErr();
269270
defer std.debug.unlockStdErr();
270-
const stderr = std.io.getStdErr();
271-
std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
271+
var stderr_buf: [1000]u8 = undefined;
272+
var stderr_writer = std.fs.File.stderr().writer(&stderr_buf);
273+
const stderr = &stderr_writer.interface;
274+
std.Build.dumpBadGetPathHelp(&compile.step, stderr, .detect(.stderr()), compile.step.owner, asking_step) catch {};
275+
stderr.flush() catch {};
272276
}
273277
@panic("missing emit option for " ++ tag_name);
274278
};
@@ -277,26 +281,22 @@ fn getGeneratedFilePath(compile: *std.Build.Step.Compile, comptime tag_name: []c
277281
{
278282
std.debug.lockStdErr();
279283
defer std.debug.unlockStdErr();
280-
const stderr = std.io.getStdErr();
281-
std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
284+
var stderr_buf: [1000]u8 = undefined;
285+
var stderr_writer = std.fs.File.stderr().writer(&stderr_buf);
286+
const stderr = &stderr_writer.interface;
287+
std.Build.dumpBadGetPathHelp(&compile.step, stderr, .detect(.stderr()), compile.step.owner, asking_step) catch {};
288+
stderr.flush() catch {};
282289
}
283290
@panic(tag_name ++ " is null. Is there a missing step dependency?");
284291
};
285292

286293
return path;
287294
}
288295

289-
fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Formatter(formatTerm) {
296+
fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Alt(?std.process.Child.Term, formatTerm) {
290297
return .{ .data = term };
291298
}
292-
fn formatTerm(
293-
term: ?std.process.Child.Term,
294-
comptime fmt: []const u8,
295-
options: std.fmt.FormatOptions,
296-
writer: anytype,
297-
) !void {
298-
_ = fmt;
299-
_ = options;
299+
fn formatTerm(term: ?std.process.Child.Term, writer: *std.Io.Writer) error{WriteFailed}!void {
300300
if (term) |t| switch (t) {
301301
.Exited => |code| try writer.print("exited with code {}", .{code}),
302302
.Signal => |sig| try writer.print("terminated with signal {}", .{sig}),

build.zig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,16 @@ fn addPythonExe(
432432
) *std.Build.Step.Compile {
433433
const exe = b.addExecutable(.{
434434
.name = args.name,
435-
.target = target,
436-
.optimize = optimize,
435+
.root_module = b.createModule(.{
436+
.target = target,
437+
.optimize = optimize,
438+
}),
437439
});
438440

439441
switch (args.pyconfig.version) {
440442
.@"3.11.13" => {
441443
// workaround dictobject.c memcpy alignment issue
442-
exe.root_module.sanitize_c = false;
444+
exe.root_module.sanitize_c = .off;
443445
},
444446
.@"3.12.11" => {},
445447
}
@@ -593,7 +595,14 @@ fn addPythonExe(
593595
},
594596
}),
595597
},
596-
.flags = &flags_common,
598+
.flags = concat(b.allocator, &.{
599+
&flags_common,
600+
switch (args.pyconfig.version) {
601+
.@"3.11.13" => &.{},
602+
// tokenizer.c uses pointer overflow in restore_fstring_buffers
603+
.@"3.12.11" => &.{"-fno-sanitize=pointer-overflow"},
604+
},
605+
}),
597606
});
598607

599608
exe.addCSourceFile(.{
@@ -1235,7 +1244,7 @@ fn addPyconfig(
12351244
};
12361245

12371246
const config_header = b.addConfigHeader(.{
1238-
.style = .{ .autoconf = upstream.path("pyconfig.h.in") },
1247+
.style = .{ .autoconf_undef = upstream.path("pyconfig.h.in") },
12391248
.include_path = "pyconfig.h",
12401249
}, .{
12411250
.ALIGNOF_LONG = 8,

build.zig.zon

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.name = .cpython,
33
.fingerprint = 0x3224901d1babdd14,
44
.version = "0.0.0",
5-
.minimum_zig_version = "0.14.1",
5+
.minimum_zig_version = "0.15.2",
66
.dependencies = .{
77
.@"upstream_3.11.13" = .{
88
.url = "git+https://github.com/python/cpython#498b971ea3673012a1d4b21860b229d55fc6e575",
@@ -15,12 +15,12 @@
1515
.lazy = true,
1616
},
1717
.zlib = .{
18-
.url = "https://github.com/allyourcodebase/zlib/archive/6c72830882690c1eb2567a537525c3f432c1da50.tar.gz",
19-
.hash = "zlib-1.3.1-ZZQ7lVgMAACwO4nUUd8GLhsuQ5JQq_VAhlEiENJTUv6h",
18+
.url = "git+https://github.com/allyourcodebase/zlib#c2585c096171b8fbc8e5f78ab6c91b39e3573e15",
19+
.hash = "zlib-1.3.1-ZZQ7lcMNAABPzkWdm_9y0tjlN17kF7czIiTVQ7h10rMR",
2020
},
2121
.openssl = .{
22-
.url = "https://github.com/allyourcodebase/openssl/archive/f348124c5382bcc377f1b3277357cbf2ed2fb8db.tar.gz",
23-
.hash = "openssl-3.3.1-2-TC9C3Se3ZACF5WO_CjoD7Bt_X94oCsAAbbwhOp1rTZBe",
22+
.url = "git+https://github.com/allyourcodebase/openssl#7d4b2590b3b05fbc0e5cc20e2704a968e63503b1",
23+
.hash = "openssl-3.3.2-TC9C3Vy3ZABkts70T3a6QfLYghNUy0tI42ksiW7jRmvd",
2424
.lazy = true,
2525
},
2626
},

makesetup.zig

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pub fn main() !void {
77
// no need to free
88

99
if (all_args.len <= 1) {
10-
try std.io.getStdErr().writer().writeAll("usage: makesetup UPSTREAM_SRC OUT_DIR SETUP_FILES...\n");
10+
var stderr = std.fs.File.stderr().writer(&.{});
11+
try stderr.interface.writeAll("usage: makesetup UPSTREAM_SRC OUT_DIR SETUP_FILES...\n");
1112
std.process.exit(0xff);
1213
}
1314
const args = all_args[1..];
@@ -36,51 +37,67 @@ pub fn main() !void {
3637
{
3738
var file = try out_dir.createFile("config.c", .{});
3839
defer file.close();
39-
var bw = std.io.bufferedWriter(file.writer());
40-
const writer = bw.writer();
41-
try writer.print("/* Generated automatically from {s} by makesetup. */\n", .{config_in_path});
42-
var lines = std.mem.splitScalar(u8, config_in, '\n');
43-
while (lines.next()) |line| {
44-
if (std.mem.indexOf(u8, line, "MARKER 1")) |_| {
45-
var it = setup.modules.iterator();
46-
while (it.next()) |entry| {
47-
if (!entry.value_ptr.enabled) continue;
48-
try writer.print("extern PyObject* PyInit_{s}(void);\n", .{entry.key_ptr.*});
49-
}
50-
} else if (std.mem.indexOf(u8, line, "MARKER 2")) |_| {
51-
var it = setup.modules.iterator();
52-
while (it.next()) |entry| {
53-
if (!entry.value_ptr.enabled) continue;
54-
try writer.print(" {{\"{s}\", PyInit_{0s}}},\n", .{entry.key_ptr.*});
55-
}
56-
}
57-
try writer.writeAll(line);
58-
try writer.writeByte('\n');
59-
}
60-
try bw.flush();
40+
var out_file_buf: [4096]u8 = undefined;
41+
var file_writer = file.writer(&out_file_buf);
42+
writeConfigC(setup, config_in_path, config_in, &file_writer.interface) catch |err| switch (err) {
43+
error.WriteFailed => return file_writer.err orelse error.Unexpected,
44+
};
6145
}
6246

6347
{
6448
var out_file = try out_dir.createFile("module-compile-args.txt", .{});
6549
defer out_file.close();
66-
var bw = std.io.bufferedWriter(out_file.writer());
67-
const writer = bw.writer();
50+
var out_file_buf: [4096]u8 = undefined;
51+
var file_writer = out_file.writer(&out_file_buf);
52+
writeCompileArgs(setup, &file_writer.interface) catch |err| switch (err) {
53+
error.WriteFailed => return file_writer.err orelse error.Unexpected,
54+
};
55+
}
56+
}
6857

69-
var it = setup.modules.iterator();
70-
while (it.next()) |entry| {
71-
const module_name = entry.key_ptr.*;
72-
{
73-
const suffix: []const u8 = if (entry.value_ptr.enabled) "" else " (DISABLED)";
74-
try writer.print("# Module '{s}'{s}\n", .{ module_name, suffix });
58+
fn writeConfigC(
59+
setup: Setup,
60+
config_in_path: []const u8,
61+
config_in: []const u8,
62+
writer: *std.Io.Writer,
63+
) error{WriteFailed}!void {
64+
try writer.print("/* Generated automatically from {s} by makesetup. */\n", .{config_in_path});
65+
var lines = std.mem.splitScalar(u8, config_in, '\n');
66+
while (lines.next()) |line| {
67+
if (std.mem.indexOf(u8, line, "MARKER 1")) |_| {
68+
var it = setup.modules.iterator();
69+
while (it.next()) |entry| {
70+
if (!entry.value_ptr.enabled) continue;
71+
try writer.print("extern PyObject* PyInit_{s}(void);\n", .{entry.key_ptr.*});
7572
}
76-
const prefix: []const u8 = if (entry.value_ptr.enabled) "" else "# ";
77-
for (entry.value_ptr.compile_args) |compile_arg| switch (compile_arg) {
78-
.source => |src| try writer.print("{s}Modules/{s}\n", .{ prefix, src }),
79-
.include => |inc| try writer.print("{s}-I{s}\n", .{ prefix, inc }),
80-
};
73+
} else if (std.mem.indexOf(u8, line, "MARKER 2")) |_| {
74+
var it = setup.modules.iterator();
75+
while (it.next()) |entry| {
76+
if (!entry.value_ptr.enabled) continue;
77+
try writer.print(" {{\"{s}\", PyInit_{0s}}},\n", .{entry.key_ptr.*});
78+
}
79+
}
80+
try writer.writeAll(line);
81+
try writer.writeByte('\n');
82+
}
83+
try writer.flush();
84+
}
85+
86+
fn writeCompileArgs(setup: Setup, writer: *std.Io.Writer) error{WriteFailed}!void {
87+
var it = setup.modules.iterator();
88+
while (it.next()) |entry| {
89+
const module_name = entry.key_ptr.*;
90+
{
91+
const suffix: []const u8 = if (entry.value_ptr.enabled) "" else " (DISABLED)";
92+
try writer.print("# Module '{s}'{s}\n", .{ module_name, suffix });
8193
}
82-
try bw.flush();
94+
const prefix: []const u8 = if (entry.value_ptr.enabled) "" else "# ";
95+
for (entry.value_ptr.compile_args) |compile_arg| switch (compile_arg) {
96+
.source => |src| try writer.print("{s}Modules/{s}\n", .{ prefix, src }),
97+
.include => |inc| try writer.print("{s}-I{s}\n", .{ prefix, inc }),
98+
};
8399
}
100+
try writer.flush();
84101
}
85102

86103
const CompileArg = union(enum) {

replace.zig

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pub fn main() !void {
77
// no need to free
88

99
if (all_args.len <= 1) {
10-
try std.io.getStdErr().writer().writeAll("usage: replace IN_FILE OUT_FILE NAME=VALUE...\n");
10+
var stderr = std.fs.File.stderr().writer(&.{});
11+
try stderr.interface.writeAll("usage: replace IN_FILE OUT_FILE NAME=VALUE...\n");
1112
std.process.exit(0xff);
1213
}
1314
const args = all_args[1..];
@@ -17,10 +18,7 @@ pub fn main() !void {
1718
const out_path = args[1];
1819
const replacements = args[2..];
1920

20-
var map: std.StringHashMapUnmanaged(struct {
21-
count: usize,
22-
value: []const u8,
23-
}) = .{};
21+
var map: std.StringHashMapUnmanaged(MapNode) = .{};
2422
for (replacements) |r| {
2523
const eq_index = std.mem.indexOfScalar(u8, r, '=') orelse errExit(
2624
"expected NAME=VALUE cmdline arg but got '{s}'",
@@ -41,9 +39,38 @@ pub fn main() !void {
4139

4240
var out_file = try std.fs.cwd().createFile(out_path, .{});
4341
defer out_file.close();
44-
var bw = std.io.bufferedWriter(out_file.writer());
45-
const writer = bw.writer();
4642

43+
var out_file_buf: [4096]u8 = undefined;
44+
var file_writer = out_file.writer(&out_file_buf);
45+
writeFile(in_path, in, &map, &file_writer.interface) catch |err| switch (err) {
46+
error.WriteFailed => return file_writer.err orelse error.Unexpected,
47+
};
48+
49+
var unused_count: usize = 0;
50+
var it = map.iterator();
51+
while (it.next()) |entry| {
52+
if (entry.value_ptr.count == 0) {
53+
std.log.err("unused variable '{s}'", .{entry.key_ptr.*});
54+
unused_count += 1;
55+
}
56+
}
57+
if (unused_count != 0) {
58+
std.log.err("{} unused variable(s), the did not appear in template '{s}'", .{ unused_count, in_path });
59+
std.process.exit(0xff);
60+
}
61+
}
62+
63+
const MapNode = struct {
64+
count: usize,
65+
value: []const u8,
66+
};
67+
68+
fn writeFile(
69+
in_path: []const u8,
70+
in: []const u8,
71+
map: *const std.StringHashMapUnmanaged(MapNode),
72+
writer: *std.Io.Writer,
73+
) error{WriteFailed}!void {
4774
var missing_count: usize = 0;
4875
var offset: usize = 0;
4976
while (true) {
@@ -65,21 +92,8 @@ pub fn main() !void {
6592
offset = end + 1;
6693
}
6794
try writer.writeAll(in[offset..]);
68-
try bw.flush();
95+
try writer.flush();
6996
if (missing_count > 0) errExit("{} missing variable(s) for template '{s}'", .{ missing_count, in_path });
70-
71-
var unused_count: usize = 0;
72-
var it = map.iterator();
73-
while (it.next()) |entry| {
74-
if (entry.value_ptr.count == 0) {
75-
std.log.err("unused variable '{s}'", .{entry.key_ptr.*});
76-
unused_count += 1;
77-
}
78-
}
79-
if (unused_count != 0) {
80-
std.log.err("{} unused variable(s), the did not appear in template '{s}'", .{ unused_count, in_path });
81-
std.process.exit(0xff);
82-
}
8397
}
8498

8599
fn errExit(comptime fmt: []const u8, args: anytype) noreturn {

0 commit comments

Comments
 (0)