Split cxx runtime and build components
diff --git a/src/lib.rs b/src/lib.rs
index cff1e88..7e8e9ec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -224,8 +224,7 @@
//! // build.rs
//!
//! fn main() {
-//! cxx::Build::new()
-//! .bridge("src/main.rs") // returns a cc::Build
+//! cxx_build::bridge("src/main.rs") // returns a cc::Build
//! .file("../demo-cxx/demo.cc")
//! .flag("-std=c++11")
//! .compile("cxxbridge-demo");
@@ -363,18 +362,14 @@
mod cxx_string;
mod cxx_vector;
-mod error;
mod exception;
mod function;
-mod gen;
mod opaque;
-mod paths;
mod result;
mod rust_sliceu8;
mod rust_str;
mod rust_string;
mod rust_vec;
-mod syntax;
mod unique_ptr;
mod unwind;
@@ -398,107 +393,3 @@
pub use crate::unique_ptr::UniquePtrTarget;
pub use crate::unwind::catch_unwind;
}
-
-use crate::error::Result;
-use crate::gen::Opt;
-use anyhow::anyhow;
-use std::fs;
-use std::io::{self, Write};
-use std::path::Path;
-use std::process;
-
-/// The CXX code generator for constructing and compiling C++ code.
-///
-/// This is intended to be used from Cargo build scripts to execute CXX's
-/// C++ code generator, set up any additional compiler flags depending on
-/// the use case, and make the C++ compiler invocation.
-///
-/// <br>
-///
-/// # Example
-///
-/// Example of a canonical Cargo build script that builds a CXX bridge:
-///
-/// ```no_run
-/// // build.rs
-///
-/// fn main() {
-/// cxx::Build::new()
-/// .bridge("src/main.rs")
-/// .file("../demo-cxx/demo.cc")
-/// .flag("-std=c++11")
-/// .compile("cxxbridge-demo");
-///
-/// println!("cargo:rerun-if-changed=src/main.rs");
-/// println!("cargo:rerun-if-changed=../demo-cxx/demo.h");
-/// println!("cargo:rerun-if-changed=../demo-cxx/demo.cc");
-/// }
-/// ```
-///
-/// A runnable working setup with this build script is shown in the
-/// *demo-rs* and *demo-cxx* directories of [https://github.com/dtolnay/cxx].
-///
-/// [https://github.com/dtolnay/cxx]: https://github.com/dtolnay/cxx
-///
-/// <br>
-///
-/// # Alternatives
-///
-/// For use in non-Cargo builds like Bazel or Buck, CXX provides an
-/// alternate way of invoking the C++ code generator as a standalone command
-/// line tool. The tool is packaged as the `cxxbridge-cmd` crate.
-///
-/// ```bash
-/// $ cargo install cxxbridge-cmd # or build it from the repo
-///
-/// $ cxxbridge src/main.rs --header > path/to/mybridge.h
-/// $ cxxbridge src/main.rs > path/to/mybridge.cc
-/// ```
-#[must_use]
-pub struct Build {
- _private: (),
-}
-
-impl Build {
- /// Begin with a [`cc::Build`] in its default configuration.
- pub fn new() -> Self {
- Build { _private: () }
- }
-
- /// This returns a [`cc::Build`] on which you should continue to set up
- /// any additional source files or compiler flags, and lastly call its
- /// [`compile`] method to execute the C++ build.
- ///
- /// [`compile`]: https://docs.rs/cc/1.0.49/cc/struct.Build.html#method.compile
- #[must_use]
- pub fn bridge(&self, rust_source_file: impl AsRef<Path>) -> cc::Build {
- match try_generate_bridge(rust_source_file.as_ref()) {
- Ok(build) => build,
- Err(err) => {
- let _ = writeln!(io::stderr(), "\n\ncxxbridge error: {:?}\n\n", anyhow!(err));
- process::exit(1);
- }
- }
- }
-}
-
-fn try_generate_bridge(rust_source_file: &Path) -> Result<cc::Build> {
- let header = gen::do_generate_header(rust_source_file, Opt::default());
- let header_path = paths::out_with_extension(rust_source_file, ".h")?;
- fs::create_dir_all(header_path.parent().unwrap())?;
- fs::write(&header_path, header)?;
- paths::symlink_header(&header_path, rust_source_file);
-
- let bridge = gen::do_generate_bridge(rust_source_file, Opt::default());
- let bridge_path = paths::out_with_extension(rust_source_file, ".cc")?;
- fs::write(&bridge_path, bridge)?;
- let mut build = paths::cc_build();
- build.file(&bridge_path);
-
- let ref cxx_h = paths::include_dir()?.join("rust").join("cxx.h");
- let _ = fs::create_dir_all(cxx_h.parent().unwrap());
- let _ = fs::remove_file(cxx_h);
- let _ = fs::write(cxx_h, gen::include::HEADER);
-
- Ok(build)
-}