Skip to content

Commit 01e8a11

Browse files
zahclaude
andauthored
profile compile: stage wrapper config.nims at the profile dir (#13)
When repro_profile_compile invokes nim against a profile that lives outside the reprobuild source tree (e.g. C:\Users\admin\reprobuild-source\ on a Windows runner), nim's parent-walk for config.nims never reaches <repoRoot>/config.nims and the sibling-repo paths (NIMCRYPTO_SRC, BEARSSL_SRC, IO_MON_SRC, RUNQUOTA_SRC, ...) don't get added to --path:. Phase G's repro_project_dsl pulls in nimcrypto/sha2, so the production profile compile crashed with "cannot open file: nimcrypto/sha2" even after PR #12 added repro_project_dsl to ProfileNimPathLibs. Fix: synthesize a single-line wrapper config.nims at the profile's directory that "include"s the upstream config.nims. nim picks it up via the normal parent-walk and the env-var-driven sibling resolution kicks in. The wrapper is only created when one is absent (so we don't clobber an operator-supplied config) and is removed in a finally block. --no-verify: pre-existing prek migration-mode failure (no .pre-commit-config.yaml in repo, same as #12). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d75fe3d commit 01e8a11

1 file changed

Lines changed: 38 additions & 17 deletions

File tree

  • libs/repro_profile_compile/src/repro_profile_compile

libs/repro_profile_compile/src/repro_profile_compile/compile.nim

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ proc compileProfileBinary*(profileRoot, nimcacheDir, outBinary: string;
5959
createDir(extendedPath(nimcacheDir))
6060
createDir(extendedPath(outBinary.parentDir))
6161

62+
# Stage a wrapper config.nims next to the profile so nim's parent-walk
63+
# picks it up and pulls in reprobuild's config.nims (which resolves
64+
# sibling-repo paths from env vars: NIMCRYPTO_SRC, BEARSSL_SRC, IO_MON_SRC,
65+
# etc.). Without this, a profile at e.g. C:\Users\admin\reprobuild-source\
66+
# never sees reprobuild's config.nims, and transitive imports of
67+
# repro_project_dsl -> nimcrypto/sha2 fail with "cannot open file".
68+
let profileDir = profileRoot.parentDir
69+
let stagedConfig = profileDir / "config.nims"
70+
let upstreamConfig = repoRoot / "config.nims"
71+
var didStageConfig = false
72+
if fileExists(extendedPath(upstreamConfig)) and
73+
not fileExists(extendedPath(stagedConfig)):
74+
writeFile(extendedPath(stagedConfig),
75+
"include \"" & upstreamConfig.replace('\\', '/') & "\"\n")
76+
didStageConfig = true
77+
6278
var compileCmd = quoteShell(nimExe) & " c --hints:off --warnings:off" &
6379
" --nimcache:" & quoteShell(nimcacheDir) &
6480
" --out:" & quoteShell(outBinary)
@@ -68,23 +84,28 @@ proc compileProfileBinary*(profileRoot, nimcacheDir, outBinary: string;
6884
if verbose:
6985
stderr.writeLine("repro profile compile: " & compileCmd)
7086

71-
let compileRes = execCmdEx(compileCmd)
72-
if compileRes.exitCode != 0:
73-
var err = new CompileFailure
74-
err.msg = "nim compile failed for " & profileRoot &
75-
" (exit " & $compileRes.exitCode & ")"
76-
err.stderrText = compileRes.output
77-
raise err
78-
79-
let runRes = execCmdEx(quoteShell(outBinary))
80-
if runRes.exitCode != 0:
81-
var err = new CompileFailure
82-
err.msg = "compiled profile binary exited " & $runRes.exitCode &
83-
" for " & profileRoot
84-
err.stderrText = runRes.output
85-
raise err
86-
result.jsonOutput = runRes.output
87-
result.stderrText = compileRes.output
87+
try:
88+
let compileRes = execCmdEx(compileCmd)
89+
if compileRes.exitCode != 0:
90+
var err = new CompileFailure
91+
err.msg = "nim compile failed for " & profileRoot &
92+
" (exit " & $compileRes.exitCode & ")"
93+
err.stderrText = compileRes.output
94+
raise err
95+
96+
let runRes = execCmdEx(quoteShell(outBinary))
97+
if runRes.exitCode != 0:
98+
var err = new CompileFailure
99+
err.msg = "compiled profile binary exited " & $runRes.exitCode &
100+
" for " & profileRoot
101+
err.stderrText = runRes.output
102+
raise err
103+
result.jsonOutput = runRes.output
104+
result.stderrText = compileRes.output
105+
finally:
106+
if didStageConfig:
107+
try: removeFile(extendedPath(stagedConfig))
108+
except OSError: discard
88109

89110
proc rbpiBytesFromJson*(jsonText: string): seq[byte] =
90111
## Parse the JSON ProfileIntent emitted by the compiled profile and

0 commit comments

Comments
 (0)