Fixes the following warning:
> Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2, actions-rs/cargo@v1, actions-rs/toolchain@v1. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.
Steps:
- upgrade checkout to v3
- Replace the actions-rs/cargo action, by simply calling cargo from the commandline.
I don't see why one would want to involve a node.js action there in the first place.
- Replace the actions-rs/toolchain with dtolnays version, which uses the shell instead
of node.js
Instead of two steps installing the toolchain, do it one step.
Removes the unmaintained action-rs/toolchain action.
Installs stable clippy instead of nightly clippy.
The current implementation never goes to a new line when writing a
function pointer type, this can lead to long, difficult to read lines.
The goal of this change is to make that a bit more sensible.
Here is a rust code example
```
1 │ pub type MyCallback = Option<unsafe extern "C" fn(a: usize, b: usize)>;
2 │
3 │ pub type MyOtherCallback =
4 │ Option<unsafe extern "C" fn(a: usize, lot: usize, of: usize, args: usize)>;
5 │
6 │ #[no_mangle]
7 │ pub extern "C" fn my_function(a: MyCallback, b: MyOtherCallback) {}
```
right when generating the corresponing C header we get
```
1 │ #include <stdarg.h>
2 │ #include <stdbool.h>
3 │ #include <stdint.h>
4 │ #include <stdlib.h>
5 │
6 │ typedef void (*MyCallback)(uintptr_t a, uintptr_t b);
7 │
8 │ typedef void (*MyOtherCallback)(uintptr_t a, uintptr_t lot, uintptr_t of, uintptr_t args);
9 │
10 │ void my_function(MyCallback a, MyOtherCallback b);
```
line 8 here is already quite long and will be even longer if we add new
args to `MyOtherCallback`
With the changes in this commit, we now get
```
1 │ #include <stdarg.h>
2 │ #include <stdbool.h>
3 │ #include <stdint.h>
4 │ #include <stdlib.h>
5 │
6 │ typedef void (*MyCallback)(uintptr_t a, uintptr_t b);
7 │
8 │ typedef void (*MyOtherCallback)(uintptr_t a,
9 │ uintptr_t lot,
10 │ uintptr_t of,
11 │ uintptr_t args);
12 │
13 │ void my_function(MyCallback a, MyOtherCallback b);
```
which is way better and more scalable if new args are atted to
`MyOtherCallback`
The behavior is configurable using the already existing `fn.args`
configuration parameter. In this case setting it to `Horizontal` gives
back the same .h as previously and setting it to `Vertical` makes the
generator go to a new line even for the shorter `MyCallback`
declaration:
```
1 │ #include <stdarg.h>
2 │ #include <stdbool.h>
3 │ #include <stdint.h>
4 │ #include <stdlib.h>
5 │
6 │ typedef void (*MyCallback)(uintptr_t a,
7 │ uintptr_t b);
8 │
9 │ typedef void (*MyOtherCallback)(uintptr_t a,
10 │ uintptr_t lot,
11 │ uintptr_t of,
12 │ uintptr_t args);
13 │
14 │ void my_function(MyCallback a,
15 │ MyOtherCallback b);
```
Closes#793
While the Cargo.lock has 1.0.89, the current minimal version in Cargo.toml
is 1.0.3, which cannot parse modern Rust code. This leads to some
downstreams (*cough* Debian) inadvertently building cbindgen against
older versions of syn and the resulting cbindgen, even if it is the last
version, not being able to parse recent Rust code.
Bumping the version in Cargo.toml alleviates this to some extent. A
quick scan of the syn logs suggests 1.0.88 is the last version where
parsing support relevant to stable Rust syntax was added.