fy

for example:

code

{.backend:cpp.}

config

compileTo:cpp

2017-08-04 08:14:53

Interestingly, you cannot do that for now. All you can do is to do something like

when not defined(cpp):
  {.error: "compile via the 'cpp' command".}

2017-08-05 21:43:41

With a sufficiently ugly hack, all things are possible...

import strutils

static:
  
  proc getNimCompilerCmdLine(): string =
    return staticRead("/proc/self/cmdline").replace('\0', ' ')
  
  const nimCompilerCmdLine = getNimCompilerCmdLine()
  
  proc getNimCompilerBackend(): string =
    result = nimCompilerCmdLine.split(' ')[1].toLowerAscii()
    if result == "compile": result = "c"
  
  proc forceNimCompilerBackend(newBackend: string) =
    let currentBackend = getNimCompilerBackend()
    if currentBackend == newBackend.toLowerAscii(): return
    var splitRestartCmdLine = nimCompilerCmdLine.split(' ')
    splitRestartCmdLine[1] = newBackend & " --forceBuild"
    let restartCmdLine = splitRestartCmdLine.join(" ")
    echo "Restarting the compiler with: `" & restartCmdLine & "`"
    echo '{'
    let restartEx = gorgeEx(restartCmdLine)
    echo restartEx.output
    echo '}'
    quit restartEx.exitCode
  
  forceNimCompilerBackend("js")


echo "This is printed at run-time."

2017-08-06 03:19:13
It would be nice to have though... I have take the liberty to open Issue #6201 on GitHub.
2017-08-08 11:25:16