From 474e3ea8afd170ae86cc5c3a547caee65f97ecb8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 27 Feb 2023 13:45:55 -0800 Subject: [PATCH] docs: update the Rust bindgen docs to talk about assertions Since we now guarantee that Rust and C/C++ will have assertions both on or both off, we can give guidance about using `cfg(debug_assertions)` to wrap code using `#ifdef NDEBUG`. --- docs/markdown/Rust-module.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/markdown/Rust-module.md b/docs/markdown/Rust-module.md index 43dbb07d7..7617dbb61 100644 --- a/docs/markdown/Rust-module.md +++ b/docs/markdown/Rust-module.md @@ -41,6 +41,7 @@ libraries. This has two advantages over hand-rolling ones own with a - It handles `include_directories`, so one doesn't have to manually convert them to `-I...` - It automatically sets up a depfile, making the results more reliable +- It automatically handles assertions, synchronizing Rust and C/C++ to have the same behavior It takes the following keyword arguments @@ -81,3 +82,11 @@ r1 = rust.bindgen( output : 'out.rs', ) ``` + + +*Since 1.1.0* Meson will synchronize assertions for Rust and C/C++ when the +`b_ndebug` option is set (via `-DNDEBUG` for C/C++, and `-C +debug-assertions=on` for Rust), and will pass `-DNDEBUG` as an extra argument +to clang. This allows for reliable wrapping of `-DNDEBUG` controlled behavior +with `#[cfg(debug_asserions)]` and or `cfg!()`. Before 1.1.0, assertions for Rust +were never turned on by Meson.