|
1 | | -use std::fs::File; |
2 | 1 | use std::path::{Path, PathBuf}; |
3 | 2 | use std::process::{Command, Stdio}; |
4 | | -use std::thread; |
5 | 3 | use std::time::{SystemTime, UNIX_EPOCH}; |
6 | 4 | use std::{env, fs}; |
7 | 5 |
|
@@ -181,108 +179,6 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool { |
181 | 179 | } |
182 | 180 | } |
183 | 181 |
|
184 | | -#[must_use] |
185 | | -pub struct NativeLibBoilerplate { |
186 | | - pub src_dir: PathBuf, |
187 | | - pub out_dir: PathBuf, |
188 | | -} |
189 | | - |
190 | | -impl NativeLibBoilerplate { |
191 | | - /// On macOS we don't want to ship the exact filename that compiler-rt builds. |
192 | | - /// This conflicts with the system and ours is likely a wildly different |
193 | | - /// version, so they can't be substituted. |
194 | | - /// |
195 | | - /// As a result, we rename it here but we need to also use |
196 | | - /// `install_name_tool` on macOS to rename the commands listed inside of it to |
197 | | - /// ensure it's linked against correctly. |
198 | | - pub fn fixup_sanitizer_lib_name(&self, sanitizer_name: &str) { |
199 | | - if env::var("TARGET").unwrap() != "x86_64-apple-darwin" { |
200 | | - return; |
201 | | - } |
202 | | - |
203 | | - let dir = self.out_dir.join("build/lib/darwin"); |
204 | | - let name = format!("clang_rt.{}_osx_dynamic", sanitizer_name); |
205 | | - let src = dir.join(&format!("lib{}.dylib", name)); |
206 | | - let new_name = format!("lib__rustc__{}.dylib", name); |
207 | | - let dst = dir.join(&new_name); |
208 | | - |
209 | | - println!("{} => {}", src.display(), dst.display()); |
210 | | - fs::rename(&src, &dst).unwrap(); |
211 | | - let status = Command::new("install_name_tool") |
212 | | - .arg("-id") |
213 | | - .arg(format!("@rpath/{}", new_name)) |
214 | | - .arg(&dst) |
215 | | - .status() |
216 | | - .expect("failed to execute `install_name_tool`"); |
217 | | - assert!(status.success()); |
218 | | - } |
219 | | -} |
220 | | - |
221 | | -impl Drop for NativeLibBoilerplate { |
222 | | - fn drop(&mut self) { |
223 | | - if !thread::panicking() { |
224 | | - t!(File::create(self.out_dir.join("rustbuild.timestamp"))); |
225 | | - } |
226 | | - } |
227 | | -} |
228 | | - |
229 | | -// Perform standard preparations for native libraries that are build only once for all stages. |
230 | | -// Emit rerun-if-changed and linking attributes for Cargo, check if any source files are |
231 | | -// updated, calculate paths used later in actual build with CMake/make or C/C++ compiler. |
232 | | -// If Err is returned, then everything is up-to-date and further build actions can be skipped. |
233 | | -// Timestamps are created automatically when the result of `native_lib_boilerplate` goes out |
234 | | -// of scope, so all the build actions should be completed until then. |
235 | | -pub fn native_lib_boilerplate( |
236 | | - src_dir: &Path, |
237 | | - out_name: &str, |
238 | | - link_name: &str, |
239 | | - search_subdir: &str, |
240 | | -) -> Result<NativeLibBoilerplate, ()> { |
241 | | - rerun_if_changed_anything_in_dir(src_dir); |
242 | | - |
243 | | - let out_dir = |
244 | | - env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or_else(|| env::var_os("OUT_DIR").unwrap()); |
245 | | - let out_dir = PathBuf::from(out_dir).join(out_name); |
246 | | - t!(fs::create_dir_all(&out_dir)); |
247 | | - if link_name.contains('=') { |
248 | | - println!("cargo:rustc-link-lib={}", link_name); |
249 | | - } else { |
250 | | - println!("cargo:rustc-link-lib=static={}", link_name); |
251 | | - } |
252 | | - println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display()); |
253 | | - |
254 | | - let timestamp = out_dir.join("rustbuild.timestamp"); |
255 | | - if !up_to_date(Path::new("build.rs"), ×tamp) || !up_to_date(src_dir, ×tamp) { |
256 | | - Ok(NativeLibBoilerplate { src_dir: src_dir.to_path_buf(), out_dir }) |
257 | | - } else { |
258 | | - Err(()) |
259 | | - } |
260 | | -} |
261 | | - |
262 | | -pub fn sanitizer_lib_boilerplate( |
263 | | - sanitizer_name: &str, |
264 | | -) -> Result<(NativeLibBoilerplate, String), ()> { |
265 | | - let (link_name, search_path, apple) = match &*env::var("TARGET").unwrap() { |
266 | | - "x86_64-unknown-linux-gnu" => { |
267 | | - (format!("clang_rt.{}-x86_64", sanitizer_name), "build/lib/linux", false) |
268 | | - } |
269 | | - "x86_64-apple-darwin" => { |
270 | | - (format!("clang_rt.{}_osx_dynamic", sanitizer_name), "build/lib/darwin", true) |
271 | | - } |
272 | | - _ => return Err(()), |
273 | | - }; |
274 | | - let to_link = if apple { |
275 | | - format!("dylib=__rustc__{}", link_name) |
276 | | - } else { |
277 | | - format!("static={}", link_name) |
278 | | - }; |
279 | | - // This env var is provided by rustbuild to tell us where `compiler-rt` |
280 | | - // lives. |
281 | | - let dir = env::var_os("RUST_COMPILER_RT_ROOT").unwrap(); |
282 | | - let lib = native_lib_boilerplate(dir.as_ref(), sanitizer_name, &to_link, search_path)?; |
283 | | - Ok((lib, link_name)) |
284 | | -} |
285 | | - |
286 | 182 | fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool { |
287 | 183 | t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| { |
288 | 184 | let meta = t!(e.metadata()); |
|
0 commit comments