Repository: dtolnay/cxx (rust)

Issue:
Decide header include path
The current setup exposes our C++ header as:

```cpp
#include "cxxbridge/cxxbridge.h"
```

This isn't great because of the repetition, and also because all the symbols in the header are namespaced under `rust::` so an include path with rust in the name somewhere may make more sense.

Something like:

- `#include "cxxbridge/rust.h"`
- `#include "rust/cxxbridge.h"`
- `#include "rust/cxx.h"`

Pull request:
Move header include path to rust/cxx.h
Closes #61.

Patch:
diff --git a/BUCK b/BUCK
index 2d127536..2f80c9b0 100644
--- a/BUCK
+++ b/BUCK
@@ -38,11 +38,11 @@ rust_binary(
 
 cxx_library(
     name = "core",
-    srcs = ["src/cxxbridge.cc"],
+    srcs = ["src/cxx.cc"],
     visibility = ["PUBLIC"],
-    header_namespace = "cxxbridge",
+    header_namespace = "rust",
     exported_headers = {
-        "cxxbridge.h": "include/cxxbridge.h",
+        "cxx.h": "include/cxx.h",
     },
     exported_linker_flags = ["-lstdc++"],
 )
diff --git a/BUILD b/BUILD
index 0405df13..db222037 100644
--- a/BUILD
+++ b/BUILD
@@ -3,7 +3,7 @@ load("//tools/bazel:rust.bzl", "rust_binary", "rust_library")
 rust_library(
     name = "cxx",
     srcs = glob(["src/**/*.rs"]),
-    data = ["src/gen/include/cxxbridge.h"],
+    data = ["src/gen/include/cxx.h"],
     visibility = ["//visibility:public"],
     deps = [
         ":core-lib",
@@ -23,7 +23,7 @@ rust_library(
 rust_binary(
     name = "codegen",
     srcs = glob(["cmd/src/**/*.rs"]),
-    data = ["cmd/src/gen/include/cxxbridge.h"],
+    data = ["cmd/src/gen/include/cxx.h"],
     visibility = ["//visibility:public"],
     deps = [
         "//third-party:anyhow",
@@ -39,16 +39,16 @@ rust_binary(
 
 cc_library(
     name = "core",
-    hdrs = ["include/cxxbridge.h"],
-    include_prefix = "cxxbridge",
+    hdrs = ["include/cxx.h"],
+    include_prefix = "rust",
     strip_include_prefix = "include",
     visibility = ["//visibility:public"],
 )
 
 cc_library(
     name = "core-lib",
-    srcs = ["src/cxxbridge.cc"],
-    hdrs = ["include/cxxbridge.h"],
+    srcs = ["src/cxx.cc"],
+    hdrs = ["include/cxx.h"],
 )
 
 rust_library(
diff --git a/README.md b/README.md
index 07ea91e6..2886082b 100644
--- a/README.md
+++ b/README.md
@@ -306,9 +306,9 @@ of functions.
 <tr><td></td><td></td><td></td></tr>
 </table>
 
-The C++ API of the `cxxbridge` namespace is defined by the *include/cxxbridge.h*
-file in this repo. You will need to include this header in your C++ code when
-working with those types.
+The C++ API of the `rust` namespace is defined by the *include/cxx.h* file in
+this repo. You will need to include this header in your C++ code when working
+with those types.
 
 The following types are intended to be supported "soon" but are just not
 implemented yet. I don't expect any of these to be hard to make work but it's a
diff --git a/build.rs b/build.rs
index ea562c22..bdda779d 100644
--- a/build.rs
+++ b/build.rs
@@ -1,8 +1,8 @@
 fn main() {
     cc::Build::new()
-        .file("src/cxxbridge.cc")
+        .file("src/cxx.cc")
         .flag("-std=c++11")
         .compile("cxxbridge01");
-    println!("cargo:rerun-if-changed=src/cxxbridge.cc");
-    println!("cargo:rerun-if-changed=include/cxxbridge.h");
+    println!("cargo:rerun-if-changed=src/cxx.cc");
+    println!("cargo:rerun-if-changed=include/cxx.h");
 }
diff --git a/cmd/src/main.rs b/cmd/src/main.rs
index 26b6ef6b..06b3bbeb 100644
--- a/cmd/src/main.rs
+++ b/cmd/src/main.rs
@@ -14,7 +14,7 @@ use structopt::StructOpt;
     usage = "\
     cxxbridge <input>.rs              Emit .cc file for bridge to stdout
     cxxbridge <input>.rs --header     Emit .h file for bridge to stdout
-    cxxbridge --header                Emit cxxbridge.h header to stdout",
+    cxxbridge --header                Emit rust/cxx.h header to stdout",
     help_message = "Print help information",
     version_message = "Print version information"
 )]
diff --git a/demo-cxx/demo.h b/demo-cxx/demo.h
index a579986e..fafc4743 100644
--- a/demo-cxx/demo.h
+++ b/demo-cxx/demo.h
@@ -1,5 +1,5 @@
 #pragma once
-#include "cxxbridge/cxxbridge.h"
+#include "rust/cxx.h"
 #include <memory>
 #include <string>
 
diff --git a/gen/include.rs b/gen/include.rs
index e34d9d00..a4b416ad 100644
--- a/gen/include.rs
+++ b/gen/include.rs
@@ -1,6 +1,6 @@
 use std::fmt::{self, Display};
 
-pub static HEADER: &str = include_str!("include/cxxbridge.h");
+pub static HEADER: &str = include_str!("include/cxx.h");
 
 pub fn get(guard: &str) -> &'static str {
     let ifndef = format!("#ifndef {}", guard);
@@ -10,7 +10,7 @@ pub fn get(guard: &str) -> &'static str {
     if let (Some(begin), Some(end)) = (begin, end) {
         &HEADER[begin..end + endif.len()]
     } else {
-        panic!("not found in cxxbridge.h header: {}", guard)
+        panic!("not found in cxx.h header: {}", guard)
     }
 }
 
diff --git a/gen/write.rs b/gen/write.rs
index 601f7efc..9ab98faf 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -126,7 +126,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
     out.begin_block("inline namespace cxxbridge01");
 
     if needs_rust_box || needs_manually_drop || needs_maybe_uninit {
-        writeln!(out, "// #include \"cxxbridge.h\"");
+        writeln!(out, "// #include \"rust/cxx.h\"");
     }
 
     if needs_rust_box {
diff --git a/include/cxxbridge.h b/include/cxx.h
similarity index 100%
rename from include/cxxbridge.h
rename to include/cxx.h
diff --git a/src/cxxbridge.cc b/src/cxx.cc
similarity index 99%
rename from src/cxxbridge.cc
rename to src/cxx.cc
index b44204df..f7b02ecd 100644
--- a/src/cxxbridge.cc
+++ b/src/cxx.cc
@@ -1,4 +1,4 @@
-#include "../include/cxxbridge.h"
+#include "../include/cxx.h"
 #include <cstring>
 #include <iostream>
 #include <memory>
diff --git a/src/lib.rs b/src/lib.rs
index 006159a3..316918f8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -310,9 +310,9 @@
 //! <tr><td></td><td></td><td></td></tr>
 //! </table>
 //!
-//! The C++ API of the `cxxbridge` namespace is defined by the
-//! *include/cxxbridge.h* file in https://github.com/dtolnay/cxx. You will need
-//! to include this header in your C++ code when working with those types.
+//! The C++ API of the `rust` namespace is defined by the *include/cxx.h* file
+//! in https://github.com/dtolnay/cxx. You will need to include this header in
+//! your C++ code when working with those types.
 //!
 //! The following types are intended to be supported "soon" but are just not
 //! implemented yet. I don't expect any of these to be hard to make work but
@@ -463,10 +463,10 @@ fn try_generate_bridge(rust_source_file: &Path) -> Result<cc::Build> {
     let mut build = paths::cc_build();
     build.file(&bridge_path);
 
-    let ref cxxbridge_h = paths::include_dir()?.join("cxxbridge").join("cxxbridge.h");
-    let _ = fs::create_dir_all(cxxbridge_h.parent().unwrap());
-    let _ = fs::remove_file(cxxbridge_h);
-    let _ = fs::write(cxxbridge_h, gen::include::HEADER);
+    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)
 }


Test patch:
diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h
index f41cc5e0..7cff6fae 100644
--- a/tests/ffi/tests.h
+++ b/tests/ffi/tests.h
@@ -1,5 +1,5 @@
 #pragma once
-#include "cxxbridge/cxxbridge.h"
+#include "rust/cxx.h"
 #include <memory>
 #include <string>