-
Notifications
You must be signed in to change notification settings - Fork 747
[WIP] Trying to solve issue # 548 #596
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
Conversation
r? @fitzgen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is a good start, but there seem to be a couple misunderstandings. See comments below.
src/lib.rs
Outdated
@@ -168,6 +168,198 @@ pub fn builder() -> Builder { | |||
} | |||
|
|||
impl Builder { | |||
/// Configure and generate Rust bindings for a C/C++ header. | |||
/// | |||
/// This is the main entry point to the library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not supposed to be the main entry point to the library. This is just a utility for debugging what was originally build.rs
usage with command line flags instead.
For example, Stylo uses the Builder
API in build.rs
, but it is easiest to run creduce
with the command line API. So when I am debugging a Stylo + bindgen bug, the first thing I do is try and convert the Builder
API usage into equivalent command line flags and arguments so I can use creduce
on it.
Nothing here should be mutating a Builder
, and it doesn't seem like the builder_ref
is mutated so it shouldn't be necessary to take an &mut
reference.
Here is the type signature skeleton I would expect:
impl Builder {
/// For debugging purposes, dump the set of command line flags that is
/// equivalent to this builder invocation.
pub fn dump_command_line_flags(&self) -> Vec<String> {
// ...
}
}
src/lib.rs
Outdated
let mut output_vector:Vec<String> = Vec::new(); | ||
|
||
if let Some(ref header) = builder_ref.options.input_header{ | ||
output_vector.push("header".into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input header is a positional argument, and does not have a --header
flag.
src/lib.rs
Outdated
|
||
if builder_ref.options.bitfield_enums.items.len() > 0 { | ||
output_vector.push("bitfield-enum".into()); | ||
output_vector.extend(builder_ref.options.bitfield_enums.items.iter().cloned()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --bitfield-enum
flag should be in front of every bitfield enum:
for bitfield_enum in self.options.bitfield_nums.items() {
output_vector.push("--bitfield-enum".into());
output_vector.push(bitfield_enum.clone());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This same fix needs to happen for basically all the flags below.
src/lib.rs
Outdated
|
||
|
||
if builder_ref.options.bitfield_enums.items.len() > 0 { | ||
output_vector.push("bitfield-enum".into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to add the "--" prefix to the flags.
src/regex_set.rs
Outdated
items: Vec<String>, | ||
set: Option<RxSet>, | ||
pub items: Vec<String>, | ||
pub set: Option<RxSet>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By making these pub
, we allow mutation, which we don't want. Instead, let's add getters that return immutable references: &[String]
and Option<&RxSet>
respectively.
Thank you for the input.
Are there any other things to look for in my code? |
Ah, sorry for misleading you into thinking of a static method! My bad. Nothing else, looking forward to seeing the next iteration of the code :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @basic-bgnr! This is really close :)
I have just a couple nitpicks below, and once fixed up, I think this will be ready to land.
src/lib.rs
Outdated
output_vector.push("--bitfield-enum".into()); | ||
output_vector.push(item.clone()); | ||
}) | ||
.collect::<Vec<()>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than collecting as a Vec
to perform map
's side effects, the Iterator::count
method is more idiomatic for forcing side effects. Even better in this case would be a plain for
loop:
for item in self.options.bitfield_enums.get_items() {
output_vector.push("--bitfield-enum".into());
output_vector.push(item.clone());
}
.map(|&x| x.into()) | ||
.collect::<Vec<String>>(); | ||
|
||
assert!(test_cases.iter().all(|ref x| command_line_flags.contains(x)) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add another test that exercises a non-default builder. Something with some whitelisting and opaque-ing perhaps?
src/lib.rs
Outdated
// output_vector.push("verbose"); | ||
|
||
|
||
output_vector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one newline for vertical spacing, not multiple new lines.
src/lib.rs
Outdated
|
||
|
||
|
||
// output_vector.push("verbose"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left over from debugging? Please remove commented out code.
src/regex_set.rs
Outdated
|
||
/// returns reference to field 'items' | ||
pub fn get_items(&self) -> &Vec<String> { | ||
self.items.as_ref() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a slice:
pub fn get_items(&self) -> &[String] {
&self.items
}
src/regex_set.rs
Outdated
@@ -27,7 +27,14 @@ impl RegexSet { | |||
self.insert(s) | |||
} | |||
} | |||
|
|||
/// returns reference to field 'items' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please capitalize and punctuate comments:
/// Returns a slice of this `RegexSet`'s items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just here, but elsewhere too.
Thanks again for taking this all the way home! :) |
One last thing: please squash all the commits into a single commit. Thanks! |
``` warning: found non-foreign-function-safe member in struct marked #[repr(C)]: found zero-size struct in foreign module, consider adding a member to this struct ```
…as a string to a Builder Currently the Builder API requires input as header files on disk. This allows passing C source directly to clang using the existing UnsavedFile struct.
Signed-off-by: Emilio Cobos Álvarez <[email protected]>
This should fix #584.
Return `None` whenever we can't find a template definition, not only when the template is a builtin.
But only if the type is not a builtin type. If it is a builtin type, then it's expected that we won't have a definition.
This is exercised in other tests, but in a round about fashion. It is nice to have a test that explicitly exercises default type parameters, without any cruft.
This enables one to locally do $ cargo doc and get library level documentation. Without the changes, cargo doesn't know whether to build docs for the binary or library, and so instead it gives an error and stops.
This replaces various `unwrap` calls with `expect` calls that have better diagnostic messages if/when they fail.
This commit ensures that all of the cargo features we have that only exist for CI/testing purposes, and aren't for external consumption, have a "testing_only_" prefix.
This commit defines a new set of assertion macros that are only checked in testing/CI when the `testing_only_extra_assertions` feature is enabled. This makes it so that *users* of bindgen that happen to be making a debug build don't enable all these extra and expensive assertions. Additionally, this removes the `testing_only_assert_no_dangling_items` feature, and runs the assertions that were previously gated on that feature when the new `testing_only_extra_assertions` feature is enabled.
…ommandline flag. add 2 test conditions
@fitzgen I can't figure what additional changes are required, could you point me to the right direction. |
@basic-bgnr great! As I mentioned in the last review, please rebase and squash into a single commit rather than merge with upstream master. Here is a basic tutorial, if you're unfamiliar: https://davidwalsh.name/squash-commits-git Thanks! |
@fitzgen I had to start fresh on the pull request. The git history was too convoluted to deal with so i deleted my repo and forked it again. I would like to PR from my new fork, is it possible ? |
@basic-bgnr opening a new PR works, or you can just force push to this PR's branch. |
Closing in favor of #630 |
I've updated the code to dump commandline flag from builder. Extremely simple test is also included in this commit. I haven't tested the code fully for total compliance but I am looking for feedback on further improvement.