mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Update demo documentation
This commit is contained in:
parent
37531b477e
commit
278f6fc8cd
25
README.md
25
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
|
||||
```
|
||||
|
||||
<br>
|
||||
@ -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");
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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<Path>) -> 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");
|
||||
/// ```
|
||||
|
27
src/lib.rs
27
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
|
||||
//! ```
|
||||
//!
|
||||
//! <br>
|
||||
@ -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");
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
Loading…
Reference in New Issue
Block a user