Commit Graph

62 Commits

Author SHA1 Message Date
徐未来 f9afaba08a 适配syn升级至2.0
Signed-off-by: 徐未来 <xuweilai2@huawei.com>
2024-04-02 15:05:30 +08:00
lubinglun 1a017c9476 Add GN Build Files and Custom Modifications
Issue:https://gitee.com/openharmony/build/issues/I6UFTP
Signed-off-by: lubinglun <lubinglun@huawei.com>
2023-04-12 17:25:45 +08:00
Justin W Smith bd4c765685 Release 0.64.0 Request (#2399)
Prepare 0.64.0 Release

---------

Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
2023-02-07 10:36:50 -05:00
Christian Poveda Ruiz bd14f85019 Generate extern wrappers for inlined functions (#2335)
* Generate extern wrappers for inlined functions

If bindgen finds an inlined function and the
`--generate-extern-functions` options is enabled, then:

- It will generate two new source and header files with external
  functions that wrap the inlined functions.
- Rerun `Bindings::generate` using the new header file to include these
  wrappers in the generated bindings.

The following additional options were added:
- `--extern-function-suffix=<suffix>`: Adds <suffix> to the name of each
  external wrapper function (`__extern` is used by default).
- `--extern-functions-file-name=<name>`: Uses <name> as the file name
  for the header and source files (`extern` is used by default).
- `--extern-function-directory=<dir>`: Creates the source and header
  files inside <dir> (`/tmp/bindgen` is used by default).

The C code serialization is experimental and only supports a very
limited set of C functions.

Fixes #1090.

---------

Co-authored-by: Amanjeev Sethi <aj@amanjeev.com>
2023-02-07 10:13:48 -05:00
Josh Guilfoyle df08ad80cf Add *-espidf target triple mappings (#2397)
Fixes #2396.

This makes it possible to workaround cc/bindgen issues with esp-rs
projects by using only environment varaibles (TARGET_CC, CLANG_PATH,
etc).  Without this, it requires modifying each crate's build.rs that
you try to depend on to add a target option passed along to clang.
2023-01-25 17:54:19 -05:00
Dan Dumont e8f278ed11 Implement cli option for custom derive (#2328)
* custom derives after DeriveInfo

* Introduce `TypeKind` instead of `CompKind`

* Add tests

* Emit CLI flags for callbacks

* update changelog

* run rustfmt

* fix tests

* fix features

Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
2023-01-20 15:12:42 -05:00
Andrew Walbran 01dea3b4a4 Update to clap 4. (#2380)
* Update to clap 4.

* Bump MSRV to minimum required by clap 4.

* Mention clap update in CHANGELOG.
2023-01-12 15:37:48 -05:00
Emilio Cobos Álvarez efc8293c07 codegen: Look through typedefs to detect void return type. (#2379)
* codegen: Look through typedefs to detect void return type.

And reuse a bit more code.

Should fix #2377, but needs a test (can't run tests atm).

* Add tests

* Run rustfmt

* Update changelog

Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
2023-01-06 13:07:28 -05:00
Christian Poveda Ruiz d6965c9264 Extend documentation about deprecation of wildcard patterns (#2374) 2022-12-15 16:02:28 -05:00
Christian Poveda Ruiz 3685af64ac Fix clippy warnings (#2371) 2022-12-09 16:15:59 -05:00
Emilio Cobos Álvarez a0af678a04 codegen: Do generate field offset checks for classes with multiple bases.
The bug only affects virtual inheritance, so instead disable layout
tests in the test that we know is broken. Not generating layout tests is
wrong anyways, because the offset would be wrong.
2022-12-07 12:18:35 +01:00
Christian Poveda Ruiz e16d1aff3f Document callback changes and avoid static lifetime (#2366) 2022-11-28 14:01:25 -05:00
Justin W Smith f6b05a4053 Extend generated_name_override callback to variables (#2351)
* This change updates `ParseCallbacks::generated_name_override` to accept a second parameter indicating the kind of item the name applies to (currently, either `Function` or `Var`).
* A `CallbackItemKind` enum was added to serve as the type for this second parameter.
* Tests have been updated to verify that the names of both function and variable can be updated by this callback.
2022-11-28 13:16:10 -05:00
David Tolnay 14df65cb32 Fix name collision between C enum and typedef (#2326)
Fixes #2008.

Example:

```c
enum Enum { Variant };
typedef int16_t Enum;
```

This is valid and idiomatic C (though not valid C++). `cbindgen` uses this idiom as the default C translation of Rust enums, the equivalent of what would be `enum Enum : int16_t { Variant };` in C++.

`bindgen header.h` before:

```rust
pub const Enum_Variant: Enum = 0;
pub type Enum = ::std::os::raw::c_uint;
pub type Enum = i16;
```

```console
error[E0428]: the name `Enum` is defined multiple times
 --> generated.rs:3:1
  |
2 | pub type Enum = ::std::os::raw::c_uint;
  | --------------------------------------- previous definition of the type `Enum` here
3 | pub type Enum = i16;
  | ^^^^^^^^^^^^^^^^^^^^ `Enum` redefined here
  |
  = note: `Enum` must be defined only once in the type namespace of this module
```

After:

```rust

pub const Enum_Variant: Enum = 0;
pub type Enum = i16;
```
2022-11-28 09:40:20 -05:00
Christian Poveda Ruiz b898d1c84f Remove traits that have a single implementation (#2363) 2022-11-24 11:17:08 -05:00
Christian Poveda Ruiz 4b3940e6c8 Fix clippy warnings (#2362) 2022-11-24 10:50:15 -05:00
Christian Poveda Ruiz 870e9723bc Escape method fragments that happen to be rust keywords (#2359) 2022-11-23 12:48:24 -05:00
Christian Poveda Ruiz b7fcf872dd Deprecate Rust targets lower or equal than 1.30 (#2356) 2022-11-22 12:31:14 -05:00
Christian Poveda Ruiz 3b303cc072 Add --wrap-unsafe-ops option (#2354)
This reverts commit fc6c702695 and adds a new `--wrap-unsafe-ops` option as a workaround.
2022-11-22 11:41:32 -05:00
Christian Poveda Ruiz ba546f41c4 Add ParseCallbacks::process_comment (#2347)
This method can be used to process comments and replace them with whatever the user wants.
2022-11-22 11:25:13 -05:00
Christian Poveda Ruiz 0cbd492cc5 Introduce DeriveInfo (#2355)
This PR introduces a new non-exhaustive `struct` called `DeriveInfo` to be used as the sole argument of `ParseCallbacks::add_derives` with the purpose of being able to extend the information passed to this method in a backwards-compatible manner, meaning that adding new fields to `DeriveInfo` won't be a breaking change when releasing a new version.
2022-11-21 10:38:42 -05:00
Christian Poveda Ruiz f730d1dc57 Remove deprecated methods (#2346) 2022-11-17 10:02:29 -05:00
Fabio Valentini 0d9e9967f6 add LICENSE symlinks to all individually published crates 2022-11-17 14:35:56 +01:00
Christian Poveda Ruiz 99ad2beef6 document regex arguments handling (#2345) 2022-11-14 12:34:05 -05:00
Christian Poveda Ruiz e682f5e260 Document and test allowlisting and blocklisting methods (#2344) 2022-11-11 13:01:53 -05:00
Christian Poveda Ruiz ab2d1c2e8b Fix duplicated function names (#2341)
Even though this change does name deduplication in a slower way, it
avoids name collisions without any breaking changes in the test suite.

Fixes #2202
2022-11-11 11:48:39 -05:00
Christian Poveda Ruiz 935202b30f Handle the const struct * and struct * patterns (#2304)
Given that C keeps a different namespace for `struct`/`enum`/`union` and `typedef` aliases. The
following patterns
```c
typedef const struct foo {
    void *inner;
} *foo;

typedef struct bar {
    void *inner;
} *bar;
```
are valid C code and produces both a `struct` and a pointer called `foo`
and `bar` in different namespaces. Given that Rust does not make this
distinction, we add the `_ptr` prefix to the pointer type aliases to
avoid any name collisions.
2022-11-10 10:43:02 -05:00
kohanis fead7eb893 Fix inline function identification 2022-11-09 16:04:01 +01:00
Emilio Cobos Álvarez af37751915 ir: Don't crash with built-in unexposed types from libclang.
This fixes #2325.

The issue is that `__bf16` is not exposed at all by libclang, which
causes us to crash. It's a bit of a shame libclang doesn't expose it but
there's no rust equivalent I think, so this should be ok for now.

Unfortunately no test because the header crashes older clang versions.
2022-11-09 13:54:34 +01:00
Christian Poveda Ruiz fc6c702695 Wrap unsafe function's bodies in unsafe blocks (#2266)
This guarantees that bindings generated by `bindgen` compile even if the `unsafe_op_in_unsafe_fn` lint is denied.
2022-11-04 15:22:49 -05:00
Christian Poveda Ruiz 5d59fb14d9 Clean the implementation of Default for BindgenOptions (#2332)
* Clean the implementation of `Default` for `BindgenOptions`
2022-11-04 13:08:14 -05:00
Christian Poveda Ruiz 334f644b1d Add support for the "C-unwind" ABI (#2334)
* Add support for the `"C-unwind"` ABI

This allows using `"C-unwind"` as an ABI override if the rust target is
nightly.
2022-11-04 10:19:28 -05:00
Christian Poveda Ruiz 18ccd45509 Add the --override-abi option (#2329)
* Add the `--override-abi` option.

This option can be used from the CLI with the <abi>:<regex> syntax and
it overrides the ABI of a function if it matches <regex>.

Fixes #2257
2022-11-02 15:30:34 -05:00
Christian Poveda Ruiz 8136142661 Allow callback composition (#2330)
* Allow callback composition

Store all the callbacks added to the builder in a `Vec` so bindgen
invokes each one of them in a last-to-first manner.
2022-11-02 13:46:22 -05:00
Christian Poveda Ruiz 36eb92ba85 Fix clippy warnings (#2331) 2022-11-02 13:32:32 -05:00
Christian Poveda Ruiz 6f71fafe26 Add a mechanism to rerun bindgen with the same user options (#2292)
* Run `Bindings::generate` again if required.

This adds a mechanism so `bindgen` is able to run `Bindings::generate`
multiple times with the same user input if the `generate_static_inline`
option is enabled and `GenerateResult::ShouldRestart` is returned by
`Bindings::generate`.

This is done to eventually solve #1090 which would require to check for
any static inline functions and generate a new header file to be used as
an extra input and run `Bindings::generate` again.
2022-11-01 08:49:57 -05:00
Adam Gausmann 0cb72922b7 Sanitize RegexSet input so alternation is properly handled (#1756)
* tests: Avoid using globs as regexes

* Sanitize regex set input to properly handle alternation

* Add test case for alternates/anchors interaction

* emit warning if wildcard pattern is used

* update changelog and bump versions

Co-authored-by: Darren Kulp <darren@kulp.ch>
Co-authored-by: Christian Poveda <christian.poveda@ferrous-systems.com>
2022-10-24 10:39:52 -05:00
Darren Kulp 4cd4e4174c Remove Travis-CI badges
Travis-CI was fully removed as of a5f9b70dca.

The only badge now [mentioned in the Cargo book][1] is `maintenance`. The
`travis-ci` badge reference was [removed from Cargo two years ago][2]. The
Cargo book advises putting badges in README.md instead.

[1]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-badges-section
[2]: https://github.com/rust-lang/cargo/commit/60779a006f98fba1680182c174134363d08e0a9b
2022-10-22 18:45:03 +02:00
Emilio Cobos Álvarez 1c8b9738de clang: Detect anonymous items explicitly, rather than relying on empty names.
In Clang 16, anonymous items may return names like
`(anonymous union at ..)` rather than empty names.

The right way to detect them is using clang_Cursor_isAnonymous.

Fixes #2312
Closes #2316

Co-Authored-by: Patrick Walton <pcwalton@fb.com>
2022-10-22 14:24:01 +02:00
Christian Poveda 49afd96b4f Use panic hooks instead of using catch_unwind
One of the advantages of doing this is that `ParseCallbacks` no longer
needs to implement `UnwindSafe` which means that users can rely on
`RefCell` and `Cell` to extract information from the callbacks.

Users relying on `catch_unwind` can still achieve similar behavior using
`std::thread::spawn`.

Fixes #2147.
2022-10-22 13:11:45 +02:00
Emilio Cobos Álvarez 9c6bcea939 Specify readme properly. 2022-10-16 21:56:05 +02:00
Emilio Cobos Álvarez 2d5755709b v0.61.0 2022-10-16 21:44:20 +02:00
Emilio Cobos Álvarez 9e66268502 ci: clippy fixes.
The allowed casts are because c_longlong etc aren't guaranteed to map to
i64 / etc. I believe c_double maps to f64 in all platforms tho.
2022-10-16 21:29:41 +02:00
Emilio Cobos Álvarez 524438387a Remove no-longer-correct include entry in Cargo.toml. 2022-10-16 21:29:41 +02:00
Emilio Cobos Álvarez b7849e9563 Move the csmith-fuzzing directory to the top level. 2022-10-16 21:29:41 +02:00
Christian Poveda 7a5876cdf7 Handle incomplete external array constants
This adds a new special case for constants like:
```c
extern const char some_static_string[];
```
so `bindgen` emits a `static` instead of a `static mut` for them.
2022-10-16 20:23:34 +02:00
Christian Poveda ad20d325df Merge pull request #2302 from ferrous-systems/clonable-builder
Implement `Clone` for `Builder`
2022-10-12 11:07:37 -05:00
Christian Poveda 55e0ce6f75 Merge pull request #2299 from ferrous-systems/more-robust-postprocessing
Make postprocessing more robust
2022-10-10 09:46:26 -05:00
Christian Poveda 5d93b0145b Implement Clone for Builder
This is done by moving all the remaining `Builder` state into
`BindgenOptions` so any internal logic that affects `Builder` state only
runs once the builder is consumed by `Builder::generate`:

- move `input_headers` to `BindgenOptions`.
- move `input_header_contents` to `BindgenOptions`.
- derive `Clone` for `Builder`.
2022-10-07 14:10:24 -05:00
Christian Poveda 12c8268404 Make postprocessing more robust
This is done by merging extern blocks and sorting items in every module
instead of just in the root module.

The tests were changed to use `cxx` namespaces so they effectively check
that items are manipulated correctly in every single module.
2022-10-06 14:52:29 -05:00