2019-12-31 19:24:05 -06:00
|
|
|
use crate::session::Session;
|
|
|
|
use rustc_data_structures::profiling::VerboseTimingGuard;
|
2021-01-26 15:27:42 -06:00
|
|
|
use std::path::{Path, PathBuf};
|
2019-11-12 07:30:40 -06:00
|
|
|
|
2019-12-31 19:24:05 -06:00
|
|
|
impl Session {
|
2020-01-07 14:34:08 -06:00
|
|
|
pub fn timer<'a>(&'a self, what: &'static str) -> VerboseTimingGuard<'a> {
|
|
|
|
self.prof.verbose_generic_activity(what)
|
2019-12-31 19:24:05 -06:00
|
|
|
}
|
2020-01-07 14:34:08 -06:00
|
|
|
pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
|
|
|
|
self.prof.verbose_generic_activity(what).run(f)
|
2019-12-31 19:24:05 -06:00
|
|
|
}
|
2019-11-12 07:30:40 -06:00
|
|
|
}
|
2019-11-14 11:16:24 -06:00
|
|
|
|
2020-06-11 09:49:57 -05:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
2022-04-19 03:43:09 -05:00
|
|
|
#[derive(HashStable_Generic)]
|
2020-05-17 16:18:50 -05:00
|
|
|
pub enum NativeLibKind {
|
2021-03-24 23:45:09 -05:00
|
|
|
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
|
|
|
|
Static {
|
|
|
|
/// Whether to bundle objects from static library into produced rlib
|
|
|
|
bundle: Option<bool>,
|
|
|
|
/// Whether to link static library without throwing any object files away
|
|
|
|
whole_archive: Option<bool>,
|
|
|
|
},
|
2020-05-17 17:37:24 -05:00
|
|
|
/// Dynamic library (e.g. `libfoo.so` on Linux)
|
|
|
|
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
|
2021-03-24 23:45:09 -05:00
|
|
|
Dylib {
|
2022-03-16 07:12:30 -05:00
|
|
|
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
|
2021-03-24 23:45:09 -05:00
|
|
|
as_needed: Option<bool>,
|
|
|
|
},
|
2020-05-17 17:37:24 -05:00
|
|
|
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
|
2020-05-17 16:18:50 -05:00
|
|
|
RawDylib,
|
|
|
|
/// A macOS-specific kind of dynamic libraries.
|
2021-03-24 23:45:09 -05:00
|
|
|
Framework {
|
2022-03-16 07:12:30 -05:00
|
|
|
/// Whether the framework will be linked only if it satisfies some undefined symbols
|
2021-03-24 23:45:09 -05:00
|
|
|
as_needed: Option<bool>,
|
|
|
|
},
|
2022-07-19 04:00:28 -05:00
|
|
|
/// Argument which is passed to linker, relative order with libraries and other arguments
|
|
|
|
/// is preserved
|
|
|
|
LinkArg,
|
2020-05-17 17:37:24 -05:00
|
|
|
/// The library kind wasn't specified, `Dylib` is currently used as a default.
|
2020-05-17 16:18:50 -05:00
|
|
|
Unspecified,
|
2019-11-14 11:16:24 -06:00
|
|
|
}
|
|
|
|
|
2022-02-11 01:08:35 -06:00
|
|
|
impl NativeLibKind {
|
|
|
|
pub fn has_modifiers(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
NativeLibKind::Static { bundle, whole_archive } => {
|
|
|
|
bundle.is_some() || whole_archive.is_some()
|
|
|
|
}
|
|
|
|
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
|
|
|
|
as_needed.is_some()
|
|
|
|
}
|
2022-07-19 04:00:28 -05:00
|
|
|
NativeLibKind::RawDylib | NativeLibKind::Unspecified | NativeLibKind::LinkArg => false,
|
2022-02-11 01:08:35 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 23:45:09 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
2022-04-19 03:43:09 -05:00
|
|
|
#[derive(HashStable_Generic)]
|
2021-03-24 23:45:09 -05:00
|
|
|
pub struct NativeLib {
|
|
|
|
pub name: String,
|
|
|
|
pub new_name: Option<String>,
|
|
|
|
pub kind: NativeLibKind,
|
|
|
|
pub verbatim: Option<bool>,
|
|
|
|
}
|
|
|
|
|
2022-02-11 01:08:35 -06:00
|
|
|
impl NativeLib {
|
|
|
|
pub fn has_modifiers(&self) -> bool {
|
|
|
|
self.verbatim.is_some() || self.kind.has_modifiers()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 15:27:42 -06:00
|
|
|
/// A path that has been canonicalized along with its original, non-canonicalized form
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
|
|
pub struct CanonicalizedPath {
|
|
|
|
// Optional since canonicalization can sometimes fail
|
|
|
|
canonicalized: Option<PathBuf>,
|
|
|
|
original: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CanonicalizedPath {
|
|
|
|
pub fn new(path: &Path) -> Self {
|
|
|
|
Self { original: path.to_owned(), canonicalized: std::fs::canonicalize(path).ok() }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn canonicalized(&self) -> &PathBuf {
|
|
|
|
self.canonicalized.as_ref().unwrap_or(self.original())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn original(&self) -> &PathBuf {
|
|
|
|
&self.original
|
|
|
|
}
|
|
|
|
}
|