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 /// Argument which is passed to linker, relative order with libraries and other arguments
40 /// The library kind wasn't specified, `Dylib` is currently used as a default.
45 pub fn has_modifiers(&self) -> bool
{
47 NativeLibKind
::Static { bundle, whole_archive }
=> {
48 bundle
.is_some() || whole_archive
.is_some()
50 NativeLibKind
::Dylib { as_needed }
| NativeLibKind
::Framework { as_needed }
=> {
53 NativeLibKind
::RawDylib
| NativeLibKind
::Unspecified
| NativeLibKind
::LinkArg
=> false,
58 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
59 #[derive(HashStable_Generic)]
60 pub struct NativeLib
{
62 pub new_name
: Option
<String
>,
63 pub kind
: NativeLibKind
,
64 pub verbatim
: Option
<bool
>,
68 pub fn has_modifiers(&self) -> bool
{
69 self.verbatim
.is_some() || self.kind
.has_modifiers()
73 /// A path that has been canonicalized along with its original, non-canonicalized form
74 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
75 pub struct CanonicalizedPath
{
76 // Optional since canonicalization can sometimes fail
77 canonicalized
: Option
<PathBuf
>,
81 impl CanonicalizedPath
{
82 pub fn new(path
: &Path
) -> Self {
83 Self { original: path.to_owned(), canonicalized: std::fs::canonicalize(path).ok() }
86 pub fn canonicalized(&self) -> &PathBuf
{
87 self.canonicalized
.as_ref().unwrap_or(self.original())
90 pub fn original(&self) -> &PathBuf
{