Skip to content

Commit

Permalink
Use nimble dump to find the lib path (#61)
Browse files Browse the repository at this point in the history
* Use nimble dump to find the lib path

* Bump version and add comments
  • Loading branch information
auxym authored Feb 18, 2023
1 parent c1b3d1b commit b12b1f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion picostdlib.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.3.2"
version = "0.3.3"
author = "Jason"
description = "Raspberry Pi Pico stdlib bindings/libraries"
license = "MIT"
Expand Down
18 changes: 15 additions & 3 deletions src/piconim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,29 @@ proc getLinkedLib(fileName: string): set[LinkableLib] =
else:
break

proc containsNimbaseh(dir: string): bool =
## Check if dir contains a file named nimbase.h
for (kind, path) in dir.walkDir:
if kind in {pcFile, pcLinkToFile} and path.extractFilename == "nimbase.h":
return true

proc getNimLibPath: string =
## Find the Nim "lib" path, which contains the nimbase.h file, using the
## "nim dump" command.
let (nimOutput, nimExitCode) = execCmdEx(
"nim --verbosity:0 --eval:\"import std/os; echo getCurrentCompilerExe()\"",
options={poUsePath}
"nim dump", options={poUsePath, poStdErrToStdOut}
)

if nimExitCode != 0:
echo nimOutput
picoError fmt"Error while trying to locate nim executable (exit code {nimExitCode})"

result = nimOutput.parentDir.parentDir / "lib"
for ln in nimOutput.splitLines:
if "lib" in ln and dirExists(ln) and ln.containsNimbaseh:
return ln

# If not found for some reason
picoError "Could not find the Nim lib path"

const cMakeIncludeTemplate = """
# This is a generated file do not modify it, 'piconim' makes it every run.
Expand Down

0 comments on commit b12b1f7

Please sign in to comment.