Repository: rust-lang/rust-bindgen
Pull request #2634 (2023-09-11 17:05:36)

make some improvements to contribution guide


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa5af685..9b536800 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -179,6 +179,8 @@
 
 ## Added
 ## Changed
+- The `--wrap-static-fns` feature was updated so function types that has no
+  argument use `void` as its sole argument.
 ## Removed
 ## Fixed
 ## Security
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e6439e12..25cad1e9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -35,9 +35,9 @@ and introduce yourself.
   - [Writing a Predicate Script](#writing-a-predicate-script)
 - [Cutting a new bindgen release](#cutting-a-new-bindgen-release)
   - [Updating the changelog](#updating-the-changelog)
-  - [Bumping the version numbers.](#bumping-the-version-numbers)
   - [Merge to `main`](#merge-to-main)
-  - [Publish and add a git tag for the right commit](#publish-and-add-a-git-tag-for-the-right-commit)
+  - [Tag and publish](#tag-and-publish)
+  - [Create a new release on GitHub](create-a-new-relese-on-github)
 
 <!-- END doctoc generated TOC please keep comment here to allow auto update -->
 
@@ -56,7 +56,7 @@ issue, provide us with:
 * The `bindgen` flags used to reproduce the issue with the header file
 * The expected `bindgen` output
 * The actual `bindgen` output
-* The [debugging logs](#logs) generated when running `bindgen` on this testcase
+* The [debugging logs](#debug-logging) generated when running `bindgen` on this testcase
 
 ## Looking to Start Contributing to `bindgen`?
 
@@ -69,7 +69,8 @@ issue, provide us with:
 
 ### `rustfmt` / `cargo fmt`
 
-We use `nightly` channel for `rustfmt` so please set the appropriate setting your editor/IDE for that.
+We use `nightly` channel for `rustfmt`,
+so please set the appropriate setting in your editor/IDE for that.
 
 For rust-analyzer, you can set `rustfmt.extraArgs = ['+nightly']`.
 
@@ -212,8 +213,8 @@ add each of:
 
 If you need to update the test expectations for a test file that generates
 different bindings for different `libclang` versions, you *don't* need to have
-many version of `libclang` installed locally. Just make a work-in-progress pull
-request, and then when Travis CI fails, it will log a diff of the
+many versions of `libclang` installed locally. Just make a work-in-progress pull
+request, and then when CI fails, it will log a diff of the
 expectations. Use the diff to patch the appropriate expectation file locally and
 then update your pull request.
 
@@ -355,7 +356,7 @@ changes should be squashed into the original commit.
 Unsure who to ask for review? Ask any of:
 
 * `@emilio`
-* `@fitzgen`
+* `@pvdrz`
 
 More resources:
 
@@ -552,42 +553,38 @@ $ npm install doctoc
 $ ./node_modules/doctoc/doctoc.js CHANGELOG.md
 ```
 
-### Bumping the version numbers
-
-Use `cargo release` (from `cargo install cargo-release`) to automate things:
-
-- For a feature release, `cargo release minor --execute` (will bump v0.62.1 to v0.63.0)
-- For a patch release, `cargo release patch --execute` (will bump v0.63.0 to v0.63.1)
-
-Run tests just to ensure everything is working as expected.
-
 ### Merge to `main`
 
 For regular releases, the changes above should end up in `main` before
 publishing. For dot-releases of an old version (e.g., cherry-picking an
 important fix) you can skip this.
 
-### Publish and add a git tag for the right commit
+### Tag and publish
 
-Once you're in the right commit, do:
+Once you're in the right branch, do:
 
 ```
 cargo release [patch|minor] --execute
-cargo release --execute
 ```
-This does the equivalent of the following:
+This does the following:
 
-```
-$ git tag -a v0.62.1 # With the right version of course
-$ pushd bindgen && cargo publish && popd
-$ pushd bindgen-cli && cargo publish && popd
-$ git push --tags upstream # To publish the tag
-```
+- Tag (`git tag`) the HEAD commit
+- Publish (`cargo publish`) bindgen and bindgen-cli
+- Push (`git push`) to GitHub
+
+The `patch` and `minor` refer to semver concepts:
+
+- `patch` would bump __v0.68.1__ to __v0.68.2__
+- `feature` would bump __v0.68.2__ to __v0.69.0__
 
 ### Create a new release on Github
 
-The release will be automated with the help of `.github/workflows/release.yml`,
-and will only be created when all tests succeed.
+The release is automated with the help of `.github/workflows/release.yml`,
+and will only be created...
+
+- when a Git tag is pushed
+- when all tests succeed
+
 While the tests are still running,
 a draft GitHub release will be created,
 to avoid notifying watchers of the repo should a CI step fail.
diff --git a/Cargo.toml b/Cargo.toml
index 0c581d66..370828da 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,6 +39,12 @@ tag-name = "v{{version}}"
 # Don't release any crate unless its manifest has `release = true`
 release = false
 
+# Add version and date to changelog file
+[[workspace.metadata.release.pre-release-replacements]]
+file = "CHANGELOG.md"
+search = "# Unreleased"
+replace = "# {{version}} ({{date}})"
+
 # The profile that 'cargo dist' will build with
 [profile.dist]
 inherits = "release"
diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs
index 58e0882f..02c46802 100644
--- a/bindgen/codegen/serialize.rs
+++ b/bindgen/codegen/serialize.rs
@@ -322,21 +322,26 @@ impl<'a> CSerialize<'a> for Type {
                 }
                 write!(writer, ")")?;
 
-                write!(writer, " (")?;
-                serialize_sep(
-                    ", ",
-                    signature.argument_types().iter(),
-                    ctx,
-                    writer,
-                    |(name, type_id), ctx, buf| {
-                        let mut stack = vec![];
-                        if let Some(name) = name {
-                            stack.push(name.clone());
-                        }
-                        type_id.serialize(ctx, (), &mut stack, buf)
-                    },
-                )?;
-                write!(writer, ")")?
+                let args = signature.argument_types();
+                if args.is_empty() {
+                    write!(writer, " (void)")?;
+                } else {
+                    write!(writer, " (")?;
+                    serialize_sep(
+                        ", ",
+                        args.iter(),
+                        ctx,
+                        writer,
+                        |(name, type_id), ctx, buf| {
+                            let mut stack = vec![];
+                            if let Some(name) = name {
+                                stack.push(name.clone());
+                            }
+                            type_id.serialize(ctx, (), &mut stack, buf)
+                        },
+                    )?;
+                    write!(writer, ")")?
+                }
             }
             TypeKind::ResolvedTypeRef(type_id) => {
                 if self.is_const() {


Test patch:
diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
index cf1106ec..a8fd5045 100644
--- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
+++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
@@ -11,6 +11,7 @@ int takes_alias__extern(func f) { return takes_alias(f); }
 int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); }
 enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); }
 void nevermore__extern(void) { nevermore(); }
+int takes_fn_with_no_args__extern(int (f) (void)) { return takes_fn_with_no_args(f); }
 void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); }
 int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); }
 int wrap_as_variadic_fn1__extern(int i, ...) {
diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs
index 03f3907e..46b369b2 100644
--- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs
+++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs
@@ -50,6 +50,12 @@ extern "C" {
     #[link_name = "nevermore__extern"]
     pub fn nevermore();
 }
+extern "C" {
+    #[link_name = "takes_fn_with_no_args__extern"]
+    pub fn takes_fn_with_no_args(
+        f: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>,
+    ) -> ::std::os::raw::c_int;
+}
 extern "C" {
     #[link_name = "no_extra_argument__extern"]
     pub fn no_extra_argument(va: *mut __va_list_tag);
diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h
index 8dcabe7b..131b7ab1 100644
--- a/bindgen-tests/tests/headers/wrap-static-fns.h
+++ b/bindgen-tests/tests/headers/wrap-static-fns.h
@@ -52,6 +52,10 @@ static inline void nevermore() {
     while (1) { }
 }
 
+static inline int takes_fn_with_no_args(int(f)(void)) {
+    return f();
+}
+
 static inline int variadic(int x, ...) {
     return x;
 }