From a8ea96055d9d1276fff401ffb1866e1f34d6bc46 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Tue, 23 Jun 2020 23:20:15 -0500 Subject: [PATCH] dynlib allow path, don't delete project, fix proc inline comment --- CHANGES.md | 1 + README.md | 2 +- nimterop/build/getheader.nim | 6 ++++++ nimterop/toast.nim | 2 +- nimterop/toastlib/ast2.nim | 5 ++++- nimterop/toastlib/tshelp.nim | 8 +++++++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cedf5a5..bf4b50a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ https://github.com/nimterop/nimterop/compare/v0.5.9...v0.6.0 - `getHeader()` now detects and links against `.lib` files as part of enabling Conan.io. Not all `.lib` files are compatible with MinGW as already stated above but for those that work, this is a required capability. +- The `dynlib` command line parameter to `toast` and `cImport()` can also be the path to a shared library (dll|so|dylib) in place of a Nim const string containing the path. This allows for the traditional use case of passing `"xxxLPath"` to `cImport()` as well as simply passing the path to the library on the command line as is. This allows the creation of standalone cached wrappers as well as the usage of the `--check` and the `--stub` functionality that `toast` provides via `cImport()`. ## Version 0.5.0 diff --git a/README.md b/README.md index ca17b90..af8501a 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ Options: -C=, --convention= string "cdecl" calling convention for wrapped procs -d, --debug bool false enable debug output -D=, --defines= strings {} definitions to pass to preprocessor - -l=, --dynlib= string "" import symbols from library in specified Nim string + -l=, --dynlib= string "" {.dynlib.} pragma to import symbols - Nim const string or file path -f=, --feature= Features ast1 flags to enable experimental features -I=, --includeDirs= strings {} include directory to pass to preprocessor -m=, --mode= string "" language parser: c or cpp diff --git a/nimterop/build/getheader.nim b/nimterop/build/getheader.nim index 3852fbf..69741b0 100644 --- a/nimterop/build/getheader.nim +++ b/nimterop/build/getheader.nim @@ -392,6 +392,12 @@ macro getHeader*( else: getLocalPath(header, outdir) + static: + # Don't delete project + when not `nameStd` and (`nameGit` or `nameDL` or `nameConan` or `nameJBB`): + doAssert `outdir`.len != 0, "getHeader():outdir cannot be blank" + doAssert `outdir` != getProjectPath(), "getHeader():outdir cannot be the project path" + const `version`* {.strdefine.} = `verVal` `lname` = diff --git a/nimterop/toast.nim b/nimterop/toast.nim index 495e5d1..e8e14cc 100644 --- a/nimterop/toast.nim +++ b/nimterop/toast.nim @@ -240,7 +240,7 @@ when isMainModule: "convention": "calling convention for wrapped procs", "debug": "enable debug output", "defines": "definitions to pass to preprocessor", - "dynlib": "import symbols from library in specified Nim string", + "dynlib": "{.dynlib.} pragma to import symbols - Nim const string or file path", "feature": "flags to enable experimental features", "includeDirs": "include directory to pass to preprocessor", "mode": "language parser: c or cpp", diff --git a/nimterop/toastlib/ast2.nim b/nimterop/toastlib/ast2.nim index 701b0b4..0016e29 100644 --- a/nimterop/toastlib/ast2.nim +++ b/nimterop/toastlib/ast2.nim @@ -1805,7 +1805,10 @@ proc setupPragmas(gState: State, root: TSNode, fullpath: string) = # {.pragma: impnameDyn, dynlib: libname.} let dynPragma = gState.newPragma(root, "pragma", gState.getIdent(gState.impShort & "Dyn")) - gState.addPragma(root, dynPragma, "dynlib", gState.getIdent(gState.dynlib)) + if '.' in gState.dynlib: + gState.addPragma(root, dynPragma, "dynlib", newStrNode(nkStrLit, gState.dynlib)) + else: + gState.addPragma(root, dynPragma, "dynlib", gState.getIdent(gState.dynlib)) gState.pragmaSection.add dynPragma count += 1 diff --git a/nimterop/toastlib/tshelp.nim b/nimterop/toastlib/tshelp.nim index b055259..e7e8d75 100644 --- a/nimterop/toastlib/tshelp.nim +++ b/nimterop/toastlib/tshelp.nim @@ -154,7 +154,13 @@ proc firstChildInTree*(node: TSNode, ntype: string): TSNode = while not cnode.isNil: if cnode.getName() == ntype: return cnode - cnode = cnode[0] + if cnode.len != 0: + for i in 0 ..< cnode.len: + if cnode[i].getName() != "comment": + cnode = cnode[i] + break + else: + cnode = cnode[0] proc anyChildInTree*(node: TSNode, ntype: string): TSNode = # Search for node type anywhere in tree - depth first