You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case in which I would like to invoke rust-bindgen multiple times. Once with generate_comments(false) and once with generate_comments(true) -- the use case here is that the C header file has comments annotating the run-time version required for a particular struct field to have been added. This is for a sqlite extension that we want to build against a new version of sqlite headers (e.g. sqlite3ext.h but then have runtime detection of version in order to make it safe to load the loadable extension into an older version of sqlite.
I have this working (using some syn parsing of the AST that rust-bindgen generates to process the fields and their comments). However, I would very much like to be able to write code like this:
let mut bindings = bindgen::builder()
.trust_clang_mangling(false) |
.header(header.clone()) |
.parse_callbacks(Box::new(SqliteTypeChooser)) |
.rustfmt_bindings(true);
// lots of conditional code that updates `bindings` with different clang args, etc in different situtaions
let bindings_with_comments = bindings.clone().generate_comments(true);
// actual invocations of `bindings.generate()` and `bindings_with_comments.generate()`
As a result of not being able to .clone(), I find that I am having to write something like this:
let mut bindings = bindgen::builder()
.trust_clang_mangling(false) |
.header(header.clone()) |
.parse_callbacks(Box::new(SqliteTypeChooser)) |
.rustfmt_bindings(true);
let mut bindings_with_comments = bindgen::builder()
.trust_clang_mangling(false) |
.header(header.clone()) |
.parse_callbacks(Box::new(SqliteTypeChooser)) |
.rustfmt_bindings(true);
// lots of conditional code that follows every update to `bindings` with an identical update to `bindings_with_comments`
// actual invocations of `bindings.generate()` and `bindings_with_comments.generate()`
I've explored a bit if there are alternatives to this but struggle to find anything that doesn't involve essentially duplicating hundreds of lines of code.
It feels like the right solution is to implement Clone on bindgen Builder -- is there a good reason not to do this, or is it simply that no one has presented a use-case for it to date?
The text was updated successfully, but these errors were encountered:
I have a use case in which I would like to invoke rust-bindgen multiple times. Once with
generate_comments(false)
and once withgenerate_comments(true)
-- the use case here is that the C header file has comments annotating the run-time version required for a particular struct field to have been added. This is for a sqlite extension that we want to build against a new version of sqlite headers (e.g.sqlite3ext.h
but then have runtime detection of version in order to make it safe to load the loadable extension into an older version of sqlite.I have this working (using some
syn
parsing of the AST that rust-bindgen generates to process the fields and their comments). However, I would very much like to be able to write code like this:However, I find that the bindgen
Builder
does not implementClone
(it appears that it used to as of 0.19.1 but has not for some trime: https://docs.rs/bindgen/0.19.1/src/bindgen/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.19.1/src/lib.rs.html#42).As a result of not being able to
.clone()
, I find that I am having to write something like this:I've explored a bit if there are alternatives to this but struggle to find anything that doesn't involve essentially duplicating hundreds of lines of code.
It feels like the right solution is to implement
Clone
on bindgenBuilder
-- is there a good reason not to do this, or is it simply that no one has presented a use-case for it to date?The text was updated successfully, but these errors were encountered: