Skip to content

Commit 91bd079

Browse files
committed
Prepare for being included via crates.io into std
This commit prepares the `libc` crate to be included directly into the standard library via crates.io. More details about this can be found on rust-lang/rust#56092, but the main idea is that this crate now depends on core/compiler-builtins explicitly (but off-by-default). The main caveat here is that this activates `no_core` when building as part of libstd, which means that it needs to explicitly have an `iter` and `option` module for the expansion of `for` loops to work.
1 parent 5b40375 commit 91bd079

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
2-
32
name = "libc"
4-
version = "0.2.43"
3+
version = "0.2.44"
54
authors = ["The Rust Project Developers"]
65
license = "MIT OR Apache-2.0"
76
readme = "README.md"
@@ -19,10 +18,14 @@ exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml"]
1918
travis-ci = { repository = "rust-lang/libc" }
2019
appveyor = { repository = "rust-lang/libc", project_name = "rust-lang-libs/libc" }
2120

21+
[dependencies]
22+
rustc-std-workspace-core = { version = "1.0.0", optional = true }
23+
2224
[features]
2325
default = ["use_std"]
2426
use_std = []
2527
align = []
28+
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
2629

2730
[workspace]
2831
members = ["libc-test"]

libc-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn main() {
441441
// which is absent in glibc, has to be defined.
442442
"__timeval" if linux => true,
443443

444-
// Fixed on stdbuild with repr(packed(4))
444+
// Fixed on feature=align with repr(packed(4))
445445
// Once repr_packed stabilizes we can fix this unconditionally
446446
// and remove this check.
447447
"kevent" | "shmid_ds" if apple && x86_64 => true,

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,33 @@
150150
)
151151
)]
152152
// Attributes needed when building as part of the standard library
153-
#![cfg_attr(feature = "stdbuild", feature(staged_api, cfg_target_vendor))]
154-
#![cfg_attr(feature = "stdbuild", feature(link_cfg, repr_packed))]
155-
#![cfg_attr(feature = "stdbuild", allow(warnings))]
153+
#![cfg_attr(feature = "rustc-dep-of-std", feature(staged_api, cfg_target_vendor))]
154+
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, repr_packed))]
155+
#![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))]
156+
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]
157+
#![cfg_attr(feature = "rustc-dep-of-std", allow(warnings))]
156158
#![cfg_attr(
157-
feature = "stdbuild",
159+
feature = "rustc-dep-of-std",
158160
unstable(
159161
feature = "libc",
160162
reason = "use `libc` from crates.io",
161163
issue = "27783"
162164
)
163165
)]
164-
#![cfg_attr(not(feature = "use_std"), no_std)]
166+
#![cfg_attr(not(any(feature = "use_std", feature = "rustc-dep-of-std")), no_std)]
165167

166168
#[cfg(all(not(cross_platform_docs), feature = "use_std"))]
167169
extern crate std as core;
168170

171+
#[cfg(feature = "rustc-dep-of-std")]
172+
extern crate rustc_std_workspace_core as core;
173+
#[cfg(feature = "rustc-dep-of-std")]
174+
#[allow(unused_imports)]
175+
use core::iter;
176+
#[cfg(feature = "rustc-dep-of-std")]
177+
#[allow(unused_imports)]
178+
use core::option;
179+
169180
#[macro_use]
170181
mod macros;
171182

src/unix/bsd/apple/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ s! {
245245
pub f_reserved: [::uint32_t; 8],
246246
}
247247

248-
#[cfg_attr(feature = "stdbuild", repr(packed(4)))]
248+
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
249249
pub struct kevent {
250250
pub ident: ::uintptr_t,
251251
pub filter: ::int16_t,
@@ -535,7 +535,7 @@ s! {
535535
pub _key: ::key_t,
536536
}
537537

538-
#[cfg_attr(feature = "stdbuild", repr(packed(4)))]
538+
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
539539
pub struct shmid_ds {
540540
pub shm_perm: ipc_perm,
541541
pub shm_segsz: ::size_t,

src/unix/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,18 @@ cfg_if! {
318318
// cargo build, don't pull in anything extra as the libstd dep
319319
// already pulls in all libs.
320320
} else if #[cfg(target_env = "musl")] {
321-
#[cfg_attr(feature = "stdbuild",
321+
#[cfg_attr(feature = "rustc-dep-of-std",
322322
link(name = "c", kind = "static",
323323
cfg(target_feature = "crt-static")))]
324-
#[cfg_attr(feature = "stdbuild",
324+
#[cfg_attr(feature = "rustc-dep-of-std",
325325
link(name = "c", cfg(not(target_feature = "crt-static"))))]
326326
extern {}
327327
} else if #[cfg(target_os = "emscripten")] {
328328
#[link(name = "c")]
329329
extern {}
330330
} else if #[cfg(all(target_os = "netbsd",
331-
feature = "stdbuild", target_vendor = "rumprun"))] {
331+
feature = "rustc-dep-of-std",
332+
target_vendor = "rumprun"))] {
332333
// Since we don't use -nodefaultlibs on Rumprun, libc is always pulled
333334
// in automatically by the linker. We avoid passing it explicitly, as it
334335
// causes some versions of binutils to crash with an assertion failure.

src/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub const EILSEQ: ::c_int = 42;
190190
pub const STRUNCATE: ::c_int = 80;
191191

192192
// inline comment below appeases style checker
193-
#[cfg(all(target_env = "msvc", feature = "stdbuild"))] // " if "
193+
#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if "
194194
#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
195195
#[link(name = "libcmt", cfg(target_feature = "crt-static"))]
196196
extern {}

0 commit comments

Comments
 (0)