Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move expand infinite recursion fix #799

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/bindgen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ impl Builder {
}

pub fn generate(self) -> Result<Bindings, Error> {
// If macro expansion is enabled, then cbindgen will attempt to build the crate
// and will run its build script which may run cbindgen again. That second run may start
// infinite recursion, or overwrite previously written files with bindings.
// So if we are called recursively, we are skipping the whole generation
// and produce "noop" bindings that won't be able to overwrite anything.
if std::env::var("_CBINDGEN_IS_RUNNING").is_ok() {
return Ok(Bindings::new(
self.config,
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
true,
));
}

let mut result = Parse::new();

if self.std_types {
Expand Down
18 changes: 0 additions & 18 deletions src/bindgen/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,6 @@ impl Library {
}

pub fn generate(mut self) -> Result<Bindings, Error> {
// If macro expansion is enabled, then cbindgen will attempt to build the crate
// and will run its build script which may run cbindgen again. That second run may start
// infinite recursion, or overwrite previously written files with bindings.
// So if we are called recursively, we are skipping the whole generation
// and produce "noop" bindings that won't be able to overwrite anything.
if std::env::var("_CBINDGEN_IS_RUNNING").is_ok() {
return Ok(Bindings::new(
self.config,
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
true,
));
}

self.transfer_annotations();
self.simplify_standard_types();

Expand Down