Add tests for conan, recurse implies preprocess
This commit is contained in:
parent
6d256d1271
commit
c63d82bf77
5 changed files with 77 additions and 10 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
46
tests/libssh2.nim
Normal file
46
tests/libssh2.nim
Normal file
|
|
@ -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:
|
||||
""
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue