aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-06-14 15:16:21 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-06-16 20:43:50 -0500
commite82f68297253ff18277b80b46b7ecd0c2cbf85f7 (patch)
tree817453ddc68dfa65b84905e61632cf6be278b631
parent12171d19e970b870a285b872bacebbe323a30c0b (diff)
downloadnimterop-e82f68297253ff18277b80b46b7ecd0c2cbf85f7.tar.gz
nimterop-e82f68297253ff18277b80b46b7ecd0c2cbf85f7.zip
Add tests for conan, recurse implies preprocess
-rw-r--r--nimterop/build.nim25
-rw-r--r--nimterop/conan.nim2
-rw-r--r--nimterop/toast.nim6
-rw-r--r--tests/getheader.nims8
-rw-r--r--tests/libssh2.nim46
5 files changed, 77 insertions, 10 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim
index fd7ad3a..d534cf9 100644
--- a/nimterop/build.nim
+++ b/nimterop/build.nim
@@ -1018,26 +1018,33 @@ macro getHeader*(
##
## This allows a single wrapper to be used in different ways depending on the user's needs.
## If no `-d:xxx` defines are specified, `outdir` will be searched for the header as is.
+ ## The user can opt to download the sources to `outdir` using any other method such as
+ ## git sub-modules, vendoring or pointing to a repository that was already cloned.
##
## If multiple `-d:xxx` defines are specified, precedence is `Std` and then `Git`, `DL` or
## `Conan`. This allows using a system installed library if available before falling back
- ## to manual building.
+ ## to manual building. The user would need to specify both `-d:xxxStd` and one of the other
+ ## methods.
##
## `-d:xxxSetVer=x.y.z` can be used to specify which version to use. It is used as a tag
## name for Git whereas for DL and Conan, it replaces `$1` in the URL defined.
##
- ## All defines can also be set in code using `setDefines()`.
+ ## All defines can also be set in code using `setDefines()` and checked for using
+ ## `isDefined()` which checks for defines set from both `-d` and `setDefines()`.
##
## The library is then configured (with `cmake` or `autotools` if possible) and built
## using `make`, unless using `-d:xxxStd` which presumes that the system package
- ## manager was used to install prebuilt headers and binaries.
+ ## manager was used to install prebuilt headers and binaries, or using `-d:xxxConan`
+ ## which downloads pre-built binaries.
##
## The header path is stored in `const xxxPath` and can be used in a `cImport()` call
## in the calling wrapper. The dynamic library path is stored in `const xxxLPath` and can
## be used for the `dynlib` parameter (within quotes) or with `{.passL.}`.
##
## `-d:xxxStatic` can be specified to statically link with the library instead. This
- ## will automatically add a `{.passL.}` call to the static library for convenience.
+ ## will automatically add a `{.passL.}` call to the static library for convenience. Note
+ ## that `-d:xxxConan` downloads all dependency libs as well and the `xxxLPath` will
+ ## include all separated by space in the right order for linking.
##
## `conFlags`, `cmakeFlags` and `makeFlags` allow sending custom parameters to `configure`,
## `cmake` and `make` in case additional configuration is required as part of the build process.
@@ -1047,19 +1054,19 @@ macro getHeader*(
## with cmake. In this case, `altNames = "z,zlib"`. Comma separate for multiple alternate names without
## spaces.
##
- ## `buildTypes` specifies a list of in order build strategies to use when building the downloaded source
- ## files. Default is [btCmake, btAutoconf]
- ##
## The original header name is not included by default if `altNames` is set since it could cause the
## wrong lib to be selected. E.g. `SDL2/SDL.h` could pick `libSDL.so` even if `altNames = "SDL2"`.
## Explicitly include it in `altNames` like the `zlib` example when required.
##
+ ## `buildTypes` specifies a list of ordered build strategies to use when building the downloaded source
+ ## files. Default is [btCmake, btAutoconf]
+ ##
## `xxxPreBuild` is a hook that is called after the source code is pulled from Git or downloaded but
## before the library is built. This might be needed if some initial prep needs to be done before
## compilation. A few values are provided to the hook to help provide context:
##
- ## `outdir` is the same `outdir` passed in and `header` is the discovered header path in the
- ## downloaded source code.
+ ## `outdir` is the same `outdir` passed in and `header` is the discovered header path in the
+ ## downloaded source code.
##
## Simply define `proc xxxPreBuild(outdir, header: string)` in the wrapper and it will get called
## prior to the build process.
diff --git a/nimterop/conan.nim b/nimterop/conan.nim
index 1a9237a..e9d23cb 100644
--- a/nimterop/conan.nim
+++ b/nimterop/conan.nim
@@ -342,6 +342,8 @@ proc downloadConan*(pkg: ConanPackage, outdir: string, clean = true) =
elif clean:
cleanDir(outdir)
+ echo &"# Downloading {pkg.name} v{pkg.version} from Conan"
+
pkg.getConanBuilds()
for recipe, builds in pkg.recipes:
diff --git a/nimterop/toast.nim b/nimterop/toast.nim
index 4a9553b..1844a56 100644
--- a/nimterop/toast.nim
+++ b/nimterop/toast.nim
@@ -123,6 +123,10 @@ proc main(
if check and outputFile.len == 0:
outputFile = getTempDir() / "toast_" & ($getTime().toUnix()).addFileExt("nim")
+ # Recurse implies preprocess
+ if gState.recurse:
+ gState.preprocess = true
+
# Redirect output to file
if outputFile.len != 0:
doAssert gState.outputHandle.open(outputFile, fmWrite),
@@ -248,7 +252,7 @@ when isMainModule:
"pnim": "print Nim output",
"prefix": "strip prefix from identifiers",
"preprocess": "run preprocessor on header",
- "recurse": "process #include files",
+ "recurse": "process #include files - implies --preprocess",
"replace": "replace X with Y in identifiers, X1=Y1,X2=Y2, @X for regex",
"source" : "C/C++ source/header(s) and command line file(s)",
"stub": "stub out undefined type references as objects",
diff --git a/tests/getheader.nims b/tests/getheader.nims
index 5d3b427..55d00f1 100644
--- a/tests/getheader.nims
+++ b/tests/getheader.nims
@@ -17,10 +17,12 @@ var
cmd = "nim c -f --hints:off -d:FLAGS=\"-f:ast2\" -d:checkAbi"
lrcmd = " -r lzma.nim"
zrcmd = " -r zlib.nim"
+ sshcmd = " -r libssh2.nim"
lexp = "liblzma version = "
zexp = "zlib version = "
testCall(cmd & lrcmd, "No build files found", 1)
+testCall(cmd & " -d:libssh2Conan" & sshcmd, "Need version for Conan uri", 1)
when defined(posix):
# stdlib
@@ -35,6 +37,9 @@ when defined(posix):
testCall(cmd & " -d:lzmaGit -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0)
testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaSetVer=v5.2.0" & lrcmd, lexp & "5.2.0", 0, delete = false)
+ # conan static
+ testCall(cmd & " -d:libssh2Conan -d:libssh2SetVer=1.9.0 -d:libssh2Static" & sshcmd, zexp, 0)
+
# git
testCall(cmd & " -d:envTest" & zrcmd, zexp, 0)
testCall(cmd & " -d:envTestStatic" & zrcmd, zexp, 0, delete = false)
@@ -51,3 +56,6 @@ testCall(cmd & " -d:lzmaDL -d:lzmaStatic -d:lzmaSetVer=5.2.4" & lrcmd, lexp & "5
# dl
testCall(cmd & " -d:zlibDL -d:zlibSetVer=1.2.11" & zrcmd, zexp & "1.2.11", 0)
testCall(cmd & " -d:zlibDL -d:zlibStatic -d:zlibSetVer=1.2.11" & zrcmd, zexp & "1.2.11", 0, delete = false)
+
+# conan
+testCall(cmd & " -d:libssh2Conan -d:libssh2SetVer=1.9.0" & sshcmd, zexp, 0)
diff --git a/tests/libssh2.nim b/tests/libssh2.nim
new file mode 100644
index 0000000..b7e591c
--- /dev/null
+++ b/tests/libssh2.nim
@@ -0,0 +1,46 @@
+import nimterop/[build, cimport]
+
+const
+ outdir = getProjectCacheDir("libssh2")
+
+getHeader(
+ header = "libssh2.h",
+ conanuri = "libssh2/$1",
+ outdir = outdir
+)
+
+cOverride:
+ type
+ stat = object
+ stat64 = object
+ SOCKET = object
+
+when not libssh2Static:
+ cImport(libssh2Path, recurse = true, dynlib = "libssh2LPath", flags = "-f:ast2 -c -E_ -F_")
+
+ when not defined(Windows):
+ proc zlibVersion(): cstring {.importc, dynlib: libssh2LPath.}
+else:
+ cImport(libssh2Path, recurse = true, flags = "-f:ast2 -c -E_ -F_")
+
+ when not defined(Windows):
+ proc zlibVersion(): cstring {.importc.}
+
+ {.passL: "-lpthread".}
+
+assert libssh2_init(0) == 0
+
+let
+ session = libssh2_session_init_ex(nil, nil, nil, nil)
+
+if session == nil:
+ quit(1)
+
+libssh2_session_set_blocking(session, 0.cint)
+
+echo "zlib version = " & (block:
+ when not defined(Windows):
+ $zlibVersion()
+ else:
+ ""
+) \ No newline at end of file