summary refs log tree commit diff stats
path: root/compiler/nim.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-08-16 00:32:12 -0700
committerGitHub <noreply@github.com>2021-08-16 09:32:12 +0200
commit1acba63cb725a0eee8f8b02f585057e030ce6295 (patch)
tree61f0cd8f16cbf400e6deb9efaccde02a04c032af /compiler/nim.nim
parentb3e077863aa6985eebab0c37785ba127b3192c80 (diff)
downloadNim-1acba63cb725a0eee8f8b02f585057e030ce6295.tar.gz
cross compilation targetting windows now supports `nim r`: `nim r -d:mingw main` (#18682)
* cross compilation targetting windows now supports `nim r`: `nim r -d:mingw main`

* quoteShell

* address comment: remove `conf.getConfigVar("nimrun.exe")`
Diffstat (limited to 'compiler/nim.nim')
-rw-r--r--compiler/nim.nim20
1 files changed, 15 insertions, 5 deletions
diff --git a/compiler/nim.nim b/compiler/nim.nim
index 91b1bc2db..b8256d576 100644
--- a/compiler/nim.nim
+++ b/compiler/nim.nim
@@ -70,6 +70,13 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
         config.arguments.len > 0 and config.cmd notin {cmdTcc, cmdNimscript, cmdCrun}:
       rawMessage(config, errGenerated, errArgsNeedRunOption)
 
+proc getNimRunExe(conf: ConfigRef): string =
+  # xxx consider defining `conf.getConfigVar("nimrun.exe")` to allow users to
+  # customize the binary to run the command with, e.g. for custom `nodejs` or `wine`.
+  if conf.isDefined("mingw"):
+    if conf.isDefined("i386"): result = "wine"
+    elif conf.isDefined("amd64"): result = "wine64"
+
 proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
   let self = NimProg(
     supportsStdinFile: true,
@@ -95,18 +102,21 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
     let output = conf.absOutFile
     case conf.cmd
     of cmdBackends, cmdTcc:
-      var cmdPrefix = ""
+      let nimRunExe = getNimRunExe(conf)
+      var cmdPrefix: string
+      if nimRunExe.len > 0: cmdPrefix.add nimRunExe.quoteShell
       case conf.backend
       of backendC, backendCpp, backendObjc: discard
       of backendJs:
         # D20210217T215950:here this flag is needed for node < v15.0.0, otherwise
         # tasyncjs_fail` would fail, refs https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode
-        cmdPrefix = findNodeJs() & " --unhandled-rejections=strict "
+        if cmdPrefix.len == 0: cmdPrefix = findNodeJs().quoteShell
+        cmdPrefix.add " --unhandled-rejections=strict"
       else: doAssert false, $conf.backend
-      # No space before command otherwise on windows you'd get a cryptic:
-      # `The parameter is incorrect`
+      if cmdPrefix.len > 0: cmdPrefix.add " "
+        # without the `cmdPrefix.len > 0` check, on windows you'd get a cryptic:
+        # `The parameter is incorrect`
       execExternalProgram(conf, cmdPrefix & output.quoteShell & ' ' & conf.arguments)
-      # execExternalProgram(conf, cmdPrefix & ' ' & output.quoteShell & ' ' & conf.arguments)
     of cmdDocLike, cmdRst2html, cmdRst2tex: # bugfix(cmdRst2tex was missing)
       if conf.arguments.len > 0:
         # reserved for future use