]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_session/src/utils.rs
Auto merge of #81047 - glittershark:stabilize-cmp-min-max-by, r=kodraus
[rust.git] / compiler / rustc_session / src / utils.rs
1 use crate::session::Session;
2 use rustc_data_structures::profiling::VerboseTimingGuard;
3 use std::path::{Path, PathBuf};
4
5 impl Session {
6     pub fn timer<'a>(&'a self, what: &'static str) -> VerboseTimingGuard<'a> {
7         self.prof.verbose_generic_activity(what)
8     }
9     pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
10         self.prof.verbose_generic_activity(what).run(f)
11     }
12 }
13
14 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
15 pub enum NativeLibKind {
16     /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included
17     /// when linking a final binary, but not when archiving an rlib.
18     StaticNoBundle,
19     /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included
20     /// when linking a final binary, but also included when archiving an rlib.
21     StaticBundle,
22     /// Dynamic library (e.g. `libfoo.so` on Linux)
23     /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
24     Dylib,
25     /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
26     RawDylib,
27     /// A macOS-specific kind of dynamic libraries.
28     Framework,
29     /// The library kind wasn't specified, `Dylib` is currently used as a default.
30     Unspecified,
31 }
32
33 rustc_data_structures::impl_stable_hash_via_hash!(NativeLibKind);
34
35 /// A path that has been canonicalized along with its original, non-canonicalized form
36 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
37 pub struct CanonicalizedPath {
38     // Optional since canonicalization can sometimes fail
39     canonicalized: Option<PathBuf>,
40     original: PathBuf,
41 }
42
43 impl CanonicalizedPath {
44     pub fn new(path: &Path) -> Self {
45         Self { original: path.to_owned(), canonicalized: std::fs::canonicalize(path).ok() }
46     }
47
48     pub fn canonicalized(&self) -> &PathBuf {
49         self.canonicalized.as_ref().unwrap_or(self.original())
50     }
51
52     pub fn original(&self) -> &PathBuf {
53         &self.original
54     }
55 }