Skip to content

Commit

Permalink
Rename the dox configuration option to cross_platform_docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FraGag committed Mar 18, 2018
1 parent 3e9ccfa commit 18341fd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
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 18341fd

Please sign in to comment.