Skip to content

Commit 5567781

Browse files
committed
build system: fixups to --seed mechanism
* support 0x prefixed hex code for CLI seed arguments * don't change the build summary; the printed CLI on build runner failure is sufficient * use `std.crypto.random` instead of system time for entropy
1 parent c1fef77 commit 5567781

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/build_runner.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ pub fn main() !void {
202202
std.debug.print("Expected u32 after {s}\n\n", .{arg});
203203
usageAndErr(builder, false, stderr_stream);
204204
};
205-
seed = std.fmt.parseUnsigned(u32, next_arg, 10) catch |err| {
206-
std.debug.print("unable to parse seed '{s}' as u32: {s}", .{ next_arg, @errorName(err) });
205+
seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
206+
std.debug.print("unable to parse seed '{s}' as 32-bit integer: {s}", .{
207+
next_arg, @errorName(err),
208+
});
207209
process.exit(1);
208210
};
209211
} else if (mem.eql(u8, arg, "--debug-log")) {
@@ -526,9 +528,7 @@ fn runStepNames(
526528
stderr.writeAll(" (disable with --summary none)") catch {};
527529
ttyconf.setColor(stderr, .reset) catch {};
528530
}
529-
ttyconf.setColor(stderr, .dim) catch {};
530-
stderr.writer().print("\nseed is {}\n", .{seed}) catch {};
531-
ttyconf.setColor(stderr, .reset) catch {};
531+
stderr.writeAll("\n") catch {};
532532
const failures_only = run.summary != Summary.all;
533533

534534
// Print a fancy tree with build results.

src/main.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,6 +4906,7 @@ pub const usage_build =
49064906
\\ --global-cache-dir [path] Override path to global Zig cache directory
49074907
\\ --zig-lib-dir [arg] Override path to Zig lib directory
49084908
\\ --build-runner [file] Override path to build runner
4909+
\\ --seed [integer] For shuffling dependency traversal order (default: random)
49094910
\\ --fetch Exit after fetching dependency tree
49104911
\\ -h, --help Print this help and exit
49114912
\\
@@ -4930,8 +4931,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
49304931
var reference_trace: ?u32 = null;
49314932
var debug_compile_errors = false;
49324933
var fetch_only = false;
4933-
const micros: u32 = @truncate(@as(u64, @bitCast(std.time.microTimestamp())));
4934-
var seed: []const u8 = try std.fmt.allocPrint(arena, "{}", .{micros});
49354934

49364935
const argv_index_exe = child_argv.items.len;
49374936
_ = try child_argv.addOne();
@@ -4947,7 +4946,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
49474946
const argv_index_global_cache_dir = child_argv.items.len;
49484947
_ = try child_argv.addOne();
49494948

4950-
try child_argv.appendSlice(&[_][]const u8{ "--seed", seed });
4949+
try child_argv.appendSlice(&.{
4950+
"--seed",
4951+
try std.fmt.allocPrint(arena, "0x{x}", .{std.crypto.random.int(u32)}),
4952+
});
49514953
const argv_index_seed = child_argv.items.len - 1;
49524954

49534955
{

0 commit comments

Comments
 (0)