Skip to content

Commit

Permalink
rustfmt cleanup (#2553)
Browse files Browse the repository at this point in the history
Closes #2540

* test-one: use prettyplease to format generated code

* contributing: note the prettyplease change, state that it is an optional dependency of bindgen, not bindgen-cli
  • Loading branch information
tshepang committed Jun 14, 2023
1 parent df439e9 commit 9042f42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 10 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ There are also some integration tests in the `./bindgen-integration` crate, whic
generate bindings to some C++ code, and then uses the bindings, asserting that
values are what we expect them to be, both on the Rust and C++ side.

The generated and expected bindings are run through `rustfmt` before they are
compared. Make sure you have `rustfmt` up to date:

```
$ rustup update nightly
$ rustup component add rustfmt --toolchain nightly
```
The generated and expected bindings are formatted with [prettyplease] before they are
compared. It is a default (but optional) dependency of `bindgen`,
so be sure to keep that in mind
(if you built `bindgen` with the `--no-default-features` option of Cargo).
Note also that `rustfmt` formatting is disabled for the `bindgen-tests/tests/expectations/`
directory tree, which helps avoid failing ui tests.

Note: running `cargo test` from the root directory of `bindgen`'s repository does not
automatically test the generated bindings or run the integration tests.
These steps must be performed manually when needed.


### Testing Bindings Generation

To regenerate bindings from the corpus of test headers in `bindgen-tests/tests/headers` and
Expand Down Expand Up @@ -576,3 +576,6 @@ $ git push --tags upstream # To publish the tag
### Create a new release on Github

See [Releasing projects on Github](https://docs.github.com/en/repositories/releasing-projects-on-github)


[prettyplease]: https://github.com/dtolnay/prettyplease
7 changes: 2 additions & 5 deletions bindgen-tests/tests/test-one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,18 @@ TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX)
FLAGS="$(grep "// bindgen-flags: " "$TEST" || echo)"
FLAGS="${FLAGS/\/\/ bindgen\-flags:/}"
# Prepend the default flags added in test.rs's `create_bindgen_builder`.
FLAGS="--rustfmt-bindings --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS"
FLAGS="--with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS"


eval ../target/debug/bindgen \
"\"$TEST\"" \
--emit-ir \
--emit-ir-graphviz ir.dot \
--emit-clang-ast \
--formatter prettyplease \
-o "\"$BINDINGS\"" \
$FLAGS

rustup run nightly rustfmt "$BINDINGS" || true

dot -Tpng ir.dot -o ir.png

echo
Expand All @@ -80,8 +79,6 @@ EXPECTED=${TEST/headers/expectations\/tests}
EXPECTED=${EXPECTED/.hpp/.rs}
EXPECTED=${EXPECTED/.h/.rs}

rustup run nightly rustfmt "$EXPECTED" || true

# Don't exit early if there is a diff.
diff -U8 "$EXPECTED" "$BINDINGS" || true

Expand Down

0 comments on commit 9042f42

Please sign in to comment.