summaryrefslogtreecommitdiff
blob: 9bca3f57a0abbe611645f5f6baa77eacc1aaa65f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
https://bugzilla.mozilla.org/show_bug.cgi?id=1496270
https://bugzilla.mozilla.org/show_bug.cgi?id=1445528

--- a/third_party/rust/cc/.cargo-checksum.json
+++ b/third_party/rust/cc/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{".travis.yml":"1a4a3f7f90349924378e93acbb524b9127e37c02cfbc6dc59fd904bbdc1c8d0b","Cargo.toml":"623dd06a83bcbf2f292ab51af93e9b79b689e3be06a62968b79f4e36f1bb769f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"186c5c8a62520cb7a3d90d77161c954b52ae8456fca0e0669bc3a5b889592a43","appveyor.yml":"ab45bfdcf2596f357225a54e730c34d518a8f3ad56c2ed33af682cfd45bddc02","src/bin/gcc-shim.rs":"d6be9137cb48b86891e7b263adbf492e1193ffe682db9ba4a88eb1079b874b58","src/com.rs":"0cb06f5db0fb70d27db0e5917ca337de6e7032119e6aabfea1bad9c719f5f34b","src/lib.rs":"996b650e19d5ccd6e64e741789427017c913644e980862a7286ec4ed53c14a17","src/registry.rs":"3876ef9573e3bbc050aef41a684b9a510cc1a91b15ae874fe032cf4377b4d116","src/setup_config.rs":"1a3eeb11c6847c31f2a4685b62ab35c76f0b6d5a17f7ed99e9df164283a771f7","src/winapi.rs":"cb5e6cab3eb570b0f97c660ca448ccfb5024262c0c7b245c181daad91a79f211","src/windows_registry.rs":"6de548aa94215e449f0e58e9a3b1702939d7c2f7b63a9040901c948bf138201d","tests/cc_env.rs":"7402315eea7ffa23b29b393c1de8e236294ede9de562ff0a562704a157135341","tests/support/mod.rs":"092551f9f6e3a999fa0aa02f93314aac0bda2b09268f948c423df56a43575e0b","tests/test.rs":"b1164258714e13173f3861126e97bedf1e29aa24618993c4eb0edd57c431dcc7"},"package":"deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0"}
\ No newline at end of file
+{"files":{".travis.yml":"1a4a3f7f90349924378e93acbb524b9127e37c02cfbc6dc59fd904bbdc1c8d0b","Cargo.toml":"623dd06a83bcbf2f292ab51af93e9b79b689e3be06a62968b79f4e36f1bb769f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","README.md":"186c5c8a62520cb7a3d90d77161c954b52ae8456fca0e0669bc3a5b889592a43","appveyor.yml":"ab45bfdcf2596f357225a54e730c34d518a8f3ad56c2ed33af682cfd45bddc02","src/bin/gcc-shim.rs":"d6be9137cb48b86891e7b263adbf492e1193ffe682db9ba4a88eb1079b874b58","src/com.rs":"0cb06f5db0fb70d27db0e5917ca337de6e7032119e6aabfea1bad9c719f5f34b","src/lib.rs":"6e8cea99f5fc8e5982b1ea9a336ee2f9a6158a9498c8f0c36f1e8cee8c99716e","src/registry.rs":"3876ef9573e3bbc050aef41a684b9a510cc1a91b15ae874fe032cf4377b4d116","src/setup_config.rs":"1a3eeb11c6847c31f2a4685b62ab35c76f0b6d5a17f7ed99e9df164283a771f7","src/winapi.rs":"cb5e6cab3eb570b0f97c660ca448ccfb5024262c0c7b245c181daad91a79f211","src/windows_registry.rs":"6de548aa94215e449f0e58e9a3b1702939d7c2f7b63a9040901c948bf138201d","tests/cc_env.rs":"7402315eea7ffa23b29b393c1de8e236294ede9de562ff0a562704a157135341","tests/support/mod.rs":"092551f9f6e3a999fa0aa02f93314aac0bda2b09268f948c423df56a43575e0b","tests/test.rs":"b1164258714e13173f3861126e97bedf1e29aa24618993c4eb0edd57c431dcc7"},"package":"deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0"}
\ No newline at end of file
--- a/third_party/rust/cc/src/lib.rs
+++ b/third_party/rust/cc/src/lib.rs
@@ -61,15 +61,14 @@
 extern crate rayon;
 
 use std::env;
-use std::ffi::{OsString, OsStr};
+use std::ffi::{OsStr, OsString};
 use std::fs;
-use std::path::{PathBuf, Path};
-use std::process::{Command, Stdio, Child};
-use std::io::{self, BufReader, BufRead, Read, Write};
+use std::path::{Path, PathBuf};
+use std::process::{Child, Command, Stdio};
+use std::io::{self, BufRead, BufReader, Read, Write};
 use std::thread::{self, JoinHandle};
-
-#[cfg(feature = "parallel")]
-use std::sync::Mutex;
+use std::collections::HashMap;
+use std::sync::{Arc, Mutex};
 
 // These modules are all glue to support reading the MSVC version from
 // the registry and from COM interfaces
@@ -97,6 +96,7 @@ pub struct Build {
     objects: Vec<PathBuf>,
     flags: Vec<String>,
     flags_supported: Vec<String>,
+    known_flag_support_status: Arc<Mutex<HashMap<String, bool>>>,
     files: Vec<PathBuf>,
     cpp: bool,
     cpp_link_stdlib: Option<Option<String>>,
@@ -241,8 +241,7 @@ impl ToolFamily {
     fn nvcc_debug_flag(&self) -> &'static str {
         match *self {
             ToolFamily::Msvc => unimplemented!(),
-            ToolFamily::Gnu |
-            ToolFamily::Clang => "-G",
+            ToolFamily::Gnu | ToolFamily::Clang => "-G",
         }
     }
 
@@ -251,8 +250,7 @@ impl ToolFamily {
     fn nvcc_redirect_flag(&self) -> &'static str {
         match *self {
             ToolFamily::Msvc => unimplemented!(),
-            ToolFamily::Gnu |
-            ToolFamily::Clang => "-Xcompiler",
+            ToolFamily::Gnu | ToolFamily::Clang => "-Xcompiler",
         }
     }
 }
@@ -269,10 +267,7 @@ struct Object {
 impl Object {
     /// Create a new source file -> object file pair.
     fn new(src: PathBuf, dst: PathBuf) -> Object {
-        Object {
-            src: src,
-            dst: dst,
-        }
+        Object { src: src, dst: dst }
     }
 }
 
@@ -289,6 +284,7 @@ impl Build {
             objects: Vec::new(),
             flags: Vec::new(),
             flags_supported: Vec::new(),
+            known_flag_support_status: Arc::new(Mutex::new(HashMap::new())),
             files: Vec::new(),
             shared_flag: None,
             static_flag: None,
@@ -344,10 +340,8 @@ impl Build {
     ///     .compile("foo");
     /// ```
     pub fn define<'a, V: Into<Option<&'a str>>>(&mut self, var: &str, val: V) -> &mut Build {
-        self.definitions.push((
-            var.to_string(),
-            val.into().map(|s| s.to_string()),
-        ));
+        self.definitions
+            .push((var.to_string(), val.into().map(|s| s.to_string())));
         self
     }
 
@@ -398,7 +392,16 @@ impl Build {
     ///
     /// It may return error if it's unable to run the compilier with a test file
     /// (e.g. the compiler is missing or a write to the `out_dir` failed).
+    ///
+    /// Note: Once computed, the result of this call is stored in the
+    /// `known_flag_support` field. If `is_flag_supported(flag)`
+    /// is called again, the result will be read from the hash table.
     pub fn is_flag_supported(&self, flag: &str) -> Result<bool, Error> {
+        let mut known_status = self.known_flag_support_status.lock().unwrap();
+        if let Some(is_supported) = known_status.get(flag).cloned() {
+            return Ok(is_supported);
+        }
+
         let out_dir = self.get_out_dir()?;
         let src = self.ensure_check_file()?;
         let obj = out_dir.join("flag_check");
@@ -413,7 +416,8 @@ impl Build {
             .cuda(self.cuda);
         let compiler = cfg.try_get_compiler()?;
         let mut cmd = compiler.to_command();
-        command_add_output_file(&mut cmd, &obj, target.contains("msvc"), false);
+        let is_arm = target.contains("aarch64") || target.contains("arm");
+        command_add_output_file(&mut cmd, &obj, target.contains("msvc"), false, is_arm);
 
         // We need to explicitly tell msvc not to link and create an exe
         // in the root directory of the crate
@@ -424,7 +428,10 @@ impl Build {
         cmd.arg(&src);
 
         let output = cmd.output()?;
-        Ok(output.stderr.is_empty())
+        let is_supported = output.stderr.is_empty();
+
+        known_status.insert(flag.to_owned(), is_supported);
+        Ok(is_supported)
     }
 
     /// Add an arbitrary flag to the invocation of the compiler if it supports it
@@ -777,9 +784,8 @@ impl Build {
         A: AsRef<OsStr>,
         B: AsRef<OsStr>,
     {
-        self.env.push(
-            (a.as_ref().to_owned(), b.as_ref().to_owned()),
-        );
+        self.env
+            .push((a.as_ref().to_owned(), b.as_ref().to_owned()));
         self
     }
 
@@ -880,31 +886,19 @@ impl Build {
     fn compile_objects(&self, objs: &[Object]) -> Result<(), Error> {
         use self::rayon::prelude::*;
 
-        let mut cfg = rayon::Configuration::new();
         if let Ok(amt) = env::var("NUM_JOBS") {
             if let Ok(amt) = amt.parse() {
-                cfg = cfg.num_threads(amt);
+                let _ = rayon::ThreadPoolBuilder::new()
+                    .num_threads(amt)
+                    .build_global();
             }
         }
-        drop(rayon::initialize(cfg));
-
-        let results: Mutex<Vec<Result<(), Error>>> = Mutex::new(Vec::new());
-
-        objs.par_iter().with_max_len(1).for_each(
-            |obj| {
-                let res = self.compile_object(obj);
-                results.lock().unwrap().push(res)
-            },
-        );
 
         // Check for any errors and return the first one found.
-        for result in results.into_inner().unwrap().iter() {
-            if result.is_err() {
-                return result.clone();
-            }
-        }
-
-        Ok(())
+        objs.par_iter()
+            .with_max_len(1)
+            .map(|obj| self.compile_object(obj))
+            .collect()
     }
 
     #[cfg(not(feature = "parallel"))]
@@ -917,7 +911,8 @@ impl Build {
 
     fn compile_object(&self, obj: &Object) -> Result<(), Error> {
         let is_asm = obj.src.extension().and_then(|s| s.to_str()) == Some("asm");
-        let msvc = self.get_target()?.contains("msvc");
+        let target = self.get_target()?;
+        let msvc = target.contains("msvc");
         let (mut cmd, name) = if msvc && is_asm {
             self.msvc_macro_assembler()?
         } else {
@@ -931,15 +926,17 @@ impl Build {
                 compiler
                     .path
                     .file_name()
-                    .ok_or_else(|| {
-                        Error::new(ErrorKind::IOError, "Failed to get compiler path.")
-                    })?
+                    .ok_or_else(|| Error::new(ErrorKind::IOError, "Failed to get compiler path."))?
                     .to_string_lossy()
                     .into_owned(),
             )
         };
-        command_add_output_file(&mut cmd, &obj.dst, msvc, is_asm);
-        cmd.arg(if msvc { "/c" } else { "-c" });
+        let is_arm = target.contains("aarch64") || target.contains("arm");
+        command_add_output_file(&mut cmd, &obj.dst, msvc, is_asm, is_arm);
+        // armasm and armasm64 don't requrie -c option
+        if !msvc || !is_asm || !is_arm {
+            cmd.arg(if msvc { "/c" } else { "-c" });
+        }
         cmd.arg(&obj.src);
 
         run(&mut cmd, &name)?;
@@ -967,9 +964,7 @@ impl Build {
         let name = compiler
             .path
             .file_name()
-            .ok_or_else(|| {
-                Error::new(ErrorKind::IOError, "Failed to get compiler path.")
-            })?
+            .ok_or_else(|| Error::new(ErrorKind::IOError, "Failed to get compiler path."))?
             .to_string_lossy()
             .into_owned();
 
@@ -1054,8 +1049,8 @@ impl Build {
                 cmd.args.push(crt_flag.into());
 
                 match &opt_level[..] {
-                    "z" | "s" => cmd.args.push("/Os".into()),
-                    "1" => cmd.args.push("/O1".into()),
+                    // Msvc uses /O1 to enable all optimizations that minimize code size.
+                    "z" | "s" | "1" => cmd.args.push("/O1".into()),
                     // -O3 is a valid value for gcc and clang compilers, but not msvc. Cap to /O2.
                     "2" | "3" => cmd.args.push("/O2".into()),
                     _ => {}
@@ -1070,8 +1065,10 @@ impl Build {
                     cmd.args.push(format!("-O{}", opt_level).into());
                 }
 
-                cmd.push_cc_arg("-ffunction-sections".into());
-                cmd.push_cc_arg("-fdata-sections".into());
+                if !target.contains("-ios") {
+                    cmd.push_cc_arg("-ffunction-sections".into());
+                    cmd.push_cc_arg("-fdata-sections".into());
+                }
                 if self.pic.unwrap_or(!target.contains("windows-gnu")) {
                     cmd.push_cc_arg("-fPIC".into());
                 }
@@ -1169,7 +1166,7 @@ impl Build {
                 // linker that we're generating 32-bit executables as well. This'll
                 // typically only be used for build scripts which transitively use
                 // these flags that try to compile executables.
-                if target == "i686-unknown-linux-musl" {
+                if target == "i686-unknown-linux-musl" || target == "i586-unknown-linux-musl" {
                     cmd.args.push("-Wl,-melf_i386".into());
                 }
 
@@ -1212,14 +1209,13 @@ impl Build {
         if self.cpp {
             match (self.cpp_set_stdlib.as_ref(), cmd.family) {
                 (None, _) => {}
-                (Some(stdlib), ToolFamily::Gnu) |
-                (Some(stdlib), ToolFamily::Clang) => {
+                (Some(stdlib), ToolFamily::Gnu) | (Some(stdlib), ToolFamily::Clang) => {
                     cmd.push_cc_arg(format!("-stdlib=lib{}", stdlib).into());
                 }
                 _ => {
                     println!(
                         "cargo:warning=cpp_set_stdlib is specified, but the {:?} compiler \
-                              does not support this option, ignored",
+                         does not support this option, ignored",
                         cmd.family
                     );
                 }
@@ -1272,6 +1268,10 @@ impl Build {
         let target = self.get_target()?;
         let tool = if target.contains("x86_64") {
             "ml64.exe"
+        } else if target.contains("arm") {
+            "armasm.exe"
+        } else if target.contains("aarch64") {
+            "armasm64.exe"
         } else {
             "ml.exe"
         };
@@ -1307,20 +1307,55 @@ impl Build {
         if target.contains("msvc") {
             let mut cmd = match self.archiver {
                 Some(ref s) => self.cmd(s),
-                None => {
-                    windows_registry::find(&target, "lib.exe").unwrap_or_else(
-                        || {
-                            self.cmd("lib.exe")
-                        },
-                    )
-                }
+                None => windows_registry::find(&target, "lib.exe")
+                    .unwrap_or_else(|| self.cmd("lib.exe")),
             };
+
             let mut out = OsString::from("/OUT:");
             out.push(dst);
-            run(
-                cmd.arg(out).arg("/nologo").args(&objects).args(&self.objects),
-                "lib.exe",
-            )?;
+            cmd.arg(out).arg("/nologo");
+
+            // Similar to https://github.com/rust-lang/rust/pull/47507
+            // and https://github.com/rust-lang/rust/pull/48548
+            let estimated_command_line_len = objects
+                .iter()
+                .chain(&self.objects)
+                .map(|a| a.as_os_str().len())
+                .sum::<usize>();
+            if estimated_command_line_len > 1024 * 6 {
+                let mut args = String::from("\u{FEFF}"); // BOM
+                for arg in objects.iter().chain(&self.objects) {
+                    args.push('"');
+                    for c in arg.to_str().unwrap().chars() {
+                        if c == '"' {
+                            args.push('\\')
+                        }
+                        args.push(c)
+                    }
+                    args.push('"');
+                    args.push('\n');
+                }
+
+                let mut utf16le = Vec::new();
+                for code_unit in args.encode_utf16() {
+                    utf16le.push(code_unit as u8);
+                    utf16le.push((code_unit >> 8) as u8);
+                }
+
+                let mut args_file = OsString::from(dst);
+                args_file.push(".args");
+                fs::File::create(&args_file)
+                    .unwrap()
+                    .write_all(&utf16le)
+                    .unwrap();
+
+                let mut args_file_arg = OsString::from("@");
+                args_file_arg.push(args_file);
+                cmd.arg(args_file_arg);
+            } else {
+                cmd.args(&objects).args(&self.objects);
+            }
+            run(&mut cmd, "lib.exe")?;
 
             // The Rust compiler will look for libfoo.a and foo.lib, but the
             // MSVC linker will also be passed foo.lib, so be sure that both
@@ -1412,6 +1447,18 @@ impl Build {
 
         cmd.args.push("-isysroot".into());
         cmd.args.push(sdk_path.trim().into());
+        cmd.args.push("-fembed-bitcode".into());
+        /*
+         * TODO we probably ultimatedly want the -fembed-bitcode-marker flag
+         * but can't have it now because of an issue in LLVM:
+         * https://github.com/alexcrichton/cc-rs/issues/301
+         * https://github.com/rust-lang/rust/pull/48896#comment-372192660
+         */
+        /*
+        if self.get_opt_level()? == "0" {
+            cmd.args.push("-fembed-bitcode-marker".into());
+        }
+        */
 
         Ok(())
     }
@@ -1437,37 +1484,44 @@ impl Build {
         };
 
         // On Solaris, c++/cc unlikely to exist or be correct.
-        let default = if host.contains("solaris") { gnu } else { traditional };
-
-        let tool_opt: Option<Tool> =
-            self.env_tool(env)
-                .map(|(tool, cc, args)| {
-                    let mut t = Tool::new(PathBuf::from(tool));
-                    if let Some(cc) = cc {
-                        t.cc_wrapper_path = Some(PathBuf::from(cc));
-                    }
-                    for arg in args {
-                        t.cc_wrapper_args.push(arg.into());
-                    }
-                    t
-                })
-                .or_else(|| {
-                    if target.contains("emscripten") {
-                        let tool = if self.cpp { "em++" } else { "emcc" };
-                        // Windows uses bat file so we have to be a bit more specific
-                        if cfg!(windows) {
-                            let mut t = Tool::new(PathBuf::from("cmd"));
-                            t.args.push("/c".into());
-                            t.args.push(format!("{}.bat", tool).into());
-                            Some(t)
-                        } else {
-                            Some(Tool::new(PathBuf::from(tool)))
-                        }
+        let default = if host.contains("solaris") {
+            gnu
+        } else {
+            traditional
+        };
+
+        let tool_opt: Option<Tool> = self.env_tool(env)
+            .map(|(tool, cc, args)| {
+                // chop off leading/trailing whitespace to work around
+                // semi-buggy build scripts which are shared in
+                // makefiles/configure scripts (where spaces are far more
+                // lenient)
+                let mut t = Tool::new(PathBuf::from(tool.trim()));
+                if let Some(cc) = cc {
+                    t.cc_wrapper_path = Some(PathBuf::from(cc));
+                }
+                for arg in args {
+                    t.cc_wrapper_args.push(arg.into());
+                }
+                t
+            })
+            .or_else(|| {
+                if target.contains("emscripten") {
+                    let tool = if self.cpp { "em++" } else { "emcc" };
+                    // Windows uses bat file so we have to be a bit more specific
+                    if cfg!(windows) {
+                        let mut t = Tool::new(PathBuf::from("cmd"));
+                        t.args.push("/c".into());
+                        t.args.push(format!("{}.bat", tool).into());
+                        Some(t)
                     } else {
-                        None
+                        Some(Tool::new(PathBuf::from(tool)))
                     }
-                })
-                .or_else(|| windows_registry::find_tool(&target, "cl.exe"));
+                } else {
+                    None
+                }
+            })
+            .or_else(|| windows_registry::find_tool(&target, "cl.exe"));
 
         let tool = match tool_opt {
             Some(t) => t,
@@ -1501,6 +1555,7 @@ impl Build {
                         "armv7-unknown-linux-gnueabihf" => Some("arm-linux-gnueabihf"),
                         "armv7-unknown-linux-musleabihf" => Some("arm-linux-musleabihf"),
                         "armv7-unknown-netbsd-eabihf" => Some("armv7--netbsdelf-eabihf"),
+                        "i586-unknown-linux-musl" => Some("musl"),
                         "i686-pc-windows-gnu" => Some("i686-w64-mingw32"),
                         "i686-unknown-linux-musl" => Some("musl"),
                         "i686-unknown-netbsd" => Some("i486--netbsdelf"),
@@ -1509,10 +1564,12 @@ impl Build {
                         "mips64-unknown-linux-gnuabi64" => Some("mips64-linux-gnuabi64"),
                         "mips64el-unknown-linux-gnuabi64" => Some("mips64el-linux-gnuabi64"),
                         "powerpc-unknown-linux-gnu" => Some("powerpc-linux-gnu"),
+                        "powerpc-unknown-linux-gnuspe" => Some("powerpc-linux-gnuspe"),
                         "powerpc-unknown-netbsd" => Some("powerpc--netbsd"),
                         "powerpc64-unknown-linux-gnu" => Some("powerpc-linux-gnu"),
                         "powerpc64le-unknown-linux-gnu" => Some("powerpc64le-linux-gnu"),
                         "s390x-unknown-linux-gnu" => Some("s390x-linux-gnu"),
+                        "sparc-unknown-linux-gnu" => Some("sparc-linux-gnu"),
                         "sparc64-unknown-linux-gnu" => Some("sparc64-linux-gnu"),
                         "sparc64-unknown-netbsd" => Some("sparc64--netbsd"),
                         "sparcv9-sun-solaris" => Some("sparcv9-sun-solaris"),
@@ -1538,14 +1595,18 @@ impl Build {
         };
 
         let tool = if self.cuda {
-            assert!(tool.args.is_empty(),
-                "CUDA compilation currently assumes empty pre-existing args");
+            assert!(
+                tool.args.is_empty(),
+                "CUDA compilation currently assumes empty pre-existing args"
+            );
             let nvcc = match self.get_var("NVCC") {
                 Err(_) => "nvcc".into(),
                 Ok(nvcc) => nvcc,
             };
             let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), self.cuda);
-            nvcc_tool.args.push(format!("-ccbin={}", tool.path.display()).into());
+            nvcc_tool
+                .args
+                .push(format!("-ccbin={}", tool.path.display()).into());
             nvcc_tool
         } else {
             tool
@@ -1568,10 +1629,7 @@ impl Build {
             Some(res) => Ok(res),
             None => Err(Error::new(
                 ErrorKind::EnvVarNotFound,
-                &format!(
-                    "Could not find environment variable {}.",
-                    var_base
-                ),
+                &format!("Could not find environment variable {}.", var_base),
             )),
         }
     }
@@ -1585,21 +1643,68 @@ impl Build {
             .collect()
     }
 
-
     /// Returns compiler path, optional modifier name from whitelist, and arguments vec
     fn env_tool(&self, name: &str) -> Option<(String, Option<String>, Vec<String>)> {
-        self.get_var(name).ok().map(|tool| {
-            let whitelist = ["ccache", "distcc", "sccache"];
+        let tool = match self.get_var(name) {
+            Ok(tool) => tool,
+            Err(_) => return None,
+        };
 
-            for t in whitelist.iter() {
-                if tool.starts_with(t) && tool[t.len()..].starts_with(' ')  {
-                    let args = tool.split_whitespace().collect::<Vec<_>>();
+        // If this is an exact path on the filesystem we don't want to do any
+        // interpretation at all, just pass it on through. This'll hopefully get
+        // us to support spaces-in-paths.
+        if Path::new(&tool).exists() {
+            return Some((tool, None, Vec::new()));
+        }
+
+        // Ok now we want to handle a couple of scenarios. We'll assume from
+        // here on out that spaces are splitting separate arguments. Two major
+        // features we want to support are:
+        //
+        //      CC='sccache cc'
+        //
+        // aka using `sccache` or any other wrapper/caching-like-thing for
+        // compilations. We want to know what the actual compiler is still,
+        // though, because our `Tool` API support introspection of it to see
+        // what compiler is in use.
+        //
+        // additionally we want to support
+        //
+        //      CC='cc -flag'
+        //
+        // where the CC env var is used to also pass default flags to the C
+        // compiler.
+        //
+        // It's true that everything here is a bit of a pain, but apparently if
+        // you're not literally make or bash then you get a lot of bug reports.
+        let known_wrappers = ["ccache", "distcc", "sccache", "icecc"];
+
+        let mut parts = tool.split_whitespace();
+        let maybe_wrapper = match parts.next() {
+            Some(s) => s,
+            None => return None,
+        };
 
-                    return (args[1].to_string(), Some(t.to_string()), args[2..].iter().map(|s| s.to_string()).collect());
-                }
+        let file_stem = Path::new(maybe_wrapper)
+            .file_stem()
+            .unwrap()
+            .to_str()
+            .unwrap();
+        if known_wrappers.contains(&file_stem) {
+            if let Some(compiler) = parts.next() {
+                return Some((
+                    compiler.to_string(),
+                    Some(maybe_wrapper.to_string()),
+                    parts.map(|s| s.to_string()).collect(),
+                ));
             }
-            (tool, None, Vec::new())
-        })
+        }
+
+        Some((
+            maybe_wrapper.to_string(),
+            None,
+            parts.map(|s| s.to_string()).collect(),
+        ))
     }
 
     /// Returns the default C++ standard library for the current target: `libc++`
@@ -1611,7 +1716,7 @@ impl Build {
                 let target = self.get_target()?;
                 if target.contains("msvc") {
                     Ok(None)
-                } else if target.contains("darwin") {
+                } else if target.contains("apple") {
                     Ok(Some("c++".to_string()))
                 } else if target.contains("freebsd") {
                     Ok(Some("c++".to_string()))
@@ -1700,10 +1805,7 @@ impl Build {
             Some(s) => Ok(s),
             None => Err(Error::new(
                 ErrorKind::EnvVarNotFound,
-                &format!(
-                    "Environment variable {} not defined.",
-                    v.to_string()
-                ),
+                &format!("Environment variable {} not defined.", v.to_string()),
             )),
         }
     }
@@ -1731,8 +1833,9 @@ impl Tool {
         let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
             if fname.contains("clang") {
                 ToolFamily::Clang
-            } else if fname.contains("cl") && !fname.contains("cloudabi") &&
-                      !fname.contains("uclibc") {
+            } else if fname.contains("cl") && !fname.contains("cloudabi")
+                && !fname.contains("uclibc")
+            {
                 ToolFamily::Msvc
             } else {
                 ToolFamily::Gnu
@@ -1775,8 +1878,8 @@ impl Tool {
                 cmd.arg(&self.path);
                 cmd.args(&self.cc_wrapper_args);
                 cmd
-            },
-            None => Command::new(&self.path)
+            }
+            None => Command::new(&self.path),
         };
         cmd.args(&self.args);
         for &(ref k, ref v) in self.env.iter() {
@@ -1822,10 +1925,8 @@ impl Tool {
                     cc_env.push(arg);
                 }
                 cc_env
-            },
-            None => {
-                OsString::from("")
             }
+            None => OsString::from(""),
         }
     }
 
@@ -1868,8 +1969,7 @@ fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
                 ErrorKind::ToolExecError,
                 &format!(
                     "Failed to wait on spawned child process, command {:?} with args {:?}.",
-                    cmd,
-                    program
+                    cmd, program
                 ),
             ))
         }
@@ -1884,9 +1984,7 @@ fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
             ErrorKind::ToolExecError,
             &format!(
                 "Command {:?} with args {:?} did not execute successfully (status code {}).",
-                cmd,
-                program,
-                status
+                cmd, program, status
             ),
         ))
     }
@@ -1909,8 +2007,7 @@ fn run_output(cmd: &mut Command, program: &str) -> Result<Vec<u8>, Error> {
                 ErrorKind::ToolExecError,
                 &format!(
                     "Failed to wait on spawned child process, command {:?} with args {:?}.",
-                    cmd,
-                    program
+                    cmd, program
                 ),
             ))
         }
@@ -1925,9 +2022,7 @@ fn run_output(cmd: &mut Command, program: &str) -> Result<Vec<u8>, Error> {
             ErrorKind::ToolExecError,
             &format!(
                 "Command {:?} with args {:?} did not execute successfully (status code {}).",
-                cmd,
-                program,
-                status
+                cmd, program, status
             ),
         ))
     }
@@ -1943,39 +2038,30 @@ fn spawn(cmd: &mut Command, program: &str) -> Result<(Child, JoinHandle<()>), Er
     match cmd.stderr(Stdio::piped()).spawn() {
         Ok(mut child) => {
             let stderr = BufReader::new(child.stderr.take().unwrap());
-            let print = thread::spawn(move || for line in stderr.split(b'\n').filter_map(
-                |l| l.ok(),
-            )
-            {
-                print!("cargo:warning=");
-                std::io::stdout().write_all(&line).unwrap();
-                println!("");
+            let print = thread::spawn(move || {
+                for line in stderr.split(b'\n').filter_map(|l| l.ok()) {
+                    print!("cargo:warning=");
+                    std::io::stdout().write_all(&line).unwrap();
+                    println!("");
+                }
             });
             Ok((child, print))
         }
         Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
             let extra = if cfg!(windows) {
                 " (see https://github.com/alexcrichton/cc-rs#compile-time-requirements \
-                   for help)"
+                 for help)"
             } else {
                 ""
             };
             Err(Error::new(
                 ErrorKind::ToolNotFound,
-                &format!(
-                    "Failed to find tool. Is `{}` installed?{}",
-                    program,
-                    extra
-                ),
+                &format!("Failed to find tool. Is `{}` installed?{}", program, extra),
             ))
         }
         Err(_) => Err(Error::new(
             ErrorKind::ToolExecError,
-            &format!(
-                "Command {:?} with args {:?} failed to start.",
-                cmd,
-                program
-            ),
+            &format!("Command {:?} with args {:?} failed to start.", cmd, program),
         )),
     }
 }
@@ -1984,9 +2070,10 @@ fn fail(s: &str) -> ! {
     panic!("\n\nInternal error occurred: {}\n\n", s)
 }
 
-
-fn command_add_output_file(cmd: &mut Command, dst: &Path, msvc: bool, is_asm: bool) {
-    if msvc && is_asm {
+fn command_add_output_file(cmd: &mut Command, dst: &Path, msvc: bool, is_asm: bool, is_arm: bool) {
+    if msvc && is_asm && is_arm {
+        cmd.arg("-o").arg(&dst);
+    } else if msvc && is_asm {
         cmd.arg("/Fo").arg(dst);
     } else if msvc {
         let mut s = OsString::from("/Fo");