Skip to content

Commit 269f23d

Browse files
committed
update zig to 0.15.2
1 parent ee31390 commit 269f23d

File tree

5 files changed

+119
-95
lines changed

5 files changed

+119
-95
lines changed

CompileCheck.zig

Lines changed: 11 additions & 20 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) {
@@ -170,7 +170,7 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
170170
.other_step => |other| {
171171
switch (other.kind) {
172172
.exe => return step.fail("cannot link with an executable build artifact", .{}),
173-
.@"test" => return step.fail("cannot link with a test", .{}),
173+
.@"test", .test_obj => return step.fail("cannot link with a test", .{}),
174174
.obj => {
175175
try zig_args.append(other.getEmittedBin().getPath2(b, step));
176176
},
@@ -248,7 +248,7 @@ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) anyerror!voi
248248
.undeclared_identifier_count = undeclared_identifier_count,
249249
} };
250250
},
251-
inline else => return step.fail("zig {}", .{fmtTerm(result.term)}),
251+
inline else => return step.fail("zig {f}", .{fmtTerm(result.term)}),
252252
}
253253
}
254254

@@ -265,38 +265,29 @@ fn getGeneratedFilePath(compile: *std.Build.Step.Compile, comptime tag_name: []c
265265

266266
const generated_file = maybe_path orelse {
267267
{
268-
std.debug.lockStdErr();
269-
defer std.debug.unlockStdErr();
270-
const stderr = std.io.getStdErr();
271-
std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
268+
const stderr = std.debug.lockStderrWriter(&.{});
269+
defer std.debug.unlockStderrWriter();
270+
std.Build.dumpBadGetPathHelp(&compile.step, stderr, .detect(.stderr()), compile.step.owner, asking_step) catch {};
272271
}
273272
@panic("missing emit option for " ++ tag_name);
274273
};
275274

276275
const path = generated_file.path orelse {
277276
{
278-
std.debug.lockStdErr();
279-
defer std.debug.unlockStdErr();
280-
const stderr = std.io.getStdErr();
281-
std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
277+
const stderr = std.debug.lockStderrWriter(&.{});
278+
defer std.debug.unlockStderrWriter();
279+
std.Build.dumpBadGetPathHelp(&compile.step, stderr, .detect(.stderr()), compile.step.owner, asking_step) catch {};
282280
}
283281
@panic(tag_name ++ " is null. Is there a missing step dependency?");
284282
};
285283

286284
return path;
287285
}
288286

289-
fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Formatter(formatTerm) {
287+
fn fmtTerm(term: ?std.process.Child.Term) std.fmt.Alt(?std.process.Child.Term, formatTerm) {
290288
return .{ .data = term };
291289
}
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;
290+
fn formatTerm(term: ?std.process.Child.Term, writer: *std.Io.Writer) error{WriteFailed}!void {
300291
if (term) |t| switch (t) {
301292
.Exited => |code| try writer.print("exited with code {}", .{code}),
302293
.Signal => |sig| try writer.print("terminated with signal {}", .{sig}),

build.zig

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,12 @@ 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

439-
switch (args.pyconfig.version) {
440-
.@"3.11.13" => {
441-
// workaround dictobject.c memcpy alignment issue
442-
exe.root_module.sanitize_c = false;
443-
},
444-
.@"3.12.11" => {},
445-
}
446-
447441
exe.root_module.addCMacro("Py_BUILD_CORE", "");
448442
exe.root_module.addCMacro("_GNU_SOURCE", "");
449443
switch (optimize) {
@@ -593,7 +587,15 @@ fn addPythonExe(
593587
},
594588
}),
595589
},
596-
.flags = &flags_common,
590+
.flags = concat(b.allocator, &.{
591+
&flags_common,
592+
switch (args.pyconfig.version) {
593+
// workaround dictobject.c memcpy alignment issue
594+
.@"3.11.13" => &.{"-fno-sanitize=alignment"},
595+
// tokenizer.c uses pointer overflow in restore_fstring_buffers
596+
.@"3.12.11" => &.{"-fno-sanitize=pointer-overflow"},
597+
},
598+
}),
597599
});
598600

599601
exe.addCSourceFile(.{
@@ -1235,7 +1237,7 @@ fn addPyconfig(
12351237
};
12361238

12371239
const config_header = b.addConfigHeader(.{
1238-
.style = .{ .autoconf = upstream.path("pyconfig.h.in") },
1240+
.style = .{ .autoconf_undef = upstream.path("pyconfig.h.in") },
12391241
.include_path = "pyconfig.h",
12401242
}, .{
12411243
.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)