Skip to content

Commit

Permalink
Adds a fallback to build_all when csources fails (#1245)
Browse files Browse the repository at this point in the history
* Adds a fallback to `build_all` when `csources` fails

* reverse test

* fixes nimenv regression
  • Loading branch information
jmgomez authored Jul 23, 2024
1 parent 3b119f6 commit ef840b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/nimblepkg/nimenv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,35 @@ proc compileNim*(options: Options, nimDest: string, v: VersionRange) =
else:
"csources_v1"
cd workspace:
echo "Entering CSOURCES", csourcesVersion, " exists ", dirExists(csourcesVersion)
if not dirExists(csourcesVersion):
exec "git clone https://github.com/nim-lang/" & csourcesVersion

var csourcesSucceed = false
cd workspace / csourcesVersion:
when defined(windows):
exec "build.bat"
let cmd = "build.bat"
csourcesSucceed = os.execShellCmd(cmd) == 0
else:
let makeExe = findExe("make")
if makeExe.len == 0:
exec "sh build.sh"
let cmd = "sh build.sh"
csourcesSucceed = os.execShellCmd(cmd) == 0
else:
exec "make"
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt)
let cmd = "make"
csourcesSucceed = os.execShellCmd(cmd) == 0

cd nimDest:
#Sometimes building from csources fails and we cant do much about it. So we fallback to the slow build_all method
if not csourcesSucceed:
display("Warning", "Building nim from csources failed. Using `build_all`", Warning, HighPriority)
let cmd =
when defined(windows): "build_all.bat"
else: "sh build_all.sh"
exec cmd
let nimExe = "bin" / "nim".addFileExt(ExeExt)
copyFileWithPermissions nimExe0, nimExe
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt)
if csourcesSucceed:
copyFileWithPermissions nimExe0, nimExe
exec nimExe & " c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch"
let kochExe = when defined(windows): "koch.exe" else: "./koch"
exec kochExe & " boot -d:release --skipUserCfg --skipParentCfg --hints:off"
Expand Down
1 change: 1 addition & 0 deletions tests/tniminstall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ suite "Nim install":
echo "Checking version ", nimVer
let (_, exitCode) = execNimble("install", "-l")
let pkgPath = getCurrentDir() / "nimbledeps" / "pkgs2"
echo "Checking ", pkgPath
check exitCode == QuitSuccess
check walkDir(pkgPath).toSeq.anyIt(it[1].isNimPkgVer(nimVer))

0 comments on commit ef840b4

Please sign in to comment.