Skip to main content

rustc_structures/
native_lib_kind.rs

1#[cfg(feature = "nightly")]
2use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
3
4#[derive(#[automatically_derived]
impl ::core::marker::Copy for NativeLibKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for NativeLibKind {
    #[inline]
    fn clone(&self) -> NativeLibKind {
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        let _: ::core::clone::AssertParamIsClone<Option<bool>>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for NativeLibKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NativeLibKind::Static {
                bundle: __self_0,
                whole_archive: __self_1,
                export_symbols: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f,
                    "Static", "bundle", __self_0, "whole_archive", __self_1,
                    "export_symbols", &__self_2),
            NativeLibKind::Dylib { as_needed: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Dylib",
                    "as_needed", &__self_0),
            NativeLibKind::RawDylib { as_needed: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "RawDylib", "as_needed", &__self_0),
            NativeLibKind::Framework { as_needed: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "Framework", "as_needed", &__self_0),
            NativeLibKind::LinkArg =>
                ::core::fmt::Formatter::write_str(f, "LinkArg"),
            NativeLibKind::WasmImportModule =>
                ::core::fmt::Formatter::write_str(f, "WasmImportModule"),
            NativeLibKind::Unspecified =>
                ::core::fmt::Formatter::write_str(f, "Unspecified"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for NativeLibKind {
    #[inline]
    fn eq(&self, other: &NativeLibKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (NativeLibKind::Static {
                    bundle: __self_0,
                    whole_archive: __self_1,
                    export_symbols: __self_2 }, NativeLibKind::Static {
                    bundle: __arg1_0,
                    whole_archive: __arg1_1,
                    export_symbols: __arg1_2 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                (NativeLibKind::Dylib { as_needed: __self_0 },
                    NativeLibKind::Dylib { as_needed: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                (NativeLibKind::RawDylib { as_needed: __self_0 },
                    NativeLibKind::RawDylib { as_needed: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                (NativeLibKind::Framework { as_needed: __self_0 },
                    NativeLibKind::Framework { as_needed: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NativeLibKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
        let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for NativeLibKind {
    #[inline]
    fn partial_cmp(&self, other: &NativeLibKind)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for NativeLibKind {
    #[inline]
    fn cmp(&self, other: &NativeLibKind) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
            ::core::cmp::Ordering::Equal =>
                match (self, other) {
                    (NativeLibKind::Static {
                        bundle: __self_0,
                        whole_archive: __self_1,
                        export_symbols: __self_2 }, NativeLibKind::Static {
                        bundle: __arg1_0,
                        whole_archive: __arg1_1,
                        export_symbols: __arg1_2 }) =>
                        match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
                            ::core::cmp::Ordering::Equal =>
                                match ::core::cmp::Ord::cmp(__self_1, __arg1_1) {
                                    ::core::cmp::Ordering::Equal =>
                                        ::core::cmp::Ord::cmp(__self_2, __arg1_2),
                                    cmp => cmp,
                                },
                            cmp => cmp,
                        },
                    (NativeLibKind::Dylib { as_needed: __self_0 },
                        NativeLibKind::Dylib { as_needed: __arg1_0 }) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (NativeLibKind::RawDylib { as_needed: __self_0 },
                        NativeLibKind::RawDylib { as_needed: __arg1_0 }) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (NativeLibKind::Framework { as_needed: __self_0 },
                        NativeLibKind::Framework { as_needed: __arg1_0 }) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    _ => ::core::cmp::Ordering::Equal,
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for NativeLibKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            NativeLibKind::Static {
                bundle: __self_0,
                whole_archive: __self_1,
                export_symbols: __self_2 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            NativeLibKind::Dylib { as_needed: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            NativeLibKind::RawDylib { as_needed: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            NativeLibKind::Framework { as_needed: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash)]
5#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            NativeLibKind {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    NativeLibKind::Static {
                        bundle: ref __binding_0,
                        whole_archive: ref __binding_1,
                        export_symbols: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                    NativeLibKind::Dylib { as_needed: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    NativeLibKind::RawDylib { as_needed: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    NativeLibKind::Framework { as_needed: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    NativeLibKind::LinkArg => {}
                    NativeLibKind::WasmImportModule => {}
                    NativeLibKind::Unspecified => {}
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for NativeLibKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NativeLibKind::Static {
                            bundle: ref __binding_0,
                            whole_archive: ref __binding_1,
                            export_symbols: ref __binding_2 } => {
                            0usize
                        }
                        NativeLibKind::Dylib { as_needed: ref __binding_0 } => {
                            1usize
                        }
                        NativeLibKind::RawDylib { as_needed: ref __binding_0 } => {
                            2usize
                        }
                        NativeLibKind::Framework { as_needed: ref __binding_0 } => {
                            3usize
                        }
                        NativeLibKind::LinkArg => { 4usize }
                        NativeLibKind::WasmImportModule => { 5usize }
                        NativeLibKind::Unspecified => { 6usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NativeLibKind::Static {
                        bundle: ref __binding_0,
                        whole_archive: ref __binding_1,
                        export_symbols: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    NativeLibKind::Dylib { as_needed: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NativeLibKind::RawDylib { as_needed: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NativeLibKind::Framework { as_needed: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NativeLibKind::LinkArg => {}
                    NativeLibKind::WasmImportModule => {}
                    NativeLibKind::Unspecified => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for NativeLibKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        NativeLibKind::Static {
                            bundle: ::rustc_serialize::Decodable::decode(__decoder),
                            whole_archive: ::rustc_serialize::Decodable::decode(__decoder),
                            export_symbols: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    1usize => {
                        NativeLibKind::Dylib {
                            as_needed: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    2usize => {
                        NativeLibKind::RawDylib {
                            as_needed: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    3usize => {
                        NativeLibKind::Framework {
                            as_needed: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    4usize => { NativeLibKind::LinkArg }
                    5usize => { NativeLibKind::WasmImportModule }
                    6usize => { NativeLibKind::Unspecified }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NativeLibKind`, expected 0..7, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext))]
6pub enum NativeLibKind {
7    /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
8    Static {
9        /// Whether to bundle objects from static library into produced rlib
10        bundle: Option<bool>,
11        /// Whether to link static library without throwing any object files away
12        whole_archive: Option<bool>,
13        /// Whether to export c static library symbols
14        export_symbols: Option<bool>,
15    },
16    /// Dynamic library (e.g. `libfoo.so` on Linux)
17    /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
18    Dylib {
19        /// Whether the dynamic library will be linked only if it satisfies some undefined symbols
20        as_needed: Option<bool>,
21    },
22    /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
23    /// On Linux, it refers to a generated shared library stub.
24    RawDylib {
25        /// Whether the dynamic library will be linked only if it satisfies some undefined symbols
26        as_needed: Option<bool>,
27    },
28    /// A macOS-specific kind of dynamic libraries.
29    Framework {
30        /// Whether the framework will be linked only if it satisfies some undefined symbols
31        as_needed: Option<bool>,
32    },
33    /// Argument which is passed to linker, relative order with libraries and other arguments
34    /// is preserved
35    LinkArg,
36
37    /// Module imported from WebAssembly
38    WasmImportModule,
39
40    /// The library kind wasn't specified, `Dylib` is currently used as a default.
41    Unspecified,
42}
43
44impl NativeLibKind {
45    pub fn has_modifiers(&self) -> bool {
46        match self {
47            NativeLibKind::Static { bundle, whole_archive, export_symbols } => {
48                bundle.is_some() || whole_archive.is_some() || export_symbols.is_some()
49            }
50            NativeLibKind::Dylib { as_needed }
51            | NativeLibKind::Framework { as_needed }
52            | NativeLibKind::RawDylib { as_needed } => as_needed.is_some(),
53            NativeLibKind::Unspecified
54            | NativeLibKind::LinkArg
55            | NativeLibKind::WasmImportModule => false,
56        }
57    }
58
59    pub fn is_statically_included(&self) -> bool {
60        #[allow(non_exhaustive_omitted_patterns)] match self {
    NativeLibKind::Static { .. } => true,
    _ => false,
}matches!(self, NativeLibKind::Static { .. })
61    }
62
63    pub fn is_dllimport(&self) -> bool {
64        #[allow(non_exhaustive_omitted_patterns)] match self {
    NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib { .. } |
        NativeLibKind::Unspecified => true,
    _ => false,
}matches!(
65            self,
66            NativeLibKind::Dylib { .. }
67                | NativeLibKind::RawDylib { .. }
68                | NativeLibKind::Unspecified
69        )
70    }
71}