2014-07-06 21:58:30 -07:00
|
|
|
//! Some stuff used by rustc that doesn't have many dependencies
|
|
|
|
//!
|
|
|
|
//! Originally extracted from rustc::back, which was nominally the
|
2017-12-08 21:18:21 +02:00
|
|
|
//! compiler 'backend', though LLVM is rustc's backend, so rustc_target
|
2014-07-06 21:58:30 -07:00
|
|
|
//! is really just odds-and-ends relating to code gen and linking.
|
|
|
|
//! This crate mostly exists to make rustc smaller, so we might put
|
2019-02-08 14:53:55 +01:00
|
|
|
//! more 'stuff' here in the future. It does not have a dependency on
|
2018-05-29 20:41:36 +03:00
|
|
|
//! LLVM.
|
2014-07-06 21:58:30 -07:00
|
|
|
|
2020-09-23 21:51:56 +02:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2019-10-08 01:14:42 +01:00
|
|
|
#![feature(bool_to_option)]
|
2018-09-26 14:26:46 -07:00
|
|
|
#![feature(nll)]
|
2019-11-03 17:21:37 +01:00
|
|
|
#![feature(never_type)]
|
|
|
|
#![feature(associated_type_bounds)]
|
|
|
|
#![feature(exhaustive_patterns)]
|
2021-04-02 00:58:45 -04:00
|
|
|
#![feature(min_specialization)]
|
2014-12-31 20:43:46 -08:00
|
|
|
|
2021-05-10 19:15:19 +03:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2020-06-11 15:49:57 +01:00
|
|
|
#[macro_use]
|
2020-05-08 09:38:18 -06:00
|
|
|
extern crate rustc_macros;
|
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
#[macro_use]
|
2020-08-13 23:05:01 -07:00
|
|
|
extern crate tracing;
|
2014-07-04 19:41:54 -07:00
|
|
|
|
2017-12-18 16:18:36 +02:00
|
|
|
pub mod abi;
|
2020-01-22 11:24:31 +00:00
|
|
|
pub mod asm;
|
2017-12-08 21:18:21 +02:00
|
|
|
pub mod spec;
|
2019-11-10 17:19:08 +01:00
|
|
|
|
2021-05-27 10:21:53 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2019-11-10 17:19:08 +01:00
|
|
|
/// Requirements for a `StableHashingContext` to be used in this crate.
|
|
|
|
/// This is a hack to allow using the `HashStable_Generic` derive macro
|
2021-04-07 14:47:01 -05:00
|
|
|
/// instead of implementing everything in `rustc_middle`.
|
2020-05-06 14:46:01 +01:00
|
|
|
pub trait HashStableContext {}
|
2021-05-10 19:15:19 +03:00
|
|
|
|
|
|
|
/// The name of rustc's own place to organize libraries.
|
|
|
|
///
|
|
|
|
/// Used to be `rustc`, now the default is `rustlib`.
|
|
|
|
const RUST_LIB_DIR: &str = "rustlib";
|
|
|
|
|
|
|
|
/// Returns a `rustlib` path for this particular target, relative to the provided sysroot.
|
|
|
|
///
|
|
|
|
/// For example: `target_sysroot_path("/usr", "x86_64-unknown-linux-gnu")` =>
|
|
|
|
/// `"lib*/rustlib/x86_64-unknown-linux-gnu"`.
|
|
|
|
pub fn target_rustlib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
|
|
|
|
let libdir = find_libdir(sysroot);
|
|
|
|
std::array::IntoIter::new([
|
|
|
|
Path::new(libdir.as_ref()),
|
|
|
|
Path::new(RUST_LIB_DIR),
|
|
|
|
Path::new(target_triple),
|
|
|
|
])
|
|
|
|
.collect::<PathBuf>()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The name of the directory rustc expects libraries to be located.
|
|
|
|
fn find_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
|
|
|
|
// FIXME: This is a quick hack to make the rustc binary able to locate
|
|
|
|
// Rust libraries in Linux environments where libraries might be installed
|
|
|
|
// to lib64/lib32. This would be more foolproof by basing the sysroot off
|
|
|
|
// of the directory where `librustc_driver` is located, rather than
|
|
|
|
// where the rustc binary is.
|
|
|
|
// If --libdir is set during configuration to the value other than
|
|
|
|
// "lib" (i.e., non-default), this value is used (see issue #16552).
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
|
|
|
const PRIMARY_LIB_DIR: &str = "lib64";
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
const PRIMARY_LIB_DIR: &str = "lib32";
|
|
|
|
|
|
|
|
const SECONDARY_LIB_DIR: &str = "lib";
|
|
|
|
|
|
|
|
match option_env!("CFG_LIBDIR_RELATIVE") {
|
|
|
|
None | Some("lib") => {
|
|
|
|
if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
|
|
|
|
PRIMARY_LIB_DIR.into()
|
|
|
|
} else {
|
|
|
|
SECONDARY_LIB_DIR.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(libdir) => libdir.into(),
|
|
|
|
}
|
|
|
|
}
|