2014-07-07 04:58:30 +00:00
|
|
|
//! Some stuff used by rustc that doesn't have many dependencies
|
|
|
|
//!
|
|
|
|
//! Originally extracted from rustc::back, which was nominally the
|
2017-12-08 19:18:21 +00:00
|
|
|
//! compiler 'backend', though LLVM is rustc's backend, so rustc_target
|
2014-07-07 04:58:30 +00: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 13:53:55 +00:00
|
|
|
//! more 'stuff' here in the future. It does not have a dependency on
|
2018-05-29 17:41:36 +00:00
|
|
|
//! LLVM.
|
2014-07-07 04:58:30 +00:00
|
|
|
|
2020-09-23 19:51:56 +00:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2022-06-17 20:53:00 +00:00
|
|
|
#![feature(assert_matches)]
|
2019-11-03 16:21:37 +00:00
|
|
|
#![feature(associated_type_bounds)]
|
|
|
|
#![feature(exhaustive_patterns)]
|
2022-03-04 02:46:56 +00:00
|
|
|
#![feature(let_else)]
|
2021-04-02 04:58:45 +00:00
|
|
|
#![feature(min_specialization)]
|
2022-03-04 02:46:56 +00:00
|
|
|
#![feature(never_type)]
|
|
|
|
#![feature(rustc_attrs)]
|
2021-03-31 04:06:01 +00:00
|
|
|
#![feature(step_trait)]
|
2015-01-01 04:43:46 +00:00
|
|
|
|
2021-09-03 10:36:33 +00:00
|
|
|
use std::iter::FromIterator;
|
2021-05-10 16:15:19 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2020-06-11 14:49:57 +00:00
|
|
|
#[macro_use]
|
2020-05-08 15:38:18 +00:00
|
|
|
extern crate rustc_macros;
|
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
#[macro_use]
|
2020-08-14 06:05:01 +00:00
|
|
|
extern crate tracing;
|
2014-07-05 02:41:54 +00:00
|
|
|
|
2017-12-18 14:18:36 +00:00
|
|
|
pub mod abi;
|
2020-01-22 11:24:31 +00:00
|
|
|
pub mod asm;
|
2021-06-03 15:45:09 +00:00
|
|
|
pub mod json;
|
2017-12-08 19:18:21 +00:00
|
|
|
pub mod spec;
|
2019-11-10 16:19:08 +00:00
|
|
|
|
2021-05-27 08:21:53 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2019-11-10 16:19:08 +00: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 19:47:01 +00:00
|
|
|
/// instead of implementing everything in `rustc_middle`.
|
2020-05-06 13:46:01 +00:00
|
|
|
pub trait HashStableContext {}
|
2021-05-10 16:15:19 +00: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);
|
2021-09-03 10:36:33 +00:00
|
|
|
PathBuf::from_iter([
|
2021-05-10 16:15:19 +00:00
|
|
|
Path::new(libdir.as_ref()),
|
|
|
|
Path::new(RUST_LIB_DIR),
|
|
|
|
Path::new(target_triple),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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(),
|
|
|
|
}
|
|
|
|
}
|