Lines Matching full:cxx
2 # Tutorial: CXX blobstore client
11 <https://github.com/dtolnay/cxx>. To try it out directly, run `cargo run` from
20 projects. (CXX works with other build systems too; refer to chapter 5.)
22 Create a blank Cargo project: `mkdir cxx-demo`; `cd cxx-demo`; `cargo init`.
24 Edit the Cargo.toml to add a dependency on the `cxx` crate:
29 # name = "cxx-demo"
34 cxx = "1.0"
41 CXX relies on a description of the function signatures that will be exposed from
43 in a Rust module annotated with the `#[cxx::bridge]` attribute macro.
51 #[cxx::bridge]
67 We'll treat `BlobstoreClient` as an *opaque type* in CXX's classification so
83 #[cxx::bridge]
86 include!("cxx-demo/include/blobstore.h");
102 unreasonable. CXX performs static assertions that the signatures exactly match
120 …= /bin/ld: target/debug/deps/cxx-demo-7cb7fddf3d67d880.rcgu.o: in function `cxx_demo::ffi::new_blo…
127 In CXX's integration with Cargo, all #include paths begin with a crate name by
130 `include!("cxx-demo/include/blobstore.h")` above — we'll be putting the
132 crate is named something other than `cxx-demo` according to the `name` field in
133 Cargo.toml, you will need to use that name everywhere in place of `cxx-demo`
153 #include "cxx-demo/include/blobstore.h"
169 Be aware that *CXX does not look at any of these files.* You're free to put
177 We need to introduce a new build-time dependency on CXX's C++ code generator in
183 # name = "cxx-demo"
188 cxx = "1.0"
191 cxx-build = "1.0"
194 Then add a build.rs build script adjacent to Cargo.toml to run the cxx-build
196 source file containing the cxx::bridge language boundary definition, and the
206 .compile("cxx-demo");
212 ***[Cargo-based builds](build/cargo.md)*** for more details about CXX's Cargo
222 .compile("cxx-demo");
232 cxx-demo$ cargo run
233 Compiling cxx-demo v0.1.0
235 Running `target/debug/cxx-demo`
237 cxx-demo$
257 #[cxx::bridge]
266 include!("cxx-demo/include/blobstore.h");
293 # #[cxx::bridge]
302 # include!("cxx-demo/include/blobstore.h");
349 C++ by a header `main.rs.h` generated by the CXX code generator. In CXX's Cargo
356 ##include "cxx-demo/include/blobstore.h"
357 ##include "cxx-demo/src/main.rs.h"
389 # #[cxx::bridge]
398 # include!("cxx-demo/include/blobstore.h");
429 cxx-demo$ cargo run
430 Compiling cxx-demo v0.1.0
432 Running `target/debug/cxx-demo`
439 For the curious, it's easy to look behind the scenes at what CXX has done to
441 usage of CXX, but for the purpose of this tutorial it can be educative.
443 CXX comprises *two* code generators: a Rust one (which is the cxx::bridge
455 cxx-demo$ cargo install cargo-expand
456 cxx-demo$ cargo expand ::ffi
468 cxx-demo$ exa -T target/cxxbridge/
470 ├── cxx-demo
472 │ ├── main.rs.cc -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/sources/cxx-de…
473 │ └── main.rs.h -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/include/cxx-dem…
475 └── cxx.h -> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cxx-1.0.0/include/cxx.h
478 In those files you'll see declarations or templates of any CXX Rust types
482 If it fits your workflow better, the CXX C++ code generator is also available as
486 cxx-demo$ cargo install cxxbridge-cmd
487 cxx-demo$ cxxbridge src/main.rs
506 #[cxx::bridge]
522 # include!("cxx-demo/include/blobstore.h");
565 # #include "rust/cxx.h"
589 ##include "cxx-demo/include/blobstore.h"
590 ##include "cxx-demo/src/main.rs.h"
653 cxx-demo$ cargo run
654 Running `target/debug/cxx-demo`
662 <https://github.com/dtolnay/cxx>. You can run it directly without stepping
669 The key contribution of CXX is it gives you Rust–C++ interop in which
681 CXX plays to the strengths of the Rust type system *and* C++ type system *and*