• Home
  • Raw
  • Download

Lines Matching +full:rust +full:- +full:src

1 {{#title Cargo-based setup — Rust ♡ C++}}
2 # Cargo-based builds
4 As one aspect of delivering a good Rust–C++ interop experience, CXX turns
7 experience `#include`-ing C++ headers across dependencies.
11 CXX's integration with Cargo is handled through the [cxx-build] crate.
13 [cxx-build]: https://docs.rs/cxx-build
25 [build-dependencies]
26 cxx-build = "1.0"
35 ```rust,noplayground
39 cxx_build::bridge("src/main.rs") // returns a cc::Build
40 .file("src/demo.cc")
41 .flag_if_supported("-std=c++11")
42 .compile("cxxbridge-demo");
44 println!("cargo:rerun-if-changed=src/main.rs");
45 println!("cargo:rerun-if-changed=src/demo.cc");
46 println!("cargo:rerun-if-changed=include/demo.h");
50 The `rerun-if-changed` lines are optional but make it so that Cargo does not
51 spend time recompiling your C++ code when only non-C++ code has changed since
52 the previous Cargo build. By default without any `rerun-if-changed`, Cargo will
53 re-execute the build script after *any* file changed in the project.
56 GitHub repo, which maintains a working Cargo-based setup for the blobstore
61 With cxx-build, by default your include paths always start with the crate name.
63 `extern "C++"` section of your Rust cxx::bridge.
77 [CFG]: https://docs.rs/cxx-build/*/cxx_build/static.CFG.html
79 ```rust,noplayground
106 If your `#[cxx::bridge]` module contains an `extern "Rust"` block i.e. types or
107 functions exposed from Rust to C++, or any shared data structures, the
108 CXX-generated C++ header declaring those things is available using a `.rs.h`
109 extension on the Rust source file's name.
117 were including the Rust file directly. Use whichever you find more palatable.
126 contained as `.h` files in their Cargo package, as well as CXX-generated ones.
136 Note that cross-crate imports are only made available between **direct
145 [links]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
152 that needs to support downstream crates `#include`-ing its C++ public headers.
181 ```rust,noplayground
192 cxx_build::bridge("src/bridge.rs").compile("demo");
204 ```rust,noplayground
222 cxx_build::bridge("src/bridge.rs").compile("demo");
255 - "crate0"
256 - "group/api/crate1"
257 - "group/api/crate2"
258 - "group/api/contrib/crate3"
259 - "detail/crate4"
261 Your header involves types from the first four so we re-export those as part of
265 ```rust,noplayground
273 cxx_build::bridge("src/bridge.rs")
274 .file("src/impl.cc")
286 re-exporting a C++ dependency as part of your crate's public API, except with
296 ```rust,noplayground
304 cxx_build::bridge("src/bridge.rs").compile("demo");