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");
216 ***[Cargo-based builds](build/cargo.md)*** for more details about CXX's Cargo
226 .compile("cxx-demo");
236 cxx-demo$ cargo run
237 Compiling cxx-demo v0.1.0
239 Running `target/debug/cxx-demo`
241 cxx-demo$
261 #[cxx::bridge]
270 include!("cxx-demo/include/blobstore.h");
297 # #[cxx::bridge]
306 # include!("cxx-demo/include/blobstore.h");
353 C++ by a header `main.rs.h` generated by the CXX code generator. In CXX's Cargo
360 #include "cxx-demo/include/blobstore.h"
361 #include "cxx-demo/src/main.rs.h"
394 # #[cxx::bridge]
403 # include!("cxx-demo/include/blobstore.h");
434 cxx-demo$ cargo run
435 Compiling cxx-demo v0.1.0
437 Running `target/debug/cxx-demo`
444 For the curious, it's easy to look behind the scenes at what CXX has done to
446 usage of CXX, but for the purpose of this tutorial it can be educative.
448 CXX comprises *two* code generators: a Rust one (which is the cxx::bridge
460 cxx-demo$ cargo install cargo-expand
461 cxx-demo$ cargo expand ::ffi
473 cxx-demo$ exa -T target/cxxbridge/
475 ├── cxx-demo
477 │ ├── main.rs.cc -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/sources/cxx-de…
478 │ └── main.rs.h -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/include/cxx-dem…
480 └── cxx.h -> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cxx-1.0.0/include/cxx.h
483 In those files you'll see declarations or templates of any CXX Rust types
487 If it fits your workflow better, the CXX C++ code generator is also available as
491 cxx-demo$ cargo install cxxbridge-cmd
492 cxx-demo$ cxxbridge src/main.rs
511 #[cxx::bridge]
527 # include!("cxx-demo/include/blobstore.h");
570 #include "rust/cxx.h"
594 #include "cxx-demo/include/blobstore.h"
595 #include "cxx-demo/src/main.rs.h"
658 cxx-demo$ cargo run
659 Running `target/debug/cxx-demo`
667 <https://github.com/dtolnay/cxx>. You can run it directly without stepping
674 The key contribution of CXX is it gives you Rust–C++ interop in which
686 CXX plays to the strengths of the Rust type system *and* C++ type system *and*