From 91bd079e23b6a2128ef605de316465068ba355d8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 19 Nov 2018 22:14:05 -0800 Subject: [PATCH 1/4] 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. --- Cargo.toml | 7 +++++-- libc-test/build.rs | 2 +- src/lib.rs | 21 ++++++++++++++++----- src/unix/bsd/apple/mod.rs | 4 ++-- src/unix/mod.rs | 7 ++++--- src/windows.rs | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 719470d3..f3e57f83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] - name = "libc" -version = "0.2.43" +version = "0.2.44" authors = ["The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -19,10 +18,14 @@ exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml"] travis-ci = { repository = "rust-lang/libc" } appveyor = { repository = "rust-lang/libc", project_name = "rust-lang-libs/libc" } +[dependencies] +rustc-std-workspace-core = { version = "1.0.0", optional = true } + [features] default = ["use_std"] use_std = [] align = [] +rustc-dep-of-std = ['align', 'rustc-std-workspace-core'] [workspace] members = ["libc-test"] diff --git a/libc-test/build.rs b/libc-test/build.rs index 5fc9aeb7..ca0b7a2e 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -441,7 +441,7 @@ fn main() { // which is absent in glibc, has to be defined. "__timeval" if linux => true, - // Fixed on stdbuild with repr(packed(4)) + // Fixed on feature=align with repr(packed(4)) // Once repr_packed stabilizes we can fix this unconditionally // and remove this check. "kevent" | "shmid_ds" if apple && x86_64 => true, diff --git a/src/lib.rs b/src/lib.rs index 54f67895..42471d17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,22 +150,33 @@ ) )] // Attributes needed when building as part of the standard library -#![cfg_attr(feature = "stdbuild", feature(staged_api, cfg_target_vendor))] -#![cfg_attr(feature = "stdbuild", feature(link_cfg, repr_packed))] -#![cfg_attr(feature = "stdbuild", allow(warnings))] +#![cfg_attr(feature = "rustc-dep-of-std", feature(staged_api, cfg_target_vendor))] +#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, repr_packed))] +#![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] +#![cfg_attr(feature = "rustc-dep-of-std", no_core)] +#![cfg_attr(feature = "rustc-dep-of-std", allow(warnings))] #![cfg_attr( - feature = "stdbuild", + feature = "rustc-dep-of-std", unstable( feature = "libc", reason = "use `libc` from crates.io", issue = "27783" ) )] -#![cfg_attr(not(feature = "use_std"), no_std)] +#![cfg_attr(not(any(feature = "use_std", feature = "rustc-dep-of-std")), no_std)] #[cfg(all(not(cross_platform_docs), feature = "use_std"))] extern crate std as core; +#[cfg(feature = "rustc-dep-of-std")] +extern crate rustc_std_workspace_core as core; +#[cfg(feature = "rustc-dep-of-std")] +#[allow(unused_imports)] +use core::iter; +#[cfg(feature = "rustc-dep-of-std")] +#[allow(unused_imports)] +use core::option; + #[macro_use] mod macros; diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index ee8108de..38f211eb 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -245,7 +245,7 @@ s! { pub f_reserved: [::uint32_t; 8], } - #[cfg_attr(feature = "stdbuild", repr(packed(4)))] + #[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))] pub struct kevent { pub ident: ::uintptr_t, pub filter: ::int16_t, @@ -535,7 +535,7 @@ s! { pub _key: ::key_t, } - #[cfg_attr(feature = "stdbuild", repr(packed(4)))] + #[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))] pub struct shmid_ds { pub shm_perm: ipc_perm, pub shm_segsz: ::size_t, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 2d25690b..b9201897 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -318,17 +318,18 @@ cfg_if! { // cargo build, don't pull in anything extra as the libstd dep // already pulls in all libs. } else if #[cfg(target_env = "musl")] { - #[cfg_attr(feature = "stdbuild", + #[cfg_attr(feature = "rustc-dep-of-std", link(name = "c", kind = "static", cfg(target_feature = "crt-static")))] - #[cfg_attr(feature = "stdbuild", + #[cfg_attr(feature = "rustc-dep-of-std", link(name = "c", cfg(not(target_feature = "crt-static"))))] extern {} } else if #[cfg(target_os = "emscripten")] { #[link(name = "c")] extern {} } else if #[cfg(all(target_os = "netbsd", - feature = "stdbuild", target_vendor = "rumprun"))] { + feature = "rustc-dep-of-std", + target_vendor = "rumprun"))] { // Since we don't use -nodefaultlibs on Rumprun, libc is always pulled // in automatically by the linker. We avoid passing it explicitly, as it // causes some versions of binutils to crash with an assertion failure. diff --git a/src/windows.rs b/src/windows.rs index 4fc2c16a..9ed89925 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -190,7 +190,7 @@ pub const EILSEQ: ::c_int = 42; pub const STRUNCATE: ::c_int = 80; // inline comment below appeases style checker -#[cfg(all(target_env = "msvc", feature = "stdbuild"))] // " if " +#[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if " #[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))] #[link(name = "libcmt", cfg(target_feature = "crt-static"))] extern {} From 1eeba38558f5f83cd62901923f4bea8eea90bf82 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 21 Nov 2018 19:25:40 -0800 Subject: [PATCH 2/4] Remove unstable `libc` feature on rustc-dep-of-std No longer needed and this is done via other means in upstream rustc --- src/lib.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 42471d17..03e78041 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -150,19 +150,11 @@ ) )] // Attributes needed when building as part of the standard library -#![cfg_attr(feature = "rustc-dep-of-std", feature(staged_api, cfg_target_vendor))] +#![cfg_attr(feature = "rustc-dep-of-std", feature(cfg_target_vendor))] #![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, repr_packed))] #![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] #![cfg_attr(feature = "rustc-dep-of-std", no_core)] #![cfg_attr(feature = "rustc-dep-of-std", allow(warnings))] -#![cfg_attr( - feature = "rustc-dep-of-std", - unstable( - feature = "libc", - reason = "use `libc` from crates.io", - issue = "27783" - ) -)] #![cfg_attr(not(any(feature = "use_std", feature = "rustc-dep-of-std")), no_std)] #[cfg(all(not(cross_platform_docs), feature = "use_std"))] From a5bfa1a044da919347c0c82555f10e3d67cf9f6e Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 22 Nov 2018 17:48:32 +0100 Subject: [PATCH 3/4] Add alias for MAP_ANONYMOUS to Apple targets. Closes #1060 . --- src/unix/bsd/apple/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 38f211eb..2dc3245a 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -772,6 +772,7 @@ pub const MAP_SHARED: ::c_int = 0x0001; pub const MAP_PRIVATE: ::c_int = 0x0002; pub const MAP_FIXED: ::c_int = 0x0010; pub const MAP_ANON: ::c_int = 0x1000; +pub const MAP_ANONYMOUS: ::c_int = MAP_ANON; pub const VM_FLAGS_FIXED: ::c_int = 0x0000; pub const VM_FLAGS_ANYWHERE: ::c_int = 0x0001; From 7afe55be24a6475d45b4faba1082fae6816814b2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 22 Nov 2018 19:05:49 +0100 Subject: [PATCH 4/4] Use crates.io keywords and categories Closes #651 . --- Cargo.toml | 9 +++++---- README.md | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3e57f83..a89376c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,13 @@ readme = "README.md" repository = "https://github.com/rust-lang/libc" homepage = "https://github.com/rust-lang/libc" documentation = "http://doc.rust-lang.org/libc" -description = """ -A library for types and bindings to native C functions often found in libc or -other common platform libraries. -""" +keywords = ["libc", "ffi", "bindings", "operating", "system" ] +categories = ["external-ffi-bindings", "no-std", "os"] build = "build.rs" exclude = ["/ci/*", "/.travis.yml", "/appveyor.yml"] +description = """ +Raw FFI bindings to platform libraries like libc. +""" [badges] travis-ci = { repository = "rust-lang/libc" } diff --git a/README.md b/README.md index 1aba6474..6cf2d159 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ libc ==== -Rust wrapper over the system's `libc`. +Raw FFI bindings to platform libraries like `libc`. [![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc) [![Build status](https://ci.appveyor.com/api/projects/status/github/rust-lang/libc?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/libc)