also looking at this
fix(build): select the core Zig project explicitly
#383
4 files
+44
-2
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.
| @@ -80,7 +80,9 @@ test('fails early for absent executables, invalid lock versions, and invalid com | ||
| 80 | 80 | test('forwards arguments, core working directory, package version and compiler exit status', () => { |
| 81 | 81 | const f = fixture() |
| 82 | 82 | expect(runZig(f.root, ['--core', '--versioned', 'build', '-Doptimize=ReleaseSafe', '-Dfoo=a b'], f.env)).toBe(23) |
| 83 | expect(JSON.parse(readFileSync(f.env.ZIG_TEST_LOG, 'utf8'))).toEqual({ cwd: join(f.root, 'packages/zig'), args: ['build', '-Doptimize=ReleaseSafe', '-Dfoo=a b', '-Dversion=1.2.3'] }) | |
| 83 | expect(JSON.parse(readFileSync(f.env.ZIG_TEST_LOG, 'utf8'))).toEqual({ cwd: join(f.root, 'packages/zig'), args: ['build', '--build-file', join(f.root, 'packages/zig/build.zig'), '-Doptimize=ReleaseSafe', '-Dfoo=a b', '-Dversion=1.2.3'] }) | |
| 84 | expect(runZig(f.root, ['--core', 'fmt', 'src/'], f.env)).toBe(23) | |
| 85 | expect(JSON.parse(readFileSync(f.env.ZIG_TEST_LOG, 'utf8'))).toEqual({ cwd: join(f.root, 'packages/zig'), args: ['fmt', 'src/'] }) | |
| 84 | 86 | expect(runZig(f.root, ['fmt', 'src/'], f.env)).toBe(23) |
| 85 | 87 | expect(JSON.parse(readFileSync(f.env.ZIG_TEST_LOG, 'utf8'))).toEqual({ cwd: f.root, args: ['fmt', 'src/'] }) |
| 86 | 88 | }) |
| @@ -59,10 +59,17 @@ export function runZig(root: string, args: string[], env: NodeJS.ProcessEnv = pr | ||
| 59 | 59 | const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) |
| 60 | 60 | command.push(`-Dversion=${version}`) |
| 61 | 61 | } |
| 62 | if (core && command[0] === 'build') { | |
| 63 | // Select the core project explicitly. A monorepo has another build.zig | |
| 64 | // at its root; compiler build discovery must not select that wrapper. | |
| 65 | command.splice(1, 0, '--build-file', join(root, 'packages/zig/build.zig')) | |
| 66 | } | |
| 62 | 67 | const zig = resolveZig(root, env) |
| 68 | const cwd = core ? join(root, 'packages/zig') : root | |
| 63 | 69 | console.error(`Zig ${zig.version}: ${zig.path}${zig.overridden ? ' (explicit unpinned override)' : ''}`) |
| 70 | console.error(`Zig project directory: ${cwd}`) | |
| 64 | 71 | const result = Bun.spawnSync([zig.path, ...command], { |
| 65 | cwd: core ? join(root, 'packages/zig') : root, | |
| 72 | cwd, | |
| 66 | 73 | env, |
| 67 | 74 | stdin: 'inherit', |
| 68 | 75 | stdout: 'inherit', |