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