Fix mode, toast output dir

This commit is contained in:
Ganesh Viswanathan 2020-04-28 12:52:08 -05:00
commit 76d9be756a
5 changed files with 16 additions and 5 deletions

View file

@ -7,7 +7,6 @@ license = "MIT"
bin = @["nimterop/toast"]
installDirs = @["nimterop"]
installFiles = @["config.nims"]
# Dependencies
requires "nim >= 0.20.2", "regex >= 0.14.1", "cligen >= 0.9.45"

View file

@ -100,6 +100,8 @@ proc getToastError(output: string): string =
# Filter out preprocessor errors
for line in output.splitLines():
if "fatal error:" in line.toLowerAscii:
if result.len == 0:
result = "\n\nFailed in preprocessing, check if `cIncludeDir()` is needed or compiler `mode` is correct (c/cpp)"
result &= "\n\nERROR:$1\n" % line.split("fatal error:")[1]
# Toast error
@ -135,7 +137,7 @@ proc getToast(fullpaths: seq[string], recurse: bool = false, dynlib: string = ""
let toastExe = toastExePath()
doAssert fileExists(toastExe), "toast not compiled: " & toastExe.sanitizePath &
" make sure 'nimble build' or 'nimble install' built it"
cmd &= &"{toastExe} --preprocess"
cmd &= &"{toastExe} --preprocess -m:{mode}"
if recurse:
cmd.add " --recurse"
@ -679,7 +681,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
echo "# Importing " & fullpath & " with c2nim"
let
output = getToast(@[fullpath], recurse, dynlib, noNimout = true)
output = getToast(@[fullpath], recurse, dynlib, mode, noNimout = true)
hash = output.hash().abs()
hpath = getProjectCacheDir("c2nimCache", forceClean = false) / "nimterop_" & $hash & ".h"
npath = hpath[0 .. hpath.rfind('.')] & "nim"

View file

@ -733,7 +733,7 @@ proc loadPlugin*(gState: State, sourcePath: string) =
else: getNimConfigFlags(getCurrentDir())
# Always set output to same directory as source, prevents override
outflags = &"--out:\"{pdll.extractFilename()}\" --outdir:\"{pdll.parentDir()}\""
outflags = &"--out:\"{pdll}\""
# Compile plugin as library with `markAndSweep` GC
cmd = &"{gState.nim.sanitizePath} c --app:lib --gc:markAndSweep {flags} {outflags} {sourcePath.sanitizePath}"

View file

@ -1,3 +1,5 @@
import os
# Workaround for C++ scanner.cc causing link error with other C obj files
when defined(MacOSX):
switch("clang.linkerexe", "g++")
@ -17,4 +19,7 @@ switch("path", "$nim")
# Case objects
when not defined(danger):
switch("define", "nimOldCaseObjects")
switch("define", "nimOldCaseObjects")
# Prevent outdir override
switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt))

5
tests/tsoloud.nims Normal file
View file

@ -0,0 +1,5 @@
# Workaround for C++ scanner.cc causing link error with other C obj files
when defined(MacOSX):
switch("clang.linkerexe", "g++")
else:
switch("gcc.linkerexe", "g++")