]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/bin/sccache-plus-cl.rs
Auto merge of #50234 - cramertj:extend, r=alexcrichton
[rust.git] / src / bootstrap / bin / sccache-plus-cl.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 extern crate cc;
12
13 use std::env;
14 use std::process::{self, Command};
15
16 fn main() {
17     let target = env::var("SCCACHE_TARGET").unwrap();
18     // Locate the actual compiler that we're invoking
19     env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
20     env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
21     let mut cfg = cc::Build::new();
22     cfg.cargo_metadata(false)
23        .out_dir("/")
24        .target(&target)
25        .host(&target)
26        .opt_level(0)
27        .warnings(false)
28        .debug(false);
29     let compiler = cfg.get_compiler();
30
31     // Invoke sccache with said compiler
32     let sccache_path = env::var_os("SCCACHE_PATH").unwrap();
33     let mut cmd = Command::new(&sccache_path);
34     cmd.arg(compiler.path());
35     for &(ref k, ref v) in compiler.env() {
36         cmd.env(k, v);
37     }
38     for arg in env::args().skip(1) {
39         cmd.arg(arg);
40     }
41
42     if let Ok(s) = env::var("SCCACHE_EXTRA_ARGS") {
43         for s in s.split_whitespace() {
44             cmd.arg(s);
45         }
46     }
47
48     let status = cmd.status().expect("failed to spawn");
49     process::exit(status.code().unwrap_or(2))
50 }