Skip to content

Commit 92b46b4

Browse files
committed
workflow cleanup | find nim toolchain path without choosenim
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent 8b39a89 commit 92b46b4

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

.github/workflows/test.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323

24-
# - name: Use Git OpenSSL 1.1 on Windows
25-
# if: matrix.os == 'windows-latest'
26-
# shell: pwsh
27-
# run: |
28-
# "C:\Program Files\Git\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
29-
3024
- uses: jiro4989/setup-nim-action@v2
3125
with:
3226
nim-version: ${{ matrix.nim-version }}
@@ -39,9 +33,5 @@ jobs:
3933
- run: "npm install node-gyp -g"
4034
- run: "npm install cmake-js -g"
4135

42-
- name: "choosenim path"
43-
if: matrix.os == 'ubuntu-latest'
44-
run: "choosenim show path -y"
45-
4636
- run: nimble install denim@#head -Y
4737
- run: nimble test

src/denimpkg/commands/build.nim

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@ import kapsis/runtime
1515
import kapsis/interactive/prompts
1616
import ../utils
1717

18+
19+
proc detectNimToolchainPath(): string =
20+
# Detect the Nim toolchain path by parsing the output of `nim dump`
21+
let d = execCmdEx("nim dump")
22+
if d.exitCode != 0: return
23+
24+
# parse from bottom; nim prints final lib paths near the end
25+
let lines = d.output.splitLines()
26+
for i in countdown(lines.high, 0):
27+
var p = lines[i].strip()
28+
if p.len == 0:
29+
continue
30+
31+
# normalize quoted lines
32+
p = p.strip(chars = {'"', '\''})
33+
34+
# candidate A: line is ".../lib"
35+
if dirExists(p) and p.endsWith("/lib") or p.endsWith("\\lib"):
36+
let root = p.parentDir
37+
if fileExists(root / "lib" / "nimbase.h"):
38+
return root
39+
40+
if dirExists(p):
41+
let idx1 = p.rfind("/lib/")
42+
let idx2 = p.rfind("\\lib\\")
43+
let idx = max(idx1, idx2)
44+
if idx >= 0:
45+
let root = p[0 ..< idx].strip()
46+
if root.len > 0 and fileExists(root / "lib" / "nimbase.h"):
47+
return root
48+
1849
proc getNodeGypConfig(getNimPath: string, release: bool = false): JsonNode =
1950
return %* {
2051
"target_name": "main",
@@ -98,13 +129,14 @@ proc buildCommand*(v: Values) =
98129
QuitFailure.quit
99130
elif v.has("--verbose"):
100131
display(nimCmd.output)
101-
var getNimPath = execCmdEx("choosenim show path")
102-
if getNimPath.exitCode != 0:
103-
displayError("Can't find Nim path")
132+
let getNimPath = detectNimToolchainPath()
133+
if getNimPath.len == 0:
134+
displayError("Can't find Nim toolchain path (from `nim`/`nim dump`)")
135+
QuitFailure.quit
104136
QuitFailure.quit
105137
discard execProcess("ln", args = [
106138
"-s",
107-
strip(getNimPath.output) / "lib" / "nimbase.h",
139+
getNimPath / "lib" / "nimbase.h",
108140
cachePathDirectory
109141
], options={poStdErrToStdOut, poUsePath})
110142

@@ -143,7 +175,7 @@ proc buildCommand*(v: Values) =
143175
# When using `node-gyp`, we need to generate a `binding.gyp` file with
144176
# the correct configuration
145177
displayInfo("Building with node-gyp")
146-
var gyp = %* {"targets": [getNodeGypConfig(getNimPath.output.strip, v.has("-r"))]}
178+
var gyp = %* {"targets": [getNodeGypConfig(getNimPath, v.has("-r"))]}
147179
let jsonConfigPath = cachePathDirectory / entryFile.replace(".nim", ".json")
148180

149181
var jarr = newJArray()

0 commit comments

Comments
 (0)