• Home
  • Raw
  • Download

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 &mdash; 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"
390 # #[cxx::bridge]
399 # include!("cxx-demo/include/blobstore.h");
430 cxx-demo$ cargo run
431 Compiling cxx-demo v0.1.0
433 Running `target/debug/cxx-demo`
440 For the curious, it's easy to look behind the scenes at what CXX has done to
442 usage of CXX, but for the purpose of this tutorial it can be educative.
444 CXX comprises *two* code generators: a Rust one (which is the cxx::bridge
456 cxx-demo$ cargo install cargo-expand
457 cxx-demo$ cargo expand ::ffi
469 cxx-demo$ exa -T target/cxxbridge/
471 ├── cxx-demo
473 │ ├── main.rs.cc -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/sources/cxx-de…
474 │ └── main.rs.h -> ../../../debug/build/cxx-demo-11c6f678ce5c3437/out/cxxbridge/include/cxx-dem…
476 └── cxx.h -> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cxx-1.0.0/include/cxx.h
479 In those files you'll see declarations or templates of any CXX Rust types
483 If it fits your workflow better, the CXX C++ code generator is also available as
487 cxx-demo$ cargo install cxxbridge-cmd
488 cxx-demo$ cxxbridge src/main.rs
507 #[cxx::bridge]
523 # include!("cxx-demo/include/blobstore.h");
566 ##include "rust/cxx.h"
590 ##include "cxx-demo/include/blobstore.h"
591 ##include "cxx-demo/src/main.rs.h"
654 cxx-demo$ cargo run
655 Running `target/debug/cxx-demo`
663 <https://github.com/dtolnay/cxx>. You can run it directly without stepping
670 The key contribution of CXX is it gives you Rust&ndash;C++ interop in which
682 CXX plays to the strengths of the Rust type system *and* C++ type system *and*