From efd16e6fedba2d3145ff7693e2c07414d0738731 Mon Sep 17 00:00:00 2001 From: Heesoo Yang Date: Fri, 11 Oct 2024 13:16:41 -0700 Subject: [PATCH] Add `unstable_ir` feature flag that makes the ir pub Rename to unstable_ir, add docs Push omitted file --- Cargo.toml | 1 + docs.md | 9 +++++++++ src/bindgen/mod.rs | 3 +++ src/lib.rs | 3 +++ 4 files changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3fafaa64d..01a484529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ pretty_assertions = "1.4.0" [features] default = ["clap"] +unstable_ir = [] [[bin]] name = "cbindgen" diff --git a/docs.md b/docs.md index c8ce9f4f2..3d00d814d 100644 --- a/docs.md +++ b/docs.md @@ -94,9 +94,18 @@ cbindgen = "0.24.0" If you'd like to use a `build.rs` script with a `cbindgen.toml`, consider using [`cbindgen::generate()`](https://docs.rs/cbindgen/*/cbindgen/fn.generate.html) instead. +## Internal Representation +Some users may find it useful to access the **unstable** internal representation (IR) that cbindgen uses to parse and generate code. By default, the IR is private, but you can access it by enabling the `"unstable_ir"` feature flag like so: +``` +[build-dependencies] +cbindgen = { version = "0.27.0", features = ["unstable_ir"] } +``` + +This opens up the `cbindgen::bindgen::ir` module. +Please remember that the IR is **not stable**, so if you use this feature, you will need to pin cbindgen to avoid breakages. # Writing Your C API diff --git a/src/bindgen/mod.rs b/src/bindgen/mod.rs index 5d7882118..8cde9116c 100644 --- a/src/bindgen/mod.rs +++ b/src/bindgen/mod.rs @@ -45,6 +45,9 @@ mod config; mod declarationtyperesolver; mod dependencies; mod error; +#[cfg(feature = "unstable_ir")] +pub mod ir; +#[cfg(not(feature = "unstable_ir"))] mod ir; mod language_backend; mod library; diff --git a/src/lib.rs b/src/lib.rs index f98f4fc05..f7f0d32a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,9 @@ extern crate quote; extern crate syn; extern crate toml; +#[cfg(feature = "unstable_ir")] +pub mod bindgen; +#[cfg(not(feature = "unstable_ir"))] mod bindgen; pub use crate::bindgen::*;