]>
Commit | Line | Data |
---|---|---|
83c7162d XL |
1 | //! Some stuff used by rustc that doesn't have many dependencies |
2 | //! | |
3 | //! Originally extracted from rustc::back, which was nominally the | |
4 | //! compiler 'backend', though LLVM is rustc's backend, so rustc_target | |
5 | //! is really just odds-and-ends relating to code gen and linking. | |
6 | //! This crate mostly exists to make rustc smaller, so we might put | |
9fa01778 | 7 | //! more 'stuff' here in the future. It does not have a dependency on |
b7449926 | 8 | //! LLVM. |
83c7162d | 9 | |
1b1a35ee | 10 | #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] |
064997fb | 11 | #![feature(assert_matches)] |
ba9703b0 XL |
12 | #![feature(associated_type_bounds)] |
13 | #![feature(exhaustive_patterns)] | |
17df50a5 | 14 | #![feature(min_specialization)] |
5e7ed085 | 15 | #![feature(never_type)] |
5e7ed085 | 16 | #![feature(rustc_attrs)] |
94222f64 | 17 | #![feature(step_trait)] |
f2b60f7d FG |
18 | #![deny(rustc::untranslatable_diagnostic)] |
19 | #![deny(rustc::diagnostic_outside_of_impl)] | |
17df50a5 XL |
20 | |
21 | use std::path::{Path, PathBuf}; | |
9fa01778 | 22 | |
3dfed10e | 23 | #[macro_use] |
f9f354fc XL |
24 | extern crate rustc_macros; |
25 | ||
dfeec247 | 26 | #[macro_use] |
3dfed10e | 27 | extern crate tracing; |
83c7162d | 28 | |
83c7162d | 29 | pub mod abi; |
f9f354fc | 30 | pub mod asm; |
923072b8 | 31 | pub mod json; |
83c7162d | 32 | pub mod spec; |
60c5eb7d | 33 | |
136023e0 XL |
34 | #[cfg(test)] |
35 | mod tests; | |
36 | ||
487cf647 | 37 | pub use rustc_abi::HashStableContext; |
17df50a5 XL |
38 | |
39 | /// The name of rustc's own place to organize libraries. | |
40 | /// | |
41 | /// Used to be `rustc`, now the default is `rustlib`. | |
42 | const RUST_LIB_DIR: &str = "rustlib"; | |
43 | ||
44 | /// Returns a `rustlib` path for this particular target, relative to the provided sysroot. | |
45 | /// | |
46 | /// For example: `target_sysroot_path("/usr", "x86_64-unknown-linux-gnu")` => | |
47 | /// `"lib*/rustlib/x86_64-unknown-linux-gnu"`. | |
48 | pub fn target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf { | |
49 | let libdir = find_libdir(sysroot); | |
a2a8927a | 50 | PathBuf::from_iter([ |
17df50a5 XL |
51 | Path::new(libdir.as_ref()), |
52 | Path::new(RUST_LIB_DIR), | |
53 | Path::new(target_triple), | |
54 | ]) | |
17df50a5 XL |
55 | } |
56 | ||
57 | /// The name of the directory rustc expects libraries to be located. | |
58 | fn find_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> { | |
59 | // FIXME: This is a quick hack to make the rustc binary able to locate | |
60 | // Rust libraries in Linux environments where libraries might be installed | |
61 | // to lib64/lib32. This would be more foolproof by basing the sysroot off | |
62 | // of the directory where `librustc_driver` is located, rather than | |
63 | // where the rustc binary is. | |
64 | // If --libdir is set during configuration to the value other than | |
65 | // "lib" (i.e., non-default), this value is used (see issue #16552). | |
66 | ||
67 | #[cfg(target_pointer_width = "64")] | |
68 | const PRIMARY_LIB_DIR: &str = "lib64"; | |
69 | ||
70 | #[cfg(target_pointer_width = "32")] | |
71 | const PRIMARY_LIB_DIR: &str = "lib32"; | |
72 | ||
73 | const SECONDARY_LIB_DIR: &str = "lib"; | |
74 | ||
75 | match option_env!("CFG_LIBDIR_RELATIVE") { | |
76 | None | Some("lib") => { | |
77 | if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() { | |
78 | PRIMARY_LIB_DIR.into() | |
79 | } else { | |
80 | SECONDARY_LIB_DIR.into() | |
81 | } | |
82 | } | |
83 | Some(libdir) => libdir.into(), | |
84 | } | |
85 | } |