ReviewOS

also looking at this

craft-native/craft

fix(native): preserve workspace sources and native overlay lifecycle

#384
Merged chris wants to merge codex/windows-zig-cache-diagnostics into main
20 files +500 -227

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

.github/workflows/ci.ymlmodified+1-0
Changes to .github/workflows/ci.yml
@@ -193,6 +193,7 @@ jobs:
193193 run: bun run build:core
194194
195195 - name: Verify pinned compiler core project selection
196 if: ${{ !cancelled() }}
196197 run: bun scripts/verify-zig-core-project.ts
197198
198199 - name: Stage pinned WebView2 loader
scripts/verify-zig-core-project.tsmodified+21-3
Changes to scripts/verify-zig-core-project.ts
@@ -1,20 +1,38 @@
1import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2import { join, resolve } from 'node:path'
1import { existsSync, mkdtempSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
2import { dirname, join, resolve } from 'node:path'
33import { resolveZig } from './zig'
4import { createHash } from 'node:crypto'
5import { cpus } from 'node:os'
46
57const source = resolve(import.meta.dir, '..')
68const zig = resolveZig(source)
7console.log('Tracked core project:', JSON.stringify({ file: join(source, 'packages/zig/build.zig'), exists: existsSync(join(source, 'packages/zig/build.zig')) }))
9const trackedBuild = join(source, 'packages/zig/build.zig')
10console.log('Tracked core project:', JSON.stringify({ file: trackedBuild, exists: existsSync(trackedBuild), sha256: createHash('sha256').update(readFileSync(trackedBuild)).digest('hex'), bun: Bun.version, executable: process.execPath, cpu: cpus()[0]?.model, platform: process.platform }))
11const zigLibrary = join(dirname(realpathSync(zig.path)), 'lib/std/zig.zig')
12console.log('Pinned compiler bytes:', JSON.stringify({ executable: zig.path, sha256: createHash('sha256').update(readFileSync(zig.path)).digest('hex'), library: zigLibrary, librarySha256: existsSync(zigLibrary) ? createHash('sha256').update(readFileSync(zigLibrary)).digest('hex') : null }))
813// Keep the fixture on the checkout's volume. Hosted Windows keeps the
914// checkout on D: and the system temporary directory/compiler cache on C:.
1015const root = mkdtempSync(join(source, '.zig-core-project-'))
1116const core = join(root, 'packages', 'zig')
1217try {
1318 mkdirSync(core, { recursive: true })
19 if (process.platform === 'win32') {
20 const volumes = Bun.spawnSync(['pwsh', '-NoProfile', '-NonInteractive', '-Command', 'Get-Volume | Where-Object { $_.DriveLetter -in @("C", "D") } | Select-Object DriveLetter,FileSystemType,HealthStatus | ConvertTo-Json -Compress'], { stdout: 'pipe', stderr: 'pipe' })
21 console.log('Native source/cache volumes:', volumes.stdout.toString(), volumes.stderr.toString())
22 }
23 const native = Bun.spawnSync([zig.path, 'run', join(source, 'scripts/zig-source-cache-probe.zig'), '--cache-dir', join(root, 'io-build-cache'), '--', join(source, 'packages/zig'), join(root, 'io-manifest-cache')], { cwd: join(source, 'packages/zig'), stdout: 'pipe', stderr: 'pipe' })
24 console.log('Native source/cache probe:', native.exitCode, native.stdout.toString(), native.stderr.toString())
25 if (native.exitCode !== 0) throw new Error('The pinned native source/cache I/O probe failed.')
1426 writeFileSync(join(root, 'pantry.lock'), readFileSync(join(source, 'pantry.lock')))
1527 writeFileSync(join(root, 'package.json'), JSON.stringify({ version: '1.2.3' }))
1628 writeFileSync(join(root, 'build.zig'), 'const std=; pub fn build(b:*std.Build) void {_=b.standardOptimizeOption(.{});}\n')
1729 writeFileSync(join(core, 'build.zig'), 'const std=; pub fn build(b:*std.Build) void {_=b.standardOptimizeOption(.{}); const version=b.option([]const u8,"version","version") orelse "missing"; std.debug.print("PROJECT_VERSION={s}\\n",.{version});}\n')
30 const manifest = { name: 'craft', fingerprint: '0xf45c4a848bf58c1c' }
31 writeFileSync(join(core, 'build.zig.zon'), `.{ .name=.${manifest.name}, .fingerprint=${manifest.fingerprint}, .version="1.2.3", .dependencies=.{ .fixture=.{ .path="../../dependency" } }, .paths=.{"build.zig","build.zig.zon"} }\n`)
32 const dependency = join(root, 'dependency')
33 mkdirSync(dependency)
34 writeFileSync(join(dependency, 'build.zig'), 'const std=; pub fn build(b:*std.Build) void {_=b;}\n')
35 writeFileSync(join(dependency, 'build.zig.zon'), `.{ .name=.${manifest.name}, .fingerprint=${manifest.fingerprint}, .version="0.0.1", .paths=.{"build.zig","build.zig.zon"} }\n`)
1836 const env = { ...process.env, CRAFT_ZIG: zig.path }
1937 const runner = join(root, 'runner.ts')
2038 writeFileSync(runner, `import {runZig} from ${JSON.stringify(join(source, 'scripts/zig.ts'))};process.exitCode=runZig(${JSON.stringify(root)},['--core','--versioned','build']);\n`)
scripts/zig-source-cache-probe.zigadded+49-0
Changes to scripts/zig-source-cache-probe.zig
@@ -0,0 +1,49 @@
1const std = ;
2const Io = std.Io;
3const Cache = std.Build.Cache;
4
5pub fn main(init: std.process.Init) !void {
6 const arena = init.arena.allocator();
7 const io = init.io;
8 const args = try init.minimal.args.toSlice(arena);
9 const cwd = try std.process.currentPathAlloc(io, arena);
10 std.debug.print("NATIVE_CWD={s}\n", .{cwd});
11 const source = try Io.Dir.cwd().openDir(io, args[1], .{});
12 defer source.close(io);
13 const file = source.openFile(io, "build.zig", .{}) catch |err| {
14 std.debug.print("SOURCE_OPEN={t}\n", .{err});
15 return err;
16 };
17 defer file.close(io);
18 const stat = file.stat(io) catch |err| {
19 std.debug.print("SOURCE_STAT={t}\n", .{err});
20 return err;
21 };
22 const contents = source.readFileAlloc(io, "build.zig", arena, .limited(1024 * 1024)) catch |err| {
23 std.debug.print("SOURCE_READ={t}\n", .{err});
24 return err;
25 };
26 std.debug.print("SOURCE_SIZE={d} READ_BYTES={d}\n", .{ stat.size, contents.len });
27 var cache: Cache = .{
28 .io = io,
29 .gpa = arena,
30 .manifest_dir = try Io.Dir.cwd().createDirPathOpen(io, args[2], .{}),
31 .cwd = cwd,
32 };
33 defer cache.manifest_dir.close(io);
34 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
35 for (0..4) |_| cache.addPrefix(.{ .path = args[1], .handle = source });
36 var manifest = cache.obtain();
37 defer manifest.deinit();
38 var check_diagnostic: Cache.Manifest.CheckDiagnostic = undefined;
39 _ = try manifest.check(&check_diagnostic, .none);
40 var diagnostic: Cache.Manifest.AddDiscoveredPathDiagnostic = .none;
41 manifest.addDiscoveredPath(.{
42 .discovered_path = .{ .prefixed = .{ .prefix = 4, .sub_path = "build.zig" } },
43 .diagnostic = &diagnostic,
44 }) catch |err| {
45 std.debug.print("SOURCE_CACHE={t} DETAILS={f}\n", .{ err, diagnostic });
46 return err;
47 };
48 std.debug.print("SOURCE_CACHE=passed\n", .{});
49}