about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Pernsteiner <spernsteiner@mozilla.com>2014-08-29 12:46:04 -0700
committerStuart Pernsteiner <spernsteiner@mozilla.com>2014-09-05 09:18:57 -0700
commit4d9a4786163a9a9831bf4e283b4e408be03a169b (patch)
treee1d42ddf0a71df13a8c38331d4e7f2e2d93a9f01
parent1b676fb7603cd2aa4e0506cb5b67d48c9da1123f (diff)
add workaround for mingw `ld --force-exe-suffix` behavior
-rw-r--r--src/librustc/back/write.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs
index d87dd84bb32..506d3585016 100644
--- a/src/librustc/back/write.rs
+++ b/src/librustc/back/write.rs
@@ -607,6 +607,19 @@ pub fn run_passes(sess: &Session,
     };
 
     let link_obj = |output_path: &Path| {
+        // Some builds of MinGW GCC will pass --force-exe-suffix to ld, which
+        // will automatically add a .exe extension if the extension is not
+        // already .exe or .dll.  To ensure consistent behavior on Windows, we
+        // add the .exe suffix explicitly and then rename the output file to
+        // the desired path.  This will give the correct behavior whether or
+        // not GCC adds --force-exe-suffix.
+        let windows_output_path =
+            if sess.targ_cfg.os == abi::OsWindows {
+                Some(output_path.with_extension("o.exe"))
+            } else {
+                None
+            };
+
         let pname = get_cc_prog(sess);
         let mut cmd = Command::new(pname.as_slice());
 
@@ -617,7 +630,9 @@ pub fn run_passes(sess: &Session,
             cmd.arg(crate_output.with_extension(format!("{}.o", index).as_slice()));
         }
 
-        cmd.arg("-r").arg("-o").arg(output_path);
+        cmd.arg("-r")
+           .arg("-o")
+           .arg(windows_output_path.as_ref().unwrap_or(output_path));
 
         if (sess.opts.debugging_opts & config::PRINT_LINK_ARGS) != 0 {
             println!("{}", &cmd);
@@ -635,6 +650,15 @@ pub fn run_passes(sess: &Session,
                 sess.abort_if_errors();
             },
         }
+
+        match windows_output_path {
+            Some(ref windows_path) => {
+                fs::rename(windows_path, output_path).unwrap();
+            },
+            None => {
+                // The file is already named according to `output_path`.
+            }
+        }
     };
 
     // Flag to indicate whether the user explicitly requested bitcode.