Skip to content

[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

Closed
wants to merge 38 commits into from
Closed

[WIP] Trying to solve issue # 548 #596

wants to merge 38 commits into from

Conversation

basic-bgnr
Copy link
Contributor

@basic-bgnr basic-bgnr commented Mar 20, 2017

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.

@emilio
Copy link
Contributor

emilio commented Mar 20, 2017

r? @fitzgen

Copy link
Member

@fitzgen fitzgen left a 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.
Copy link
Member

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());
Copy link
Member

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());
Copy link
Member

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());
}

Copy link
Member

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());
Copy link
Member

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>,
Copy link
Member

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.

@basic-bgnr
Copy link
Contributor Author

Thank you for the input.
I'll try to answer the listed issue one by one.

  1. Regarding the doc comment, /// Configure and generate Rust bindings for a C/C++ header.: While building with cargo, I found that, comment for each function are required, so i simply copied the comment from previous function to quickly get to build, later i forgot to remove the top line, :-). Sorry for that. I will replace that with /// Generate command line flag for builder.
  2. Regarding the type signature of fn generate_command_line_flag : When you assigned me the issue you described the function as Builder::command_line_flags(), so I thought you wanted a static function. I should have asked you earlier. The mut in builder_ref was me trying to outrun the rust compiler. Thank for pointing that out.
  3. Making the field of RegexSet public: This was a bad idea from beginning, I'll implement a getter function.
  4. prefix --: Will get to it immediately. how did I missed it :-(

Are there any other things to look for in my code?
Thanks you.

@fitzgen
Copy link
Member

fitzgen commented Mar 20, 2017

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 :)

Copy link
Member

@fitzgen fitzgen left a 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<()>>();
Copy link
Member

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)) );
Copy link
Member

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
Copy link
Member

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");
Copy link
Member

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()
Copy link
Member

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'
Copy link
Member

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.

Copy link
Member

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.

@fitzgen
Copy link
Member

fitzgen commented Apr 10, 2017

Thanks again for taking this all the way home! :)

@fitzgen
Copy link
Member

fitzgen commented Apr 10, 2017

One last thing: please squash all the commits into a single commit. Thanks!

SimonSapin and others added 19 commits April 11, 2017 08:28
```
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.
fitzgen and others added 16 commits April 11, 2017 08:28
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.
@basic-bgnr
Copy link
Contributor Author

@fitzgen I can't figure what additional changes are required, could you point me to the right direction.

@fitzgen
Copy link
Member

fitzgen commented Apr 11, 2017

@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!

@basic-bgnr
Copy link
Contributor Author

@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 ?

@fitzgen
Copy link
Member

fitzgen commented Apr 12, 2017

@basic-bgnr opening a new PR works, or you can just force push to this PR's branch.

@fitzgen
Copy link
Member

fitzgen commented Apr 13, 2017

Closing in favor of #630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants