1 use crate::session::Session;
2 use rustc_data_structures::profiling::VerboseTimingGuard;
3 use std::path::{Path, PathBuf};
6 pub fn timer<'a>(&'a self, what: &'static str) -> VerboseTimingGuard<'a> {
7 self.prof.verbose_generic_activity(what)
9 pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
10 self.prof.verbose_generic_activity(what).run(f)
14 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
15 #[derive(HashStable_Generic)]
16 pub enum NativeLibKind {
17 /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
19 /// Whether to bundle objects from static library into produced rlib
21 /// Whether to link static library without throwing any object files away
22 whole_archive: Option<bool>,
24 /// Dynamic library (e.g. `libfoo.so` on Linux)
25 /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
27 /// Whether the dynamic library will be linked only if it satisfies some undefined symbols
28 as_needed: Option<bool>,
30 /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
32 /// A macOS-specific kind of dynamic libraries.
34 /// Whether the framework will be linked only if it satisfies some undefined symbols
35 as_needed: Option<bool>,
37 /// The library kind wasn't specified, `Dylib` is currently used as a default.
42 pub fn has_modifiers(&self) -> bool {
44 NativeLibKind::Static { bundle, whole_archive } => {
45 bundle.is_some() || whole_archive.is_some()
47 NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
50 NativeLibKind::RawDylib | NativeLibKind::Unspecified => false,
55 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
56 #[derive(HashStable_Generic)]
57 pub struct NativeLib {
59 pub new_name: Option<String>,
60 pub kind: NativeLibKind,
61 pub verbatim: Option<bool>,
65 pub fn has_modifiers(&self) -> bool {
66 self.verbatim.is_some() || self.kind.has_modifiers()
70 /// A path that has been canonicalized along with its original, non-canonicalized form
71 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
72 pub struct CanonicalizedPath {
73 // Optional since canonicalization can sometimes fail
74 canonicalized: Option<PathBuf>,
78 impl CanonicalizedPath {
79 pub fn new(path: &Path) -> Self {
80 Self { original: path.to_owned(), canonicalized: std::fs::canonicalize(path).ok() }
83 pub fn canonicalized(&self) -> &PathBuf {
84 self.canonicalized.as_ref().unwrap_or(self.original())
87 pub fn original(&self) -> &PathBuf {