Skip to content

Commit 479a91b

Browse files
committed
Merge branch 'master' into add-no-undefined-version-linker-arg
2 parents 8287e5a + fc79b22 commit 479a91b

35 files changed

+835
-495
lines changed

ci/x86_64-windows-debug.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
9696
CheckLastExitCode
9797

9898
Write-Output "Build and run behavior tests with msvc..."
99-
Write-Output "Skipped due to https://github.com/ziglang/zig/issues/17817"
100-
#& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
101-
#CheckLastExitCode
102-
#
103-
#& .\test-x86_64-windows-msvc.exe
104-
#CheckLastExitCode
99+
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
100+
CheckLastExitCode
101+
102+
& .\test-x86_64-windows-msvc.exe
103+
CheckLastExitCode

ci/x86_64-windows-release.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\E
9595
CheckLastExitCode
9696

9797
Write-Output "Build and run behavior tests with msvc..."
98-
Write-Output "Skipped due to https://github.com/ziglang/zig/issues/17817"
99-
#& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
100-
#CheckLastExitCode
101-
#
102-
#& .\test-x86_64-windows-msvc.exe
103-
#CheckLastExitCode
98+
& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib
99+
CheckLastExitCode
100+
101+
& .\test-x86_64-windows-msvc.exe
102+
CheckLastExitCode

lib/std/Build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 {
15511551

15521552
pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 {
15531553
// TODO report error for ambiguous situations
1554-
const exe_extension = @as(Target.Query, .{}).exeFileExt();
1554+
const exe_extension = self.host.result.exeFileExt();
15551555
for (self.search_prefixes.items) |search_prefix| {
15561556
for (names) |name| {
15571557
if (fs.path.isAbsolute(name)) {

lib/std/Build/Cache.zig

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ fn getPrefixSubpath(allocator: Allocator, prefix: []const u8, path: []u8) ![]u8
179179
pub const bin_digest_len = 16;
180180
pub const hex_digest_len = bin_digest_len * 2;
181181
pub const BinDigest = [bin_digest_len]u8;
182+
pub const HexDigest = [hex_digest_len]u8;
182183

183184
/// This is currently just an arbitrary non-empty string that can't match another manifest line.
184185
const manifest_header = "0";
@@ -300,11 +301,11 @@ pub const HashHelper = struct {
300301
}
301302

302303
/// Returns a hex encoded hash of the inputs, mutating the state of the hasher.
303-
pub fn final(hh: *HashHelper) [hex_digest_len]u8 {
304+
pub fn final(hh: *HashHelper) HexDigest {
304305
var bin_digest: BinDigest = undefined;
305306
hh.hasher.final(&bin_digest);
306307

307-
var out_digest: [hex_digest_len]u8 = undefined;
308+
var out_digest: HexDigest = undefined;
308309
_ = fmt.bufPrint(
309310
&out_digest,
310311
"{s}",
@@ -360,7 +361,7 @@ pub const Manifest = struct {
360361
// will then use the same timestamp, to avoid unnecessary filesystem writes.
361362
want_refresh_timestamp: bool = true,
362363
files: std.ArrayListUnmanaged(File) = .{},
363-
hex_digest: [hex_digest_len]u8,
364+
hex_digest: HexDigest,
364365
/// Populated when hit() returns an error because of one
365366
/// of the files listed in the manifest.
366367
failed_file_index: ?usize = null,
@@ -843,7 +844,7 @@ pub const Manifest = struct {
843844
}
844845

845846
/// Returns a hex encoded hash of the inputs.
846-
pub fn final(self: *Manifest) [hex_digest_len]u8 {
847+
pub fn final(self: *Manifest) HexDigest {
847848
assert(self.manifest_file != null);
848849

849850
// We don't close the manifest file yet, because we want to
@@ -855,7 +856,7 @@ pub const Manifest = struct {
855856
var bin_digest: BinDigest = undefined;
856857
self.hash.hasher.final(&bin_digest);
857858

858-
var out_digest: [hex_digest_len]u8 = undefined;
859+
var out_digest: HexDigest = undefined;
859860
_ = fmt.bufPrint(
860861
&out_digest,
861862
"{s}",
@@ -1035,8 +1036,8 @@ test "cache file and then recall it" {
10351036
std.time.sleep(1);
10361037
}
10371038

1038-
var digest1: [hex_digest_len]u8 = undefined;
1039-
var digest2: [hex_digest_len]u8 = undefined;
1039+
var digest1: HexDigest = undefined;
1040+
var digest2: HexDigest = undefined;
10401041

10411042
{
10421043
var cache = Cache{
@@ -1103,8 +1104,8 @@ test "check that changing a file makes cache fail" {
11031104
std.time.sleep(1);
11041105
}
11051106

1106-
var digest1: [hex_digest_len]u8 = undefined;
1107-
var digest2: [hex_digest_len]u8 = undefined;
1107+
var digest1: HexDigest = undefined;
1108+
var digest2: HexDigest = undefined;
11081109

11091110
{
11101111
var cache = Cache{
@@ -1166,8 +1167,8 @@ test "no file inputs" {
11661167

11671168
const temp_manifest_dir = "no_file_inputs_manifest_dir";
11681169

1169-
var digest1: [hex_digest_len]u8 = undefined;
1170-
var digest2: [hex_digest_len]u8 = undefined;
1170+
var digest1: HexDigest = undefined;
1171+
var digest2: HexDigest = undefined;
11711172

11721173
var cache = Cache{
11731174
.gpa = testing.allocator,
@@ -1225,9 +1226,9 @@ test "Manifest with files added after initial hash work" {
12251226
std.time.sleep(1);
12261227
}
12271228

1228-
var digest1: [hex_digest_len]u8 = undefined;
1229-
var digest2: [hex_digest_len]u8 = undefined;
1230-
var digest3: [hex_digest_len]u8 = undefined;
1229+
var digest1: HexDigest = undefined;
1230+
var digest2: HexDigest = undefined;
1231+
var digest3: HexDigest = undefined;
12311232

12321233
{
12331234
var cache = Cache{

lib/std/Build/Step/Run.zig

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub fn addDepFileOutputArg(self: *Run, basename: []const u8) std.Build.LazyPath
243243
/// Add a prefixed path argument to a dep file (.d) for the child process to
244244
/// write its discovered additional dependencies.
245245
/// Only one dep file argument is allowed by instance.
246-
pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []const u8) void {
246+
pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []const u8) std.Build.LazyPath {
247247
assert(self.dep_output_file == null);
248248

249249
const b = self.step.owner;
@@ -258,6 +258,8 @@ pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []c
258258
self.dep_output_file = dep_file;
259259

260260
self.argv.append(.{ .output = dep_file }) catch @panic("OOM");
261+
262+
return .{ .generated = &dep_file.generated_file };
261263
}
262264

263265
pub fn addArg(self: *Run, arg: []const u8) void {
@@ -448,17 +450,18 @@ fn checksContainStderr(checks: []const StdIo.Check) bool {
448450
return false;
449451
}
450452

453+
const IndexedOutput = struct {
454+
index: usize,
455+
output: *Output,
456+
};
451457
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
452458
const b = step.owner;
453459
const arena = b.allocator;
454460
const self = @fieldParentPtr(Run, "step", step);
455461
const has_side_effects = self.hasSideEffects();
456462

457463
var argv_list = ArrayList([]const u8).init(arena);
458-
var output_placeholders = ArrayList(struct {
459-
index: usize,
460-
output: *Output,
461-
}).init(arena);
464+
var output_placeholders = ArrayList(IndexedOutput).init(arena);
462465

463466
var man = b.cache.obtain();
464467
defer man.deinit();
@@ -540,32 +543,25 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
540543
if (try step.cacheHit(&man)) {
541544
// cache hit, skip running command
542545
const digest = man.final();
543-
for (output_placeholders.items) |placeholder| {
544-
placeholder.output.generated_file.path = try b.cache_root.join(arena, &.{
545-
"o", &digest, placeholder.output.basename,
546-
});
547-
}
548546

549-
if (self.captured_stdout) |output| {
550-
output.generated_file.path = try b.cache_root.join(arena, &.{
551-
"o", &digest, output.basename,
552-
});
553-
}
554-
555-
if (self.captured_stderr) |output| {
556-
output.generated_file.path = try b.cache_root.join(arena, &.{
557-
"o", &digest, output.basename,
558-
});
559-
}
547+
try populateGeneratedPaths(
548+
arena,
549+
output_placeholders.items,
550+
self.captured_stdout,
551+
self.captured_stderr,
552+
b.cache_root,
553+
&digest,
554+
);
560555

561556
step.result_cached = true;
562557
return;
563558
}
564559

565-
const digest = man.final();
560+
const rand_int = std.crypto.random.int(u64);
561+
const tmp_dir_path = "tmp" ++ fs.path.sep_str ++ std.Build.hex64(rand_int);
566562

567563
for (output_placeholders.items) |placeholder| {
568-
const output_components = .{ "o", &digest, placeholder.output.basename };
564+
const output_components = .{ tmp_dir_path, placeholder.output.basename };
569565
const output_sub_path = try fs.path.join(arena, &output_components);
570566
const output_sub_dir_path = fs.path.dirname(output_sub_path).?;
571567
b.cache_root.handle.makePath(output_sub_dir_path) catch |err| {
@@ -582,12 +578,83 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
582578
argv_list.items[placeholder.index] = cli_arg;
583579
}
584580

585-
try runCommand(self, argv_list.items, has_side_effects, &digest, prog_node);
581+
try runCommand(self, argv_list.items, has_side_effects, tmp_dir_path, prog_node);
586582

587583
if (self.dep_output_file) |dep_output_file|
588584
try man.addDepFilePost(std.fs.cwd(), dep_output_file.generated_file.getPath());
589585

586+
const digest = man.final();
587+
588+
const any_output = output_placeholders.items.len > 0 or
589+
self.captured_stdout != null or self.captured_stderr != null;
590+
591+
// Rename into place
592+
if (any_output) {
593+
const o_sub_path = "o" ++ fs.path.sep_str ++ &digest;
594+
595+
b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |err| {
596+
if (err == error.PathAlreadyExists) {
597+
b.cache_root.handle.deleteTree(o_sub_path) catch |del_err| {
598+
return step.fail("unable to remove dir '{}'{s}: {s}", .{
599+
b.cache_root,
600+
tmp_dir_path,
601+
@errorName(del_err),
602+
});
603+
};
604+
b.cache_root.handle.rename(tmp_dir_path, o_sub_path) catch |retry_err| {
605+
return step.fail("unable to rename dir '{}{s}' to '{}{s}': {s}", .{
606+
b.cache_root, tmp_dir_path,
607+
b.cache_root, o_sub_path,
608+
@errorName(retry_err),
609+
});
610+
};
611+
} else {
612+
return step.fail("unable to rename dir '{}{s}' to '{}{s}': {s}", .{
613+
b.cache_root, tmp_dir_path,
614+
b.cache_root, o_sub_path,
615+
@errorName(err),
616+
});
617+
}
618+
};
619+
}
620+
590621
try step.writeManifest(&man);
622+
623+
try populateGeneratedPaths(
624+
arena,
625+
output_placeholders.items,
626+
self.captured_stdout,
627+
self.captured_stderr,
628+
b.cache_root,
629+
&digest,
630+
);
631+
}
632+
633+
fn populateGeneratedPaths(
634+
arena: std.mem.Allocator,
635+
output_placeholders: []const IndexedOutput,
636+
captured_stdout: ?*Output,
637+
captured_stderr: ?*Output,
638+
cache_root: Build.Cache.Directory,
639+
digest: *const Build.Cache.HexDigest,
640+
) !void {
641+
for (output_placeholders) |placeholder| {
642+
placeholder.output.generated_file.path = try cache_root.join(arena, &.{
643+
"o", digest, placeholder.output.basename,
644+
});
645+
}
646+
647+
if (captured_stdout) |output| {
648+
output.generated_file.path = try cache_root.join(arena, &.{
649+
"o", digest, output.basename,
650+
});
651+
}
652+
653+
if (captured_stderr) |output| {
654+
output.generated_file.path = try cache_root.join(arena, &.{
655+
"o", digest, output.basename,
656+
});
657+
}
591658
}
592659

593660
fn formatTerm(
@@ -639,7 +706,7 @@ fn runCommand(
639706
self: *Run,
640707
argv: []const []const u8,
641708
has_side_effects: bool,
642-
digest: ?*const [std.Build.Cache.hex_digest_len]u8,
709+
tmp_dir_path: ?[]const u8,
643710
prog_node: *std.Progress.Node,
644711
) !void {
645712
const step = &self.step;
@@ -812,7 +879,7 @@ fn runCommand(
812879
},
813880
}) |stream| {
814881
if (stream.captured) |output| {
815-
const output_components = .{ "o", digest.?, output.basename };
882+
const output_components = .{ tmp_dir_path.?, output.basename };
816883
const output_path = try b.cache_root.join(arena, &output_components);
817884
output.generated_file.path = output_path;
818885

lib/std/debug.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ test "machoSearchSymbols" {
853853
.{ .addr = 300, .strx = undefined, .size = undefined, .ofile = undefined },
854854
};
855855

856-
try testing.expectEqual(@as(?*const MachoSymbol, null), machoSearchSymbols(&symbols, 0));
857-
try testing.expectEqual(@as(?*const MachoSymbol, null), machoSearchSymbols(&symbols, 99));
856+
try testing.expectEqual(null, machoSearchSymbols(&symbols, 0));
857+
try testing.expectEqual(null, machoSearchSymbols(&symbols, 99));
858858
try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 100).?);
859859
try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 150).?);
860860
try testing.expectEqual(&symbols[0], machoSearchSymbols(&symbols, 199).?);

lib/std/http.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ pub const Status = enum(u10) {
283283
}
284284

285285
test {
286-
try std.testing.expectEqual(@as(?Status.Class, Status.Class.success), Status.ok.class());
287-
try std.testing.expectEqual(@as(?Status.Class, Status.Class.client_error), Status.not_found.class());
286+
try std.testing.expectEqual(Status.Class.success, Status.ok.class());
287+
try std.testing.expectEqual(Status.Class.client_error, Status.not_found.class());
288288
}
289289
};
290290

lib/std/json/static_test.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,19 @@ test "test all types" {
373373
test "parse" {
374374
try testing.expectEqual(false, try parseFromSliceLeaky(bool, testing.allocator, "false", .{}));
375375
try testing.expectEqual(true, try parseFromSliceLeaky(bool, testing.allocator, "true", .{}));
376-
try testing.expectEqual(@as(u1, 1), try parseFromSliceLeaky(u1, testing.allocator, "1", .{}));
376+
try testing.expectEqual(1, try parseFromSliceLeaky(u1, testing.allocator, "1", .{}));
377377
try testing.expectError(error.Overflow, parseFromSliceLeaky(u1, testing.allocator, "50", .{}));
378-
try testing.expectEqual(@as(u64, 42), try parseFromSliceLeaky(u64, testing.allocator, "42", .{}));
379-
try testing.expectEqual(@as(f64, 42), try parseFromSliceLeaky(f64, testing.allocator, "42.0", .{}));
380-
try testing.expectEqual(@as(?bool, null), try parseFromSliceLeaky(?bool, testing.allocator, "null", .{}));
381-
try testing.expectEqual(@as(?bool, true), try parseFromSliceLeaky(?bool, testing.allocator, "true", .{}));
378+
try testing.expectEqual(42, try parseFromSliceLeaky(u64, testing.allocator, "42", .{}));
379+
try testing.expectEqual(42, try parseFromSliceLeaky(f64, testing.allocator, "42.0", .{}));
380+
try testing.expectEqual(null, try parseFromSliceLeaky(?bool, testing.allocator, "null", .{}));
381+
try testing.expectEqual(true, try parseFromSliceLeaky(?bool, testing.allocator, "true", .{}));
382382

383-
try testing.expectEqual(@as([3]u8, "foo".*), try parseFromSliceLeaky([3]u8, testing.allocator, "\"foo\"", .{}));
384-
try testing.expectEqual(@as([3]u8, "foo".*), try parseFromSliceLeaky([3]u8, testing.allocator, "[102, 111, 111]", .{}));
385-
try testing.expectEqual(@as([0]u8, undefined), try parseFromSliceLeaky([0]u8, testing.allocator, "[]", .{}));
383+
try testing.expectEqual("foo".*, try parseFromSliceLeaky([3]u8, testing.allocator, "\"foo\"", .{}));
384+
try testing.expectEqual("foo".*, try parseFromSliceLeaky([3]u8, testing.allocator, "[102, 111, 111]", .{}));
385+
try testing.expectEqual(undefined, try parseFromSliceLeaky([0]u8, testing.allocator, "[]", .{}));
386386

387-
try testing.expectEqual(@as(u64, 12345678901234567890), try parseFromSliceLeaky(u64, testing.allocator, "\"12345678901234567890\"", .{}));
388-
try testing.expectEqual(@as(f64, 123.456), try parseFromSliceLeaky(f64, testing.allocator, "\"123.456\"", .{}));
387+
try testing.expectEqual(12345678901234567890, try parseFromSliceLeaky(u64, testing.allocator, "\"12345678901234567890\"", .{}));
388+
try testing.expectEqual(123.456, try parseFromSliceLeaky(f64, testing.allocator, "\"123.456\"", .{}));
389389
}
390390

391391
test "parse into enum" {
@@ -394,9 +394,9 @@ test "parse into enum" {
394394
Bar,
395395
@"with\\escape",
396396
};
397-
try testing.expectEqual(@as(T, .Foo), try parseFromSliceLeaky(T, testing.allocator, "\"Foo\"", .{}));
398-
try testing.expectEqual(@as(T, .Foo), try parseFromSliceLeaky(T, testing.allocator, "42", .{}));
399-
try testing.expectEqual(@as(T, .@"with\\escape"), try parseFromSliceLeaky(T, testing.allocator, "\"with\\\\escape\"", .{}));
397+
try testing.expectEqual(.Foo, try parseFromSliceLeaky(T, testing.allocator, "\"Foo\"", .{}));
398+
try testing.expectEqual(.Foo, try parseFromSliceLeaky(T, testing.allocator, "42", .{}));
399+
try testing.expectEqual(.@"with\\escape", try parseFromSliceLeaky(T, testing.allocator, "\"with\\\\escape\"", .{}));
400400
try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "5", .{}));
401401
try testing.expectError(error.InvalidEnumTag, parseFromSliceLeaky(T, testing.allocator, "\"Qux\"", .{}));
402402
}

lib/std/math.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
12661266
}
12671267

12681268
test "lerp" {
1269+
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884
12691270
if (builtin.zig_backend == .stage2_x86_64 and
12701271
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest;
12711272

0 commit comments

Comments
 (0)