-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a section for calling C++ from Rust in the tutorial
- Loading branch information
Showing
12 changed files
with
499 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "example-tutorial_cpp" | ||
version = "0.4.0" | ||
edition.workspace = true | ||
license.workspace = true | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
||
[build-dependencies] | ||
cc = "1.0" | ||
build-rs = "0.1.2" | ||
zngur = { path = "../../zngur" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Example: Tutorial Cpp | ||
|
||
Full code of the [Tutorial](https://hkalbasi.github.io/zngur/tutorial.html) part 2 (Calling C++ from Rust) in the Zngur book. | ||
|
||
To run this example: | ||
|
||
``` | ||
cargo run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{env, path::PathBuf}; | ||
|
||
use zngur::Zngur; | ||
|
||
fn main() { | ||
build::rerun_if_changed("main.zng"); | ||
build::rerun_if_changed("impls.cpp"); | ||
build::rerun_if_env_changed("CXX"); | ||
|
||
let cxx = env::var("CXX").unwrap_or("c++".to_owned()); | ||
|
||
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
|
||
Zngur::from_zng_file(crate_dir.join("main.zng")) | ||
.with_cpp_file(out_dir.join("generated.cpp")) | ||
.with_h_file(out_dir.join("generated.h")) | ||
.with_rs_file(out_dir.join("generated.rs")) | ||
.generate(); | ||
|
||
let my_build = &mut cc::Build::new(); | ||
let my_build = my_build | ||
.cpp(true) | ||
.compiler(&cxx) | ||
.include(&crate_dir) | ||
.include(&out_dir); | ||
let my_build = || my_build.clone(); | ||
|
||
my_build() | ||
.file(out_dir.join("generated.cpp")) | ||
.compile("zngur_generated"); | ||
my_build().file("impls.cpp").compile("impls"); | ||
} |
Oops, something went wrong.