diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55431b61f..315bac2b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} - - run: cargo run --manifest-path demo-rs/Cargo.toml + - run: cargo run --manifest-path demo/Cargo.toml - run: cargo test --workspace --exclude cxx-test-suite msrv: @@ -43,7 +43,7 @@ jobs: steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@1.42.0 - - run: cargo run --manifest-path demo-rs/Cargo.toml + - run: cargo run --manifest-path demo/Cargo.toml buck: name: Buck @@ -66,7 +66,7 @@ jobs: cp third-party/Cargo.lock . cargo vendor --versioned-dirs --locked third-party/vendor - run: buck build :cxx#check --verbose=0 - - run: buck run demo-rs --verbose=0 + - run: buck run demo --verbose=0 - run: buck test ... --verbose=0 bazel: @@ -84,5 +84,5 @@ jobs: run: | cp third-party/Cargo.lock . cargo vendor --versioned-dirs --locked third-party/vendor - - run: bazel run demo-rs --verbose_failures --noshow_progress + - run: bazel run demo --verbose_failures --noshow_progress - run: bazel test ... --verbose_failures --noshow_progress diff --git a/Cargo.toml b/Cargo.toml index 5458398a4..c950d2e4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ description = "Safe interop between Rust and C++" repository = "https://github.com/dtolnay/cxx" documentation = "https://docs.rs/cxx" readme = "README.md" -exclude = ["/demo-cxx", "/gen", "/syntax", "/third-party"] +exclude = ["/demo", "/gen", "/syntax", "/third-party"] keywords = ["ffi"] categories = ["development-tools::ffi", "api-bindings"] @@ -34,7 +34,7 @@ rustversion = "1.0" trybuild = { version = "1.0.33", features = ["diff"] } [workspace] -members = ["demo-rs", "flags", "gen/build", "gen/cmd", "gen/lib", "macro", "tests/ffi"] +members = ["demo", "flags", "gen/build", "gen/cmd", "gen/lib", "macro", "tests/ffi"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/README.md b/README.md index 345ce7d4b..9c65df690 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,8 @@ function calls Rust's `len()`. ## Example -A runnable version of this example is provided under the *demo-rs* directory of -this repo (with the C++ side of the implementation in the *demo-cxx* directory). -To try it out, jump into demo-rs and run `cargo run`. +A runnable version of this example is provided under the *demo* directory of +this repo. To try it out, run `cargo run` from that directory. ```rust #[cxx::bridge] @@ -78,7 +77,7 @@ mod ffi { // One or more headers with the matching C++ declarations. Our code // generators don't read it but it gets #include'd and used in static // assertions to ensure our picture of the FFI boundary is accurate. - include!("demo-cxx/demo.h"); + include!("demo/include/demo.h"); // Zero or more opaque types which both languages can pass around but // only C++ can see the fields. @@ -107,10 +106,10 @@ get to call back and forth safely. Here are links to the complete set of source files involved in the demo: -- [demo-rs/src/main.rs](demo-rs/src/main.rs) -- [demo-rs/build.rs](demo-rs/build.rs) -- [demo-cxx/demo.h](demo-cxx/demo.h) -- [demo-cxx/demo.cc](demo-cxx/demo.cc) +- [demo/src/main.rs](demo/src/main.rs) +- [demo/build.rs](demo/build.rs) +- [demo/include/demo.h](demo/include/demo.h) +- [demo/src/demo.cc](demo/src/demo.cc) To look at the code generated in both languages for the example by the CXX code generators: @@ -118,10 +117,10 @@ generators: ```console # run Rust code generator and print to stdout # (requires https://github.com/dtolnay/cargo-expand) -$ cargo expand --manifest-path demo-rs/Cargo.toml +$ cargo expand --manifest-path demo/Cargo.toml # run C++ code generator and print to stdout -$ cargo run --manifest-path gen/cmd/Cargo.toml -- demo-rs/src/main.rs +$ cargo run --manifest-path gen/cmd/Cargo.toml -- demo/src/main.rs ```
@@ -228,13 +227,13 @@ cxx-build = "0.3" fn main() { cxx_build::bridge("src/main.rs") // returns a cc::Build - .file("../demo-cxx/demo.cc") + .file("src/demo.cc") .flag_if_supported("-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"); + println!("cargo:rerun-if-changed=src/demo.cc"); + println!("cargo:rerun-if-changed=include/demo.h"); } ``` diff --git a/demo-cxx/BUCK b/demo-cxx/BUCK deleted file mode 100644 index f60200bfe..000000000 --- a/demo-cxx/BUCK +++ /dev/null @@ -1,17 +0,0 @@ -cxx_library( - name = "demo-cxx", - srcs = ["demo.cc"], - compiler_flags = ["-std=c++14"], - visibility = ["PUBLIC"], - deps = [ - ":include", - "//demo-rs:include", - ], -) - -cxx_library( - name = "include", - exported_headers = ["demo.h"], - visibility = ["PUBLIC"], - deps = ["//:core"], -) diff --git a/demo-cxx/BUILD b/demo-cxx/BUILD deleted file mode 100644 index 7b1860ad8..000000000 --- a/demo-cxx/BUILD +++ /dev/null @@ -1,17 +0,0 @@ -cc_library( - name = "demo-cxx", - srcs = ["demo.cc"], - copts = ["-std=c++14"], - visibility = ["//visibility:public"], - deps = [ - ":include", - "//demo-rs:include", - ], -) - -cc_library( - name = "include", - hdrs = ["demo.h"], - visibility = ["//visibility:public"], - deps = ["//:core"], -) diff --git a/demo-rs/BUCK b/demo/BUCK similarity index 61% rename from demo-rs/BUCK rename to demo/BUCK index a3f460bb3..78e75e6ea 100644 --- a/demo-rs/BUCK +++ b/demo/BUCK @@ -1,10 +1,10 @@ rust_binary( - name = "demo-rs", - srcs = glob(["src/**"]), + name = "demo", + srcs = glob(["src/**/*.rs"]), deps = [ + ":demo-sys", ":gen", "//:cxx", - "//demo-cxx:demo-cxx", ], ) @@ -12,8 +12,8 @@ cxx_library( name = "gen", srcs = [":gen-source"], deps = [ + ":demo-include", ":include", - "//demo-cxx:include", ], ) @@ -38,5 +38,20 @@ cxx_library( exported_headers = { "src/main.rs.h": ":gen-header", }, - visibility = ["PUBLIC"], +) + +cxx_library( + name = "demo-sys", + srcs = ["src/demo.cc"], + compiler_flags = ["-std=c++14"], + deps = [ + ":demo-include", + ":include", + ], +) + +cxx_library( + name = "demo-include", + exported_headers = ["include/demo.h"], + deps = ["//:core"], ) diff --git a/demo-rs/BUILD b/demo/BUILD similarity index 62% rename from demo-rs/BUILD rename to demo/BUILD index e3ebb96be..1edc65c59 100644 --- a/demo-rs/BUILD +++ b/demo/BUILD @@ -1,12 +1,12 @@ load("//tools/bazel:rust.bzl", "rust_binary", "rust_library") rust_binary( - name = "demo-rs", - srcs = glob(["src/**"]), + name = "demo", + srcs = glob(["src/**/*.rs"]), deps = [ + ":demo-sys", ":gen", "//:cxx", - "//demo-cxx", ], ) @@ -14,8 +14,8 @@ cc_library( name = "gen", srcs = [":gen-source"], deps = [ + ":demo-include", ":include", - "//demo-cxx:include", ], ) @@ -38,6 +38,21 @@ genrule( cc_library( name = "include", hdrs = [":gen-header"], - include_prefix = "demo-rs/src", - visibility = ["//visibility:public"], + include_prefix = "demo/src", +) + +cc_library( + name = "demo-sys", + srcs = ["src/demo.cc"], + copts = ["-std=c++14"], + deps = [ + ":demo-include", + ":include", + ], +) + +cc_library( + name = "demo-include", + hdrs = ["include/demo.h"], + deps = ["//:core"], ) diff --git a/demo-rs/Cargo.toml b/demo/Cargo.toml similarity index 100% rename from demo-rs/Cargo.toml rename to demo/Cargo.toml diff --git a/demo-rs/build.rs b/demo/build.rs similarity index 53% rename from demo-rs/build.rs rename to demo/build.rs index f32b8ef48..a3c31b395 100644 --- a/demo-rs/build.rs +++ b/demo/build.rs @@ -1,10 +1,10 @@ fn main() { cxx_build::bridge("src/main.rs") - .file("../demo-cxx/demo.cc") + .file("src/demo.cc") .flag_if_supported("-std=c++14") .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"); + println!("cargo:rerun-if-changed=src/demo.cc"); + println!("cargo:rerun-if-changed=include/demo.h"); } diff --git a/demo-cxx/demo.h b/demo/include/demo.h similarity index 100% rename from demo-cxx/demo.h rename to demo/include/demo.h diff --git a/demo-cxx/demo.cc b/demo/src/demo.cc similarity index 88% rename from demo-cxx/demo.cc rename to demo/src/demo.cc index 21bdad43b..79c693f33 100644 --- a/demo-cxx/demo.cc +++ b/demo/src/demo.cc @@ -1,5 +1,5 @@ -#include "demo-cxx/demo.h" -#include "demo-rs/src/main.rs.h" +#include "demo/include/demo.h" +#include "demo/src/main.rs.h" #include namespace org { diff --git a/demo-rs/src/main.rs b/demo/src/main.rs similarity index 94% rename from demo-rs/src/main.rs rename to demo/src/main.rs index 66dfc7997..ee7e09347 100644 --- a/demo-rs/src/main.rs +++ b/demo/src/main.rs @@ -7,7 +7,7 @@ mod ffi { } extern "C" { - include!("demo-cxx/demo.h"); + include!("demo/include/demo.h"); type ThingC; fn make_demo(appname: &str) -> UniquePtr; diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs index 2560aeec5..768de1538 100644 --- a/gen/build/src/lib.rs +++ b/gen/build/src/lib.rs @@ -15,18 +15,18 @@ //! //! fn main() { //! cxx_build::bridge("src/main.rs") -//! .file("../demo-cxx/demo.cc") +//! .file("src/demo.cc") //! .flag_if_supported("-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"); +//! println!("cargo:rerun-if-changed=src/demo.cc"); +//! println!("cargo:rerun-if-changed=include/demo.h"); //! } //! ``` //! -//! A runnable working setup with this build script is shown in the -//! *demo-rs* and *demo-cxx* directories of [https://github.com/dtolnay/cxx]. +//! A runnable working setup with this build script is shown in the *demo* +//! directory of [https://github.com/dtolnay/cxx]. //! //! [https://github.com/dtolnay/cxx]: https://github.com/dtolnay/cxx //! @@ -83,7 +83,7 @@ pub fn bridge(rust_source_file: impl AsRef) -> Build { /// ```no_run /// let source_files = vec!["src/main.rs", "src/path/to/other.rs"]; /// cxx_build::bridges(source_files) -/// .file("../demo-cxx/demo.cc") +/// .file("src/demo.cc") /// .flag_if_supported("-std=c++11") /// .compile("cxxbridge-demo"); /// ``` diff --git a/src/lib.rs b/src/lib.rs index a7073388c..94a903745 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,10 +57,9 @@ //! //! # Example //! -//! A runnable version of this example is provided under the *demo-rs* directory -//! of [https://github.com/dtolnay/cxx] (with the C++ side of the implementation -//! in the *demo-cxx* directory). To try it out, jump into demo-rs and run -//! `cargo run`. +//! A runnable version of this example is provided under the *demo* directory of +//! [https://github.com/dtolnay/cxx]. To try it out, run `cargo run` from that +//! directory. //! //! ```no_run //! #[cxx::bridge] @@ -76,7 +75,7 @@ //! // One or more headers with the matching C++ declarations. Our code //! // generators don't read it but it gets #include'd and used in static //! // assertions to ensure our picture of the FFI boundary is accurate. -//! include!("demo-cxx/demo.h"); +//! include!("demo/include/demo.h"); //! //! // Zero or more opaque types which both languages can pass around but //! // only C++ can see the fields. @@ -113,10 +112,10 @@ //! //! Here are links to the complete set of source files involved in the demo: //! -//! - [demo-rs/src/main.rs](https://github.com/dtolnay/cxx/blob/master/demo-rs/src/main.rs) -//! - [demo-rs/build.rs](https://github.com/dtolnay/cxx/blob/master/demo-rs/build.rs) -//! - [demo-cxx/demo.h](https://github.com/dtolnay/cxx/blob/master/demo-cxx/demo.h) -//! - [demo-cxx/demo.cc](https://github.com/dtolnay/cxx/blob/master/demo-cxx/demo.cc) +//! - [demo/src/main.rs](https://github.com/dtolnay/cxx/blob/master/demo/src/main.rs) +//! - [demo/build.rs](https://github.com/dtolnay/cxx/blob/master/demo/build.rs) +//! - [demo/include/demo.h](https://github.com/dtolnay/cxx/blob/master/demo/include/demo.h) +//! - [demo/src/demo.cc](https://github.com/dtolnay/cxx/blob/master/demo/src/demo.cc) //! //! To look at the code generated in both languages for the example by the CXX //! code generators: @@ -124,10 +123,10 @@ //! ```console //! # run Rust code generator and print to stdout //! # (requires https://github.com/dtolnay/cargo-expand) -//! $ cargo expand --manifest-path demo-rs/Cargo.toml +//! $ cargo expand --manifest-path demo/Cargo.toml //! //! # run C++ code generator and print to stdout -//! $ cargo run --manifest-path gen/cmd/Cargo.toml -- demo-rs/src/main.rs +//! $ cargo run --manifest-path gen/cmd/Cargo.toml -- demo/src/main.rs //! ``` //! //!
@@ -237,13 +236,13 @@ //! //! fn main() { //! cxx_build::bridge("src/main.rs") // returns a cc::Build -//! .file("../demo-cxx/demo.cc") +//! .file("src/demo.cc") //! .flag_if_supported("-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"); +//! println!("cargo:rerun-if-changed=src/demo.cc"); +//! println!("cargo:rerun-if-changed=include/demo.h"); //! } //! ``` //!