xref: /rust-libc-0.2.174/src/lib.rs (revision a72002ac)
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 /// Type definitions that are coupled tighter to architecture than OS.
45 mod arch {
46     cfg_if! {
47         // This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
48         if #[cfg(all(
49             not(windows),
50             // FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
51             not(any(
52                 target_os = "macos",
53                 target_os = "ios",
54                 target_os = "tvos",
55                 target_os = "watchos",
56                 target_os = "visionos",
57             )),
58             any(
59                 target_arch = "aarch64",
60                 target_arch = "arm",
61                 target_arch = "csky",
62                 target_arch = "hexagon",
63                 target_arch = "msp430",
64                 target_arch = "powerpc",
65                 target_arch = "powerpc64",
66                 target_arch = "riscv64",
67                 target_arch = "riscv32",
68                 target_arch = "s390x",
69                 target_arch = "xtensa",
70             )
71         ))] {
72             // To be reexported as `c_char`
73             // FIXME(ctest): just name these `c_char` once `ctest` learns that these don't get
74             // exported.
75             pub type c_char_def = u8;
76         } else {
77             pub type c_char_def = i8;
78         }
79     }
80 }
81 
82 cfg_if! {
83     if #[cfg(windows)] {
84         mod fixed_width_ints;
85         pub use crate::fixed_width_ints::*;
86 
87         mod windows;
88         pub use crate::windows::*;
89 
90         prelude!();
91     } else if #[cfg(target_os = "fuchsia")] {
92         mod fixed_width_ints;
93         pub use crate::fixed_width_ints::*;
94 
95         mod fuchsia;
96         pub use crate::fuchsia::*;
97 
98         prelude!();
99     } else if #[cfg(target_os = "switch")] {
100         mod fixed_width_ints;
101         pub use fixed_width_ints::*;
102 
103         mod switch;
104         pub use switch::*;
105 
106         prelude!();
107     } else if #[cfg(target_os = "psp")] {
108         mod fixed_width_ints;
109         pub use crate::fixed_width_ints::*;
110 
111         mod psp;
112         pub use crate::psp::*;
113 
114         prelude!();
115     } else if #[cfg(target_os = "vxworks")] {
116         mod fixed_width_ints;
117         pub use crate::fixed_width_ints::*;
118 
119         mod vxworks;
120         pub use crate::vxworks::*;
121 
122         prelude!();
123     } else if #[cfg(target_os = "solid_asp3")] {
124         mod fixed_width_ints;
125         pub use crate::fixed_width_ints::*;
126 
127         mod solid;
128         pub use crate::solid::*;
129 
130         prelude!();
131     } else if #[cfg(unix)] {
132         mod fixed_width_ints;
133         pub use crate::fixed_width_ints::*;
134 
135         mod unix;
136         pub use crate::unix::*;
137 
138         prelude!();
139     } else if #[cfg(target_os = "hermit")] {
140         mod fixed_width_ints;
141         pub use crate::fixed_width_ints::*;
142 
143         mod hermit;
144         pub use crate::hermit::*;
145 
146         prelude!();
147     } else if #[cfg(target_os = "teeos")] {
148         mod fixed_width_ints;
149         pub use fixed_width_ints::*;
150 
151         mod teeos;
152         pub use teeos::*;
153 
154         prelude!();
155     } else if #[cfg(target_os = "trusty")] {
156         mod fixed_width_ints;
157         pub use crate::fixed_width_ints::*;
158 
159         mod trusty;
160         pub use crate::trusty::*;
161 
162         prelude!();
163     } else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
164         mod fixed_width_ints;
165         pub use crate::fixed_width_ints::*;
166 
167         mod sgx;
168         pub use crate::sgx::*;
169 
170         prelude!();
171     } else if #[cfg(any(target_env = "wasi", target_os = "wasi"))] {
172         mod fixed_width_ints;
173         pub use crate::fixed_width_ints::*;
174 
175         mod wasi;
176         pub use crate::wasi::*;
177 
178         prelude!();
179     } else if #[cfg(target_os = "xous")] {
180         mod fixed_width_ints;
181         pub use crate::fixed_width_ints::*;
182 
183         mod xous;
184         pub use crate::xous::*;
185 
186         prelude!();
187     } else {
188         // non-supported targets: empty...
189     }
190 }
191