]>
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/")] |
60c5eb7d | 11 | #![feature(bool_to_option)] |
0bf4aa26 | 12 | #![feature(nll)] |
ba9703b0 XL |
13 | #![feature(never_type)] |
14 | #![feature(associated_type_bounds)] | |
15 | #![feature(exhaustive_patterns)] | |
17df50a5 | 16 | #![feature(min_specialization)] |
94222f64 | 17 | #![feature(step_trait)] |
17df50a5 XL |
18 | |
19 | use std::path::{Path, PathBuf}; | |
9fa01778 | 20 | |
3dfed10e | 21 | #[macro_use] |
f9f354fc XL |
22 | extern crate rustc_macros; |
23 | ||
dfeec247 | 24 | #[macro_use] |
3dfed10e | 25 | extern crate tracing; |
83c7162d | 26 | |
83c7162d | 27 | pub mod abi; |
f9f354fc | 28 | pub mod asm; |
83c7162d | 29 | pub mod spec; |
60c5eb7d | 30 | |
136023e0 XL |
31 | #[cfg(test)] |
32 | mod tests; | |
33 | ||
60c5eb7d XL |
34 | /// Requirements for a `StableHashingContext` to be used in this crate. |
35 | /// This is a hack to allow using the `HashStable_Generic` derive macro | |
cdc7bbd5 | 36 | /// instead of implementing everything in `rustc_middle`. |
60c5eb7d | 37 | pub trait 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); | |
50 | std::array::IntoIter::new([ | |
51 | Path::new(libdir.as_ref()), | |
52 | Path::new(RUST_LIB_DIR), | |
53 | Path::new(target_triple), | |
54 | ]) | |
55 | .collect::<PathBuf>() | |
56 | } | |
57 | ||
58 | /// The name of the directory rustc expects libraries to be located. | |
59 | fn find_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> { | |
60 | // FIXME: This is a quick hack to make the rustc binary able to locate | |
61 | // Rust libraries in Linux environments where libraries might be installed | |
62 | // to lib64/lib32. This would be more foolproof by basing the sysroot off | |
63 | // of the directory where `librustc_driver` is located, rather than | |
64 | // where the rustc binary is. | |
65 | // If --libdir is set during configuration to the value other than | |
66 | // "lib" (i.e., non-default), this value is used (see issue #16552). | |
67 | ||
68 | #[cfg(target_pointer_width = "64")] | |
69 | const PRIMARY_LIB_DIR: &str = "lib64"; | |
70 | ||
71 | #[cfg(target_pointer_width = "32")] | |
72 | const PRIMARY_LIB_DIR: &str = "lib32"; | |
73 | ||
74 | const SECONDARY_LIB_DIR: &str = "lib"; | |
75 | ||
76 | match option_env!("CFG_LIBDIR_RELATIVE") { | |
77 | None | Some("lib") => { | |
78 | if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() { | |
79 | PRIMARY_LIB_DIR.into() | |
80 | } else { | |
81 | SECONDARY_LIB_DIR.into() | |
82 | } | |
83 | } | |
84 | Some(libdir) => libdir.into(), | |
85 | } | |
86 | } |