summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/extccomp.nim38
-rw-r--r--compiler/nim.nim8
2 files changed, 29 insertions, 17 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index f3f74ece8..a9faefe7b 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -763,6 +763,13 @@ proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx:
       rawMessage(conf, errGenerated, "execution of an external program failed: '$1'" %
         cmds.join())
 
+proc minimizeObjfileNameLen(fullObjName: AbsoluteFile, conf: ConfigRef): string =
+  # For OSes with command line length limitations we try to use relative
+  # paths over absolute ones:
+  result = relativeTo(fullObjName, getNimcacheDir(conf)).string
+  if result.len >= fullObjName.string.len:
+    result = fullObjName.string
+
 proc callCCompiler*(conf: ConfigRef; projectfile: AbsoluteFile) =
   var
     linkCmd: string
@@ -783,19 +790,24 @@ proc callCCompiler*(conf: ConfigRef; projectfile: AbsoluteFile) =
   if optNoLinking notin conf.globalOptions:
     # call the linker:
     var objfiles = ""
-    for it in conf.externalToLink:
-      let objFile = if noAbsolutePaths(conf): it.extractFilename else: it
-      add(objfiles, ' ')
-      add(objfiles, quoteShell(
-          addFileExt(objFile, CC[conf.cCompiler].objExt)))
-    for x in conf.toCompile:
-      let objFile = if noAbsolutePaths(conf): x.obj.extractFilename else: x.obj.string
-      add(objfiles, ' ')
-      add(objfiles, quoteShell(objFile))
-
-    linkCmd = getLinkCmd(conf, projectfile, objfiles)
-    if optCompileOnly notin conf.globalOptions:
-      execLinkCmd(conf, linkCmd)
+    let oldCwd = getCurrentDir()
+    try:
+      setCurrentDir(getNimcacheDir(conf).string)
+      for it in conf.externalToLink:
+        let objFile = if noAbsolutePaths(conf): it.extractFilename else: it
+        add(objfiles, ' ')
+        let fullObjName = AbsoluteFile addFileExt(objFile, CC[conf.cCompiler].objExt)
+        add(objfiles, quoteShell(minimizeObjfileNameLen(fullObjName, conf)))
+      for x in conf.toCompile:
+        let objFile = if noAbsolutePaths(conf): x.obj.extractFilename.AbsoluteFile else: x.obj
+        add(objfiles, ' ')
+        add(objfiles, quoteShell(minimizeObjfileNameLen(objFile, conf)))
+
+      linkCmd = getLinkCmd(conf, projectfile, objfiles)
+      if optCompileOnly notin conf.globalOptions:
+        execLinkCmd(conf, linkCmd)
+    finally:
+      setCurrentDir(oldCwd)
   else:
     linkCmd = ""
   if optGenScript in conf.globalOptions:
diff --git a/compiler/nim.nim b/compiler/nim.nim
index 1c4dbd3be..cbd9d6f39 100644
--- a/compiler/nim.nim
+++ b/compiler/nim.nim
@@ -9,14 +9,14 @@
 
 when defined(gcc) and defined(windows):
   when defined(x86):
-    {.link: "icons/nim.res".}
+    {.link: "../icons/nim.res".}
   else:
-    {.link: "icons/nim_icon.o".}
+    {.link: "../icons/nim_icon.o".}
 
 when defined(amd64) and defined(windows) and defined(vcc):
-  {.link: "icons/nim-amd64-windows-vcc.res".}
+  {.link: "../icons/nim-amd64-windows-vcc.res".}
 when defined(i386) and defined(windows) and defined(vcc):
-  {.link: "icons/nim-i386-windows-vcc.res".}
+  {.link: "../icons/nim-i386-windows-vcc.res".}
 
 import
   commands, lexer, condsyms, options, msgs, nversion, nimconf, ropes,
1'>241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311