Skip to content

Commit

Permalink
Add documentation on CFG and Cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 9, 2020
1 parent cf3c3f8 commit 983ccf8
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions gen/build/src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
use std::fmt::{self, Debug};
use std::marker::PhantomData;

/// Build configuration. See [CFG].
pub struct Cfg<'a> {
pub include_prefix: &'a str,
marker: PhantomData<*const ()>, // !Send + !Sync
}

/// Global configuration of the current build.
///
/// <br>
///
/// ## **`CFG.include_prefix`**
///
/// Presently the only exposed configuration is the `include_prefix`, the prefix
/// at which C++ code from your crate as well as directly dependent crates can
/// access the code generated during this build.
///
/// By default, the `include_prefix` is equal to the name of the current crate.
/// That means if our crate is called `demo` and has Rust source files in a
/// *src/* directory and maybe some handwritten C++ header files in an
/// *include/* directory, then the current crate as well as downstream crates
/// might include them as follows:
///
/// ```
/// # const _: &str = stringify! {
/// // include one of the handwritten headers:
/// #include "demo/include/wow.h"
///
/// // include a header generated from Rust cxx::bridge:
/// #include "demo/src/lib.rs.h"
/// # };
/// ```
///
/// By modifying `CFG.include_prefix` we can substitute a prefix that is
/// different from the crate name if desired. Here we'll change it to
/// `"path/to"` which will make import paths take the form
/// `"path/to/include/wow.h"` and `"path/to/src/lib.rs.h"`.
///
/// ```no_run
/// // build.rs
///
/// use cxx_build::CFG;
///
/// fn main() {
/// CFG.include_prefix = "path/to";
///
/// cxx_build::bridge("src/lib.rs")
/// .file("src/demo.cc") // probably contains `#include "path/to/src/lib.rs.h"`
/// /* ... */
/// .compile("demo");
/// }
/// ```
///
/// Note that cross-crate imports are only made available between **direct
/// dependencies**. Another crate must directly depend on your crate in order to
/// #include its headers; a transitive dependency is not sufficient.
/// Additionally, headers from a direct dependency are only importable if the
/// dependency's Cargo.toml manifest contains a `links` key. If not, its headers
/// will not be importable from outside of the same crate.
#[cfg(doc)]
pub static mut CFG: Cfg = Cfg {
include_prefix: "",
Expand Down

0 comments on commit 983ccf8

Please sign in to comment.