also looking at this
fix(build): select the core Zig project explicitly
#383
4 files
+44
-2
| @@ -0,0 +1,30 @@ | ||
| 1 | import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs' | |
| 2 | import { join, resolve } from 'node:path' | |
| 3 | import { resolveZig } from './zig' | |
| 4 | ||
| 5 | const source = resolve(import.meta.dir, '..') | |
| 6 | const zig = resolveZig(source) | |
| 7 | console.log('Tracked core project:', JSON.stringify({ file: join(source, 'packages/zig/build.zig'), exists: existsSync(join(source, 'packages/zig/build.zig')) })) | |
| 8 | // Keep the fixture on the checkout's volume. Hosted Windows keeps the | |
| 9 | // checkout on D: and the system temporary directory/compiler cache on C:. | |
| 10 | const root = mkdtempSync(join(source, '.zig-core-project-')) | |
| 11 | const core = join(root, 'packages', 'zig') | |
| 12 | try { | |
| 13 | mkdirSync(core, { recursive: true }) | |
| 14 | writeFileSync(join(root, 'pantry.lock'), readFileSync(join(source, 'pantry.lock'))) | |
| 15 | writeFileSync(join(root, 'package.json'), JSON.stringify({ version: '1.2.3' })) | |
| 16 | writeFileSync(join(root, 'build.zig'), 'const std=; pub fn build(b:*std.Build) void {_=b.standardOptimizeOption(.{});}\n') | |
| 17 | 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') | |
| 18 | const env = { ...process.env, CRAFT_ZIG: zig.path } | |
| 19 | const runner = join(root, 'runner.ts') | |
| 20 | writeFileSync(runner, `import {runZig} from ${JSON.stringify(join(source, 'scripts/zig.ts'))};process.exitCode=runZig(${JSON.stringify(root)},['--core','--versioned','build']);\n`) | |
| 21 | const result = Bun.spawnSync([process.execPath, runner], { cwd: root, env, stdout: 'pipe', stderr: 'pipe' }) | |
| 22 | console.log(result.stdout.toString(), result.stderr.toString()) | |
| 23 | // The root wrapper rejects -Dversion. A successful configure therefore | |
| 24 | // proves core selection even when Zig reuses its cached configuration. | |
| 25 | if (result.exitCode !== 0) | |
| 26 | throw new Error('The actual pinned compiler did not configure the selected core project with its package version.') | |
| 27 | } | |
| 28 | finally { | |
| 29 | rmSync(root, { recursive: true, force: true }) | |
| 30 | } | |