Skip to content

Commit 97543b7

Browse files
committed
Replace libc::c_int with core::ffi::c_int
And remove the libc crate when it isn't needed
1 parent 5055f25 commit 97543b7

File tree

14 files changed

+35
-15
lines changed

14 files changed

+35
-15
lines changed

panic_abort/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ doc = false
1515
alloc = { path = "../alloc" }
1616
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
core = { path = "../core" }
18-
libc = { version = "0.2", default-features = false }
1918
compiler_builtins = "0.1.0"
19+
20+
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
21+
libc = { version = "0.2", default-features = false }

panic_unwind/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ doc = false
1414
[dependencies]
1515
alloc = { path = "../alloc" }
1616
core = { path = "../core" }
17-
libc = { version = "0.2", default-features = false }
1817
unwind = { path = "../unwind" }
1918
compiler_builtins = "0.1.0"
2019
cfg-if = "1.0"
20+
21+
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
22+
libc = { version = "0.2", default-features = false }

panic_unwind/src/seh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848

4949
use alloc::boxed::Box;
5050
use core::any::Any;
51+
use core::ffi::{c_int, c_uint, c_void};
5152
use core::mem::{self, ManuallyDrop};
5253
use core::ptr::{addr_of, addr_of_mut};
53-
use libc::{c_int, c_uint, c_void};
5454

5555
// NOTE(nbdd0121): The `canary` field is part of stable ABI.
5656
#[repr(C)]

std/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
2120
compiler_builtins = { version = "0.1.105" }
2221
profiler_builtins = { path = "../profiler_builtins", optional = true }
2322
unwind = { path = "../unwind" }
@@ -31,6 +30,12 @@ rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] }
3130
miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
3231
addr2line = { version = "0.21.0", optional = true, default-features = false }
3332

33+
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
34+
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
35+
36+
[target.'cfg(all(windows, target_env = "msvc"))'.dependencies]
37+
libc = { version = "0.2.153", default-features = false }
38+
3439
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
3540
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
3641

std/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ extern crate test;
431431
#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
432432
#[macro_use]
433433
extern crate alloc as alloc_crate;
434+
435+
// Many compiler tests depend on libc being pulled in by std
436+
// so include it here even if it's unused.
434437
#[doc(masked)]
435438
#[allow(unused_extern_crates)]
436439
extern crate libc;

std/src/os/unix/net/addr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{fmt, io, mem, ptr};
1111
#[cfg(not(unix))]
1212
#[allow(non_camel_case_types)]
1313
mod libc {
14-
pub use libc::c_int;
14+
pub use core::ffi::c_int;
1515
pub type socklen_t = u32;
1616
pub struct sockaddr;
1717
#[derive(Clone)]

std/src/os/unix/net/ancillary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::sys::net::Socket;
2020
))]
2121
#[allow(non_camel_case_types)]
2222
mod libc {
23-
pub use libc::c_int;
23+
pub use core::ffi::c_int;
2424
pub struct ucred;
2525
pub struct cmsghdr;
2626
pub struct sockcred2;

std/src/os/unix/net/datagram.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use libc::MSG_NOSIGNAL;
3434
target_os = "haiku",
3535
target_os = "nto",
3636
)))]
37-
const MSG_NOSIGNAL: libc::c_int = 0x0;
37+
const MSG_NOSIGNAL: core::ffi::c_int = 0x0;
3838

3939
/// A Unix datagram socket.
4040
///
@@ -317,7 +317,7 @@ impl UnixDatagram {
317317
fn recv_from_flags(
318318
&self,
319319
buf: &mut [u8],
320-
flags: libc::c_int,
320+
flags: core::ffi::c_int,
321321
) -> io::Result<(usize, SocketAddr)> {
322322
let mut count = 0;
323323
let addr = SocketAddr::new(|addr, len| unsafe {

std/src/os/unix/net/listener.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ impl UnixListener {
7979
target_os = "espidf",
8080
target_os = "horizon"
8181
))]
82-
const backlog: libc::c_int = 128;
82+
const backlog: core::ffi::c_int = 128;
8383
#[cfg(any(
8484
target_os = "linux",
8585
target_os = "freebsd",
8686
target_os = "openbsd",
8787
target_os = "macos"
8888
))]
89-
const backlog: libc::c_int = -1;
89+
const backlog: core::ffi::c_int = -1;
9090
#[cfg(not(any(
9191
target_os = "windows",
9292
target_os = "redox",
@@ -138,9 +138,9 @@ impl UnixListener {
138138
unsafe {
139139
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
140140
#[cfg(target_os = "linux")]
141-
const backlog: libc::c_int = -1;
141+
const backlog: core::ffi::c_int = -1;
142142
#[cfg(not(target_os = "linux"))]
143-
const backlog: libc::c_int = 128;
143+
const backlog: core::ffi::c_int = 128;
144144
cvt(libc::bind(
145145
inner.as_raw_fd(),
146146
core::ptr::addr_of!(socket_addr.addr) as *const _,

test/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ std = { path = "../std" }
99
core = { path = "../core" }
1010
panic_unwind = { path = "../panic_unwind" }
1111
panic_abort = { path = "../panic_abort" }
12+
13+
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
1214
libc = { version = "0.2.150", default-features = false }

unwind/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ doc = false
1515

1616
[dependencies]
1717
core = { path = "../core" }
18-
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
1918
compiler_builtins = "0.1.0"
2019
cfg-if = "1.0"
2120

21+
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
22+
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
23+
2224
[target.'cfg(target_os = "xous")'.dependencies]
2325
unwinding = { version = "0.2.1", features = ['rustc-dep-of-std', 'unwinder', 'fde-custom'], default-features = false }
2426

unwind/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
)]
1313
#![allow(internal_features)]
1414

15+
// Force libc to be included even if unused. This is required by many platforms.
16+
#[cfg(not(all(windows, target_env = "msvc")))]
17+
extern crate libc as _;
18+
1519
cfg_if::cfg_if! {
1620
if #[cfg(target_env = "msvc")] {
1721
// Windows MSVC no extra unwinder support needed

unwind/src/libunwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(nonstandard_style)]
22

3-
use libc::{c_int, c_void};
3+
use core::ffi::{c_int, c_void};
44

55
#[repr(C)]
66
#[derive(Debug, Copy, Clone, PartialEq)]

unwind/src/unwinding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(nonstandard_style)]
22

3-
use libc::{c_int, c_void};
3+
use core::ffi::{c_int, c_void};
44

55
#[repr(C)]
66
#[derive(Copy, Clone, PartialEq)]

0 commit comments

Comments
 (0)