Replace libc::c_int with core::ffi::c_int

And remove the libc crate when it isn't needed
This commit is contained in:
Chris Denton 2024-03-09 02:03:22 +00:00
parent f3c6608861
commit b1f1039d8b
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
14 changed files with 35 additions and 15 deletions

View File

@ -15,5 +15,7 @@ doc = false
alloc = { path = "../alloc" } alloc = { path = "../alloc" }
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
core = { path = "../core" } core = { path = "../core" }
libc = { version = "0.2", default-features = false }
compiler_builtins = "0.1.0" compiler_builtins = "0.1.0"
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2", default-features = false }

View File

@ -14,7 +14,9 @@ doc = false
[dependencies] [dependencies]
alloc = { path = "../alloc" } alloc = { path = "../alloc" }
core = { path = "../core" } core = { path = "../core" }
libc = { version = "0.2", default-features = false }
unwind = { path = "../unwind" } unwind = { path = "../unwind" }
compiler_builtins = "0.1.0" compiler_builtins = "0.1.0"
cfg-if = "1.0" cfg-if = "1.0"
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2", default-features = false }

View File

@ -48,9 +48,9 @@
use alloc::boxed::Box; use alloc::boxed::Box;
use core::any::Any; use core::any::Any;
use core::ffi::{c_int, c_uint, c_void};
use core::mem::{self, ManuallyDrop}; use core::mem::{self, ManuallyDrop};
use core::ptr::{addr_of, addr_of_mut}; use core::ptr::{addr_of, addr_of_mut};
use libc::{c_int, c_uint, c_void};
// NOTE(nbdd0121): The `canary` field is part of stable ABI. // NOTE(nbdd0121): The `canary` field is part of stable ABI.
#[repr(C)] #[repr(C)]

View File

@ -17,7 +17,6 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true } panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" } panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true } core = { path = "../core", public = true }
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
compiler_builtins = { version = "0.1.105" } compiler_builtins = { version = "0.1.105" }
profiler_builtins = { path = "../profiler_builtins", optional = true } profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" } unwind = { path = "../unwind" }
@ -31,6 +30,12 @@ rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] }
miniz_oxide = { version = "0.7.0", optional = true, default-features = false } miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
addr2line = { version = "0.21.0", optional = true, default-features = false } addr2line = { version = "0.21.0", optional = true, default-features = false }
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
[target.'cfg(all(windows, target_env = "msvc"))'.dependencies]
libc = { version = "0.2.153", default-features = false }
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies] [target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] } object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }

View File

@ -431,6 +431,9 @@
#[allow(unused_imports)] // macros from `alloc` are not used on all platforms #[allow(unused_imports)] // macros from `alloc` are not used on all platforms
#[macro_use] #[macro_use]
extern crate alloc as alloc_crate; extern crate alloc as alloc_crate;
// Many compiler tests depend on libc being pulled in by std
// so include it here even if it's unused.
#[doc(masked)] #[doc(masked)]
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]
extern crate libc; extern crate libc;

View File

@ -11,7 +11,7 @@
#[cfg(not(unix))] #[cfg(not(unix))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
mod libc { mod libc {
pub use libc::c_int; pub use core::ffi::c_int;
pub type socklen_t = u32; pub type socklen_t = u32;
pub struct sockaddr; pub struct sockaddr;
#[derive(Clone)] #[derive(Clone)]

View File

@ -20,7 +20,7 @@
))] ))]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
mod libc { mod libc {
pub use libc::c_int; pub use core::ffi::c_int;
pub struct ucred; pub struct ucred;
pub struct cmsghdr; pub struct cmsghdr;
pub struct sockcred2; pub struct sockcred2;

View File

@ -34,7 +34,7 @@
target_os = "haiku", target_os = "haiku",
target_os = "nto", target_os = "nto",
)))] )))]
const MSG_NOSIGNAL: libc::c_int = 0x0; const MSG_NOSIGNAL: core::ffi::c_int = 0x0;
/// A Unix datagram socket. /// A Unix datagram socket.
/// ///
@ -317,7 +317,7 @@ pub fn peer_addr(&self) -> io::Result<SocketAddr> {
fn recv_from_flags( fn recv_from_flags(
&self, &self,
buf: &mut [u8], buf: &mut [u8],
flags: libc::c_int, flags: core::ffi::c_int,
) -> io::Result<(usize, SocketAddr)> { ) -> io::Result<(usize, SocketAddr)> {
let mut count = 0; let mut count = 0;
let addr = SocketAddr::new(|addr, len| unsafe { let addr = SocketAddr::new(|addr, len| unsafe {

View File

@ -79,14 +79,14 @@ pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
target_os = "espidf", target_os = "espidf",
target_os = "horizon" target_os = "horizon"
))] ))]
const backlog: libc::c_int = 128; const backlog: core::ffi::c_int = 128;
#[cfg(any( #[cfg(any(
target_os = "linux", target_os = "linux",
target_os = "freebsd", target_os = "freebsd",
target_os = "openbsd", target_os = "openbsd",
target_os = "macos" target_os = "macos"
))] ))]
const backlog: libc::c_int = -1; const backlog: core::ffi::c_int = -1;
#[cfg(not(any( #[cfg(not(any(
target_os = "windows", target_os = "windows",
target_os = "redox", target_os = "redox",
@ -138,9 +138,9 @@ pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
unsafe { unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const backlog: libc::c_int = -1; const backlog: core::ffi::c_int = -1;
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
const backlog: libc::c_int = 128; const backlog: core::ffi::c_int = 128;
cvt(libc::bind( cvt(libc::bind(
inner.as_raw_fd(), inner.as_raw_fd(),
core::ptr::addr_of!(socket_addr.addr) as *const _, core::ptr::addr_of!(socket_addr.addr) as *const _,

View File

@ -9,4 +9,6 @@ std = { path = "../std" }
core = { path = "../core" } core = { path = "../core" }
panic_unwind = { path = "../panic_unwind" } panic_unwind = { path = "../panic_unwind" }
panic_abort = { path = "../panic_abort" } panic_abort = { path = "../panic_abort" }
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.150", default-features = false } libc = { version = "0.2.150", default-features = false }

View File

@ -15,10 +15,12 @@ doc = false
[dependencies] [dependencies]
core = { path = "../core" } core = { path = "../core" }
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
compiler_builtins = "0.1.0" compiler_builtins = "0.1.0"
cfg-if = "1.0" cfg-if = "1.0"
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
[target.'cfg(target_os = "xous")'.dependencies] [target.'cfg(target_os = "xous")'.dependencies]
unwinding = { version = "0.2.1", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false } unwinding = { version = "0.2.1", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false }

View File

@ -12,6 +12,10 @@
)] )]
#![allow(internal_features)] #![allow(internal_features)]
// Force libc to be included even if unused. This is required by many platforms.
#[cfg(not(all(windows, target_env = "msvc")))]
extern crate libc as _;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_env = "msvc")] { if #[cfg(target_env = "msvc")] {
// Windows MSVC no extra unwinder support needed // Windows MSVC no extra unwinder support needed

View File

@ -1,6 +1,6 @@
#![allow(nonstandard_style)] #![allow(nonstandard_style)]
use libc::{c_int, c_void}; use core::ffi::{c_int, c_void};
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]

View File

@ -1,6 +1,6 @@
#![allow(nonstandard_style)] #![allow(nonstandard_style)]
use libc::{c_int, c_void}; use core::ffi::{c_int, c_void};
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]