Skip to content

Commit

Permalink
Auto merge of #951 - FraGag:rename-dox-cfg, r=alexcrichton
Browse files Browse the repository at this point in the history
Rename the dox configuration option to cross_platform_docs

The libc crate is used as a dependency of the Rust compiler. Its build system passes `--cfg dox` to all crates when generating their documentation. libc's documentation is generated when the build system is asked to generate the compiler documentation because `cargo doc` automatically documents all dependencies.

When the dox configuration option is enabled, libc disables its dependency on the core crate and provides the necessary definitions itself. The dox configuration option is meant for generating documentation for a multitude of targets even if the core crate for that target is not installed. However, when documenting the compiler, it's not necessary to do that; we can just use `core` or `std` as usual.

This change is motivated by the changes made to the compiler in rust-lang/rust#48171. With these changes, it's necessary to provide implementations of the `Clone` and `Copy` traits for some primitive types in the library that defines these traits (previously, these implementations were provided by the compiler). Normally, these traits (and thus the implementations) are provided by core, so any crate that uses `#![no_core]` must now provide its own copy of the implementations.

Because libc doesn't provide its own copy of the implementations yet, and because the compiler's build system passes `--cfg dox` to libc, generating the documentation for the compiler fails when generating documentation for libc. By renaming the configuration option, libc will use `core` or `std` and will thus have the necessary definitions for the documentation to be generated successfully.

**Note:** rust-lang/rust#48171 is blocked on this PR and on a release of libc including this change on crates.io. (Some crates in the compiler use libc as a submodule, while others use a version from crates.io.)
  • Loading branch information
bors committed Mar 19, 2018
2 parents 3e9ccfa + e1fd577 commit 84b80d9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 68 deletions.
114 changes: 56 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "libc"
version = "0.2.39"
version = "0.2.40"
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion ci/dox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cp ci/landing-page-head.html target/doc/index.html
for target in $TARGETS; do
echo documenting $target

rustdoc -o target/doc/$target --target $target src/lib.rs --cfg dox \
rustdoc -o target/doc/$target --target $target src/lib.rs --cfg cross_platform_docs \
--crate-name libc

echo "<li><a href="/libc/$target/libc/index.html">$target</a></li>" \
Expand Down
4 changes: 2 additions & 2 deletions src/dox.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pub use self::imp::*;

#[cfg(not(dox))]
#[cfg(not(cross_platform_docs))]
mod imp {
pub use core::option::Option;
pub use core::clone::Clone;
pub use core::marker::Copy;
pub use core::mem;
}

#[cfg(dox)]
#[cfg(cross_platform_docs)]
mod imp {
pub enum Option<T> {
Some(T),
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#![allow(bad_style, overflowing_literals, improper_ctypes)]
#![crate_type = "rlib"]
#![crate_name = "libc"]
#![cfg_attr(dox, feature(no_core, lang_items))]
#![cfg_attr(dox, no_core)]
#![cfg_attr(cross_platform_docs, feature(no_core, lang_items))]
#![cfg_attr(cross_platform_docs, no_core)]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico")]

Expand Down Expand Up @@ -97,7 +97,7 @@

#![cfg_attr(not(feature = "use_std"), no_std)]

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

#[macro_use] mod macros;
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ macro_rules! f {
$($body:stmt);*
})*) => ($(
#[inline]
#[cfg(not(dox))]
#[cfg(not(cross_platform_docs))]
pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
$($body);*
}

#[cfg(dox)]
#[cfg(cross_platform_docs)]
#[allow(dead_code)]
pub unsafe extern fn $i($($arg: $argty),*) -> $ret {
loop {}
Expand Down
2 changes: 1 addition & 1 deletion src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub const INADDR_BROADCAST: in_addr_t = 4294967295;
pub const INADDR_NONE: in_addr_t = 4294967295;

cfg_if! {
if #[cfg(dox)] {
if #[cfg(cross_platform_docs)] {
// on dox builds don't pull in anything
} else if #[cfg(target_os = "l4re")] {
// required libraries for L4Re are linked externally, ATM
Expand Down

0 comments on commit 84b80d9

Please sign in to comment.