diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-05-10 18:51:46 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-05-10 18:51:46 -0500 |
| commit | 7729ea93cab424ca629216aa52df289afc206a91 (patch) | |
| tree | 2012dd735e81d03e52e83847ae262f8ca1fee2f4 | |
| parent | 78d116b2050d538a11086912af2161da40681c52 (diff) | |
| download | nimterop-ccnim.tar.gz nimterop-ccnim.zip | |
Use $CC for gcc and user specified Nimccnim
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | nimterop/cimport.nim | 12 | ||||
| -rw-r--r-- | nimterop/getters.nim | 4 | ||||
| -rw-r--r-- | nimterop/globals.nim | 2 | ||||
| -rw-r--r-- | nimterop/toast.nim | 3 |
5 files changed, 18 insertions, 6 deletions
@@ -72,6 +72,7 @@ Usage: -I=, --includeDirs= strings {} include directory to pass to preprocessor -l=, --dynlib= string "" Import symbols from library in specified Nim string -O=, --symOverride= strings {} skip generating specified symbols + --nim= string "nim" use a particular Nim executable (default: $PATH/nim) --pluginSourcePath= string "" Nim file to build and load as a plugin -d, --debug bool false enable debug output -m=, --mode= string "cpp" language parser: c or cpp @@ -84,7 +85,7 @@ In order to use the tree-sitter C library, it has to be compiled into a separate Alternatively, the `cImport()` macro allows easier creation of wrappers in code. It runs `toast` on the specified header file and injects the generated wrapper content into the application at compile time. A few other helper procs are provided to influence this process. Output is cached to save time on subsequent runs. -`toast` can also be used to run the header through the preprocessor which cleans up the code considerably. Along with the recursion capability which runs through all #include files, one large simpler header file can be created which can then be processed with `toast` or even `c2nim` if so desired. +`toast` can also be used to run the header through the preprocessor which cleans up the code considerably. Along with the recursion capability which runs through all #include files, one large simpler header file can be created which can then be processed with `toast` or even `c2nim` if so desired. By default, the `$CC` environment variable is used. If not found, `toast` defaults to `gcc`. The tree-sitter library is limited as well - it may fail on some advanced language constructs but is designed to handle them gracefully since it is expected to have bad code while actively typing in an editor. When an error is detected, tree-sitter includes an ERROR node at that location in the AST. At this time, `cImport()` will complain and continue if it encounters any errors. Depending on how severe the errors are, compilation may succeed or fail. Glaring issues will be communicated to the tree-sitter team but their goals may not always align with those of this project. diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index 764fc10..5717ac3 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -115,7 +115,12 @@ proc getNimCheckError(output: string): tuple[tmpFile, errors: string] = doAssert fileExists(result.tmpFile), "Bad codegen - unable to write to TEMP: " & result.tmpFile let - (check, _) = gorgeEx("nim check " & result.tmpFile) + nim = + when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9): + getCurrentCompilerExe() + else: + "nim" + (check, _) = gorgeEx(&"{nim} check {result.tmpFile.quoteShell}") result.errors = "\n\n" & check @@ -144,6 +149,9 @@ proc getToast(fullpath: string, recurse: bool = false, dynlib: string = ""): str if gStateCT.symOverride.len != 0: cmd.add &" --symOverride={gStateCT.symOverride.join(\",\")}" + when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9): + cmd.add &" --nim:{getCurrentCompilerExe().quoteShell}" + if gStateCT.pluginSourcePath.nBl: cmd.add &" --pluginSourcePath={gStateCT.pluginSourcePath.quoteShell}" @@ -159,7 +167,7 @@ proc getGccPaths(mode = "c"): string = nul = when defined(Windows): "nul" else: "/dev/null" mmode = if mode == "cpp": "c++" else: mode - (result, ret) = gorgeEx("gcc -Wp,-v -x" & mmode & " " & nul) + (result, ret) = gorgeEx(&"""{getEnv("CC", "gcc")} -Wp,-v -x{mmode} {nul}""") macro cOverride*(body): untyped = ## When the wrapper code generated by nimterop is missing certain symbols or not diff --git a/nimterop/getters.nim b/nimterop/getters.nim index 6eaf049..1051e4f 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -198,7 +198,7 @@ proc removeStatic(content: string): string = proc getPreprocessor*(gState: State, fullpath: string, mode = "cpp"): string = var mmode = if mode == "cpp": "c++" else: mode - cmd = &"gcc -E -CC -dD -x{mmode} -w " + cmd = &"""{getEnv("CC", "gcc")} -E -CC -dD -x{mmode} -w """ rdata: seq[string] = @[] start = false @@ -392,7 +392,7 @@ proc loadPlugin*(gState: State, sourcePath: string) = pdll = sourcePath.dll if not fileExists(pdll) or sourcePath.getLastModificationTime() > pdll.getLastModificationTime(): - discard execAction("nim c --app:lib " & sourcePath.quoteShell) + discard execAction(&"{gState.nim.quoteShell} c --app:lib {sourcePath.quoteShell}") doAssert fileExists(pdll), "No plugin binary generated for " & sourcePath let lib = loadLib(pdll) diff --git a/nimterop/globals.nim b/nimterop/globals.nim index 2db31be..32a461c 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -57,7 +57,7 @@ type nocache*, nocomments*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool - code*, dynlib*, mode*, pluginSourcePath*: string + code*, dynlib*, mode*, nim*, pluginSourcePath*: string onSymbol*: OnSymbol diff --git a/nimterop/toast.nim b/nimterop/toast.nim index da903b0..6e38670 100644 --- a/nimterop/toast.nim +++ b/nimterop/toast.nim @@ -107,6 +107,7 @@ proc main( includeDirs: seq[string] = @[], dynlib: string = "", symOverride: seq[string] = @[], + nim: string = "nim", pluginSourcePath: string = "", debug = false, mode = modeDefault, @@ -124,6 +125,7 @@ proc main( includeDirs: includeDirs, dynlib: dynlib, symOverride: symOverride, + nim: nim, pluginSourcePath: pluginSourcePath, debug: debug, mode: mode, @@ -157,6 +159,7 @@ when isMainModule: "includeDirs": "include directory to pass to preprocessor", "dynlib": "Import symbols from library in specified Nim string", "symOverride": "skip generating specified symbols", + "nim": "use a particular Nim executable (default: $PATH/nim)", "pluginSourcePath": "Nim file to build and load as a plugin", "debug": "enable debug output", "mode": "language parser: c or cpp", |
