|
19 | 19 | //! ensure that they're always in place if needed.
|
20 | 20 |
|
21 | 21 | use std::env;
|
| 22 | +use std::ffi::OsString; |
22 | 23 | use std::fs::{self, File};
|
23 | 24 | use std::io::{Read, Write};
|
24 | 25 | use std::path::Path;
|
@@ -129,22 +130,55 @@ pub fn llvm(build: &Build, target: &str) {
|
129 | 130 | .define("LLVM_TABLEGEN", &host);
|
130 | 131 | }
|
131 | 132 |
|
132 |
| - // MSVC handles compiler business itself |
133 |
| - if !target.contains("msvc") { |
134 |
| - if let Some(ref ccache) = build.config.ccache { |
| 133 | + let sanitize_cc = |cc: &Path| { |
| 134 | + if target.contains("msvc") { |
| 135 | + OsString::from(cc.to_str().unwrap().replace("\\", "/")) |
| 136 | + } else { |
| 137 | + cc.as_os_str().to_owned() |
| 138 | + } |
| 139 | + }; |
| 140 | + |
| 141 | + let configure_compilers = |cfg: &mut cmake::Config| { |
| 142 | + // MSVC with CMake uses msbuild by default which doesn't respect these |
| 143 | + // vars that we'd otherwise configure. In that case we just skip this |
| 144 | + // entirely. |
| 145 | + if target.contains("msvc") && !build.config.ninja { |
| 146 | + return |
| 147 | + } |
| 148 | + |
| 149 | + let cc = build.cc(target); |
| 150 | + let cxx = build.cxx(target); |
| 151 | + |
| 152 | + // Handle msvc + ninja + ccache specially (this is what the bots use) |
| 153 | + if target.contains("msvc") && |
| 154 | + build.config.ninja && |
| 155 | + build.config.ccache.is_some() { |
| 156 | + let mut cc = env::current_exe().expect("failed to get cwd"); |
| 157 | + cc.set_file_name("sccache-plus-cl.exe"); |
| 158 | + |
| 159 | + cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc)) |
| 160 | + .define("CMAKE_CXX_COMPILER", sanitize_cc(&cc)); |
| 161 | + cfg.env("SCCACHE_PATH", |
| 162 | + build.config.ccache.as_ref().unwrap()); |
| 163 | + |
| 164 | + // If ccache is configured we inform the build a little differently hwo |
| 165 | + // to invoke ccache while also invoking our compilers. |
| 166 | + } else if let Some(ref ccache) = build.config.ccache { |
135 | 167 | cfg.define("CMAKE_C_COMPILER", ccache)
|
136 |
| - .define("CMAKE_C_COMPILER_ARG1", build.cc(target)) |
| 168 | + .define("CMAKE_C_COMPILER_ARG1", sanitize_cc(cc)) |
137 | 169 | .define("CMAKE_CXX_COMPILER", ccache)
|
138 |
| - .define("CMAKE_CXX_COMPILER_ARG1", build.cxx(target)); |
| 170 | + .define("CMAKE_CXX_COMPILER_ARG1", sanitize_cc(cxx)); |
139 | 171 | } else {
|
140 |
| - cfg.define("CMAKE_C_COMPILER", build.cc(target)) |
141 |
| - .define("CMAKE_CXX_COMPILER", build.cxx(target)); |
| 172 | + cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc)) |
| 173 | + .define("CMAKE_CXX_COMPILER", sanitize_cc(cxx)); |
142 | 174 | }
|
143 |
| - cfg.build_arg("-j").build_arg(build.jobs().to_string()); |
144 | 175 |
|
| 176 | + cfg.build_arg("-j").build_arg(build.jobs().to_string()); |
145 | 177 | cfg.define("CMAKE_C_FLAGS", build.cflags(target).join(" "));
|
146 | 178 | cfg.define("CMAKE_CXX_FLAGS", build.cflags(target).join(" "));
|
147 |
| - } |
| 179 | + }; |
| 180 | + |
| 181 | + configure_compilers(&mut cfg); |
148 | 182 |
|
149 | 183 | if env::var_os("SCCACHE_ERROR_LOG").is_some() {
|
150 | 184 | cfg.env("RUST_LOG", "sccache=info");
|
|
0 commit comments