From 76d9be756a540272cc7a910eb0730297643276f7 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Tue, 28 Apr 2020 12:52:08 -0500 Subject: Fix mode, toast output dir --- config.nims | 20 -------------------- nimterop.nimble | 1 - nimterop/cimport.nim | 6 ++++-- nimterop/getters.nim | 2 +- nimterop/toast.nims | 25 +++++++++++++++++++++++++ tests/tsoloud.nims | 5 +++++ 6 files changed, 35 insertions(+), 24 deletions(-) delete mode 100644 config.nims create mode 100644 nimterop/toast.nims create mode 100644 tests/tsoloud.nims diff --git a/config.nims b/config.nims deleted file mode 100644 index f5f7d21..0000000 --- a/config.nims +++ /dev/null @@ -1,20 +0,0 @@ -# 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++") - -# Workaround for NilAccessError crash on Windows #98 -# Could also help for OSX/Linux crash -switch("gc", "markAndSweep") - -# Retain stackTrace for clear errors -switch("stackTrace", "on") -switch("lineTrace", "on") - -# Path to compiler -switch("path", "$nim") - -# Case objects -when not defined(danger): - switch("define", "nimOldCaseObjects") \ No newline at end of file diff --git a/nimterop.nimble b/nimterop.nimble index e520c71..caaaf90 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -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" diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index 4afb27c..47dc0eb 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -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" diff --git a/nimterop/getters.nim b/nimterop/getters.nim index ebd3432..42a5a57 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -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}" diff --git a/nimterop/toast.nims b/nimterop/toast.nims new file mode 100644 index 0000000..94c9f20 --- /dev/null +++ b/nimterop/toast.nims @@ -0,0 +1,25 @@ +import os + +# 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++") + +# Workaround for NilAccessError crash on Windows #98 +# Could also help for OSX/Linux crash +switch("gc", "markAndSweep") + +# Retain stackTrace for clear errors +switch("stackTrace", "on") +switch("lineTrace", "on") + +# Path to compiler +switch("path", "$nim") + +# Case objects +when not defined(danger): + switch("define", "nimOldCaseObjects") + +# Prevent outdir override +switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt)) \ No newline at end of file diff --git a/tests/tsoloud.nims b/tests/tsoloud.nims new file mode 100644 index 0000000..3b6174b --- /dev/null +++ b/tests/tsoloud.nims @@ -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++") \ No newline at end of file -- cgit v1.2.3