diff --git a/README.md b/README.md index 716f5d0..68288fc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ __Installation__ Nimgen can be installed via [Nimble](https://github.com/nim-lang/nimble): -```> nimble install https://github.com/genotrance/nimgen``` +```> nimble install nimgen``` This will download, build and install nimgen in the standard Nimble package location, typically ~/.nimble. Once installed, it can be run just like c2nim. @@ -40,6 +40,9 @@ To see examples of nimgen in action check out the following wrappers:- * [nimssl](https://github.com/genotrance/nimssl) - OpenSSL wrapper * git sparse checkout * Compile C code into binary +* [nimssh2](https://github.com/genotrance/nimssh2) - libssh2 wrapper + * git sparse checkout + * Compile libssh2 in as static binary Nimgen only supports the ```gcc``` preprocessor at this time. Support for detecting and using other preprocessors is TBD. @@ -87,7 +90,7 @@ File wildcards such as *.nim, ssl*.h, etc. can be used to perform tasks across a _[sourcefile]_ -The following keys apply to library source code and help with generating the .nim files. -win, -lin and -osx can be used for OS specific tasks. E.g. dynlib-win +The following keys apply to library source code and help with generating the .nim files. -win, -lin and -osx can be used for OS specific tasks. E.g. dynlib-win, pragma-win ```recurse``` = find #include files and process them [default: false] @@ -107,6 +110,8 @@ Multiple entries for the all following keys are possible by appending any .strin ```compile``` = file or dir of files of source code to {.compile.} into generated .nim +```pragma``` = pragmas to define in generated .nim file. E.g. pragma = "passL: \"-lssl\"" => {.passL: "-lssl".} + ```dynlib``` = dynamic library to load at runtime for generated .nim procs The following keys apply to library source code (before processing) and generated .nim files (after processing) and allow manipulating the files as required to enable successful wrapping. They are not propagated to #include files when ```recurse = true```. diff --git a/nimgen.nim b/nimgen.nim index 4d3c8ab..b531e05 100644 --- a/nimgen.nim +++ b/nimgen.nim @@ -326,7 +326,7 @@ proc runCtags(file: string): string = proc runFile(file: string, cfgin: OrderedTableRef) -proc c2nim(fl, outfile, flags, ppflags: string, recurse, preprocess, ctags, defines: bool, dynlib, compile: seq[string] = @[]) = +proc c2nim(fl, outfile, flags, ppflags: string, recurse, preprocess, ctags, defines: bool, dynlib, compile, pragma: seq[string] = @[]) = var file = search(fl) if file == "": return @@ -369,11 +369,15 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, preprocess, ctags, defi var extflags = "" var passC = "" var outlib = "" + var outpragma = "" passC = "import strutils\n" for inc in INCLUDES: passC &= ("""{.passC: "-I\"" & gorge("nimble path $#").strip() & "/$#\"".}""" % [OUTPUT, inc]) & "\n" + for prag in pragma: + outpragma &= "{." & prag & ".}\n" + let fname = file.splitFile().name.replace(re"[\.\-]", "_") if dynlib.len() != 0: let win = "when defined(Windows):\n" @@ -430,6 +434,10 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, preprocess, ctags, defi else: prepend(outfile, compile(dir=cpl)) + # Add any pragmas + if outpragma != "": + prepend(outfile, outpragma) + # Add header file and include paths if passC != "": prepend(outfile, passC) @@ -455,13 +463,14 @@ proc runFile(file: string, cfgin: OrderedTableRef) = var srch = "" var compile: seq[string] = @[] var dynlib: seq[string] = @[] + var pragma: seq[string] = @[] for act in cfg.keys(): let (action, val) = getKey(act) if val == true: if action == "create": createDir(file.splitPath().head) writeFile(file, cfg[act]) - elif action in @["prepend", "append", "replace", "compile", "dynlib"] and sfile != "": + elif action in @["prepend", "append", "replace", "compile", "dynlib", "pragma"] and sfile != "": if action == "prepend": if srch != "": prepend(sfile, cfg[act], cfg[srch]) @@ -479,6 +488,8 @@ proc runFile(file: string, cfgin: OrderedTableRef) = compile.add(cfg[act]) elif action == "dynlib": dynlib.add(cfg[act]) + elif action == "pragma": + pragma.add(cfg[act]) srch = "" elif action == "search": srch = act @@ -510,7 +521,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) = ppflags = cfg[act] if not noprocess: - c2nim(file, getNimout(file), flags, ppflags, recurse, preprocess, ctags, defines, dynlib, compile) + c2nim(file, getNimout(file), flags, ppflags, recurse, preprocess, ctags, defines, dynlib, compile, pragma) proc runCfg(cfg: string) = if not fileExists(cfg): diff --git a/tests/nimgentest.nims b/tests/nimgentest.nims index c5644d0..085b597 100644 --- a/tests/nimgentest.nims +++ b/tests/nimgentest.nims @@ -1,7 +1,7 @@ import ospaths import strutils -for comp in @["nimbass", "nimfuzz", "nimssl"]: +for comp in @["nimbass", "nimfuzz", "nimssl", "nimssh2"]: withDir(".."/comp): exec "nimble install -y" exec "nimble test"