xref: /rust-libc-0.2.174/src/lib.rs (revision 7cbbfedb)
1 //! libc - Raw FFI bindings to platforms' system libraries
2 #![crate_name = "libc"]
3 #![crate_type = "rlib"]
4 #![allow(
5     renamed_and_removed_lints, // Keep this order.
6     unknown_lints, // Keep this order.
7     bad_style,
8     overflowing_literals,
9     improper_ctypes,
10     // This lint is renamed but we run CI for old stable rustc so should be here.
11     redundant_semicolon,
12     redundant_semicolons,
13     unused_macros,
14     unused_macro_rules,
15     // FIXME: temporarily allow dead_code to fix CI:
16     // - https://github.com/rust-lang/libc/issues/3740
17     // - https://github.com/rust-lang/rust/pull/126456
18     dead_code,
19 )]
20 #![cfg_attr(libc_deny_warnings, deny(warnings))]
21 // Attributes needed when building as part of the standard library
22 #![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
23 #![cfg_attr(libc_thread_local, feature(thread_local))]
24 #![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
25 // DIFF(1.0): The thread local references that raise this lint were removed in 1.0
26 #![cfg_attr(feature = "rustc-dep-of-std", allow(static_mut_refs))]
27 // Enable extra lints:
28 #![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))]
29 #![deny(missing_copy_implementations, safe_packed_borrows)]
30 #![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
31 #![cfg_attr(feature = "rustc-dep-of-std", no_core)]
32 
33 #[macro_use]
34 mod macros;
35 
36 cfg_if! {
37     if #[cfg(feature = "rustc-dep-of-std")] {
38         extern crate rustc_std_workspace_core as core;
39     }
40 }
41 
42 pub use core::ffi::c_void;
43 
44 cfg_if! {
45     // This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
46     if #[cfg(all(
47         not(windows),
48         // FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
49         not(any(
50             target_os = "macos",
51             target_os = "ios",
52             target_os = "tvos",
53             target_os = "watchos",
54             target_os = "visionos",
55         )),
56         any(
57             target_arch = "aarch64",
58             target_arch = "arm",
59             target_arch = "csky",
60             target_arch = "hexagon",
61             target_arch = "msp430",
62             target_arch = "powerpc",
63             target_arch = "powerpc64",
64             target_arch = "riscv64",
65             target_arch = "riscv32",
66             target_arch = "s390x",
67             target_arch = "xtensa",
68         )
69     ))] {
70         pub type c_char = u8;
71     } else {
72         pub type c_char = i8;
73     }
74 }
75 
76 cfg_if! {
77     if #[cfg(windows)] {
78         mod fixed_width_ints;
79         pub use crate::fixed_width_ints::*;
80 
81         mod windows;
82         pub use crate::windows::*;
83 
84         prelude!();
85     } else if #[cfg(target_os = "fuchsia")] {
86         mod fixed_width_ints;
87         pub use crate::fixed_width_ints::*;
88 
89         mod fuchsia;
90         pub use crate::fuchsia::*;
91 
92         prelude!();
93     } else if #[cfg(target_os = "switch")] {
94         mod fixed_width_ints;
95         pub use fixed_width_ints::*;
96 
97         mod switch;
98         pub use switch::*;
99 
100         prelude!();
101     } else if #[cfg(target_os = "psp")] {
102         mod fixed_width_ints;
103         pub use crate::fixed_width_ints::*;
104 
105         mod psp;
106         pub use crate::psp::*;
107 
108         prelude!();
109     } else if #[cfg(target_os = "vxworks")] {
110         mod fixed_width_ints;
111         pub use crate::fixed_width_ints::*;
112 
113         mod vxworks;
114         pub use crate::vxworks::*;
115 
116         prelude!();
117     } else if #[cfg(target_os = "solid_asp3")] {
118         mod fixed_width_ints;
119         pub use crate::fixed_width_ints::*;
120 
121         mod solid;
122         pub use crate::solid::*;
123 
124         prelude!();
125     } else if #[cfg(unix)] {
126         mod fixed_width_ints;
127         pub use crate::fixed_width_ints::*;
128 
129         mod unix;
130         pub use crate::unix::*;
131 
132         prelude!();
133     } else if #[cfg(target_os = "hermit")] {
134         mod fixed_width_ints;
135         pub use crate::fixed_width_ints::*;
136 
137         mod hermit;
138         pub use crate::hermit::*;
139 
140         prelude!();
141     } else if #[cfg(target_os = "teeos")] {
142         mod fixed_width_ints;
143         pub use fixed_width_ints::*;
144 
145         mod teeos;
146         pub use teeos::*;
147 
148         prelude!();
149     } else if #[cfg(target_os = "trusty")] {
150         mod fixed_width_ints;
151         pub use crate::fixed_width_ints::*;
152 
153         mod trusty;
154         pub use crate::trusty::*;
155 
156         prelude!();
157     } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
158         mod fixed_width_ints;
159         pub use crate::fixed_width_ints::*;
160 
161         mod sgx;
162         pub use crate::sgx::*;
163 
164         prelude!();
165     } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
166         mod fixed_width_ints;
167         pub use crate::fixed_width_ints::*;
168 
169         mod wasi;
170         pub use crate::wasi::*;
171 
172         prelude!();
173     } else if #[cfg(target_os = "xous")] {
174         mod fixed_width_ints;
175         pub use crate::fixed_width_ints::*;
176 
177         mod xous;
178         pub use crate::xous::*;
179 
180         prelude!();
181     } else {
182         // non-supported targets: empty...
183     }
184 }
185