63 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez
2bb3e9ba66 Use cargo test instead of test.py.
This makes cargo test test all the stuff in tests/rust, and thus makes tests.py
unnecessary.

Co-authored-by: Axel Nennker <axel.nennker@telekom.de>
2019-04-20 00:30:58 +02:00
Ingvar Stepanyan
944ecb958e Add C99 doc comment style
In modern C (post-C99) it's common to just use `// double-slash comments`, but currently cbindgen provides only `/* block-comment */` and `/// triple-slash comment` variants.
2019-04-14 16:20:07 +02:00
Emilio Cobos Álvarez
7619be86bd
ir: Add support for #[must_use]. (#307) 2019-03-27 00:47:21 +01:00
Emilio Cobos Álvarez
c6131722dc config: Add an option to make explicit renaming override the prefix setting.
This is useful for opaque types or types cbindgen doesn't otherwise understand.
2019-03-26 13:24:19 -05:00
Ralf Biedert
51aff0a119 Add more documentation style options (#305)
* Ignoring IDE files.

* Addresses issue #302, also amends #59 insofar that vanilla C-style now does not prefix individual lines with `*` anymore.

* Removed Javadoc reference.

* Renamed `Doxylight` to `Doxy` and changed C default to that.

* Added documentation.

* Changed enum name and applied `fmt`.

* Fixed comment.

* Fixed match.
2019-03-24 20:56:17 +01:00
Emilio Cobos Álvarez
dea102d6c8 bindgen: Allow to auto-generate asserted casts for tagged enums.
This fixes one of my pet-peeves. Without this patch, I need to add them manually
using the raw body stuff, or along the code that accesses the struct member,
none of those being ideal.
2019-03-05 11:06:01 -06:00
Emilio Cobos Álvarez
011b584d7e parser: Make bitflags expansion opt-in.
Otherwise we may break code that does its own bitflags parsing.

In particular, this will prevent Gecko builds from breaking due to:

  https://searchfox.org/mozilla-central/rev/92d11a33250a8e368c8ca3e962e15ca67117f765/gfx/webrender_bindings/webrender_ffi.h#67

(Which should go away once we start opting-in).
2019-03-05 11:02:48 -06:00
Emilio Cobos Álvarez
80da1f59aa Allow to generate associated constants in the body of C++ structs.
Opt-in since it uses a C++17 feature, but this allow exactly the same usage in
C++ and Rust, which I think is nice.

This also fixes constants of transparent structs in general, since the initial
version of this patch broke a test (associated constants in enums), so I added a
test for that too.
2019-02-23 17:58:22 -08:00
Emilio Cobos Álvarez
0a6324f4e6 config: Allow to output user-defined stuff in the struct body. 2019-01-22 18:50:12 -06:00
Ingvar Stepanyan
bc517fd899 Update few more APIs to use AsRef<Path>
This makes few more final APIs that work with files consistent with the rest.

Fixes #280.
2019-01-22 13:19:11 -06:00
konstin
8faf7011ae Add no_includes option 2018-10-01 16:53:09 -05:00
Basile Clement
33c45a26bb Add ability to specify features to use for macro expansion
Currently, `cbindgen` uses the `--all-features` flag when expanding a
dependent crate. However, this may not be desirable in a number of
cases:

 - Some C APIs may be gated by a feature flag and would not be present
   in the final cdylib depending on the features provided (for instance
   one could want to have the ability to build a "debug" version of the
   library which provides extra unstable hooks). In such cases, a
   programmatic `cbindgen` call in a build script would want to use only
   the features that will get used in the current build.

 - Some features may bring in large dependencies and/or potentially
   increase compilation time without affecting the FFI surface, and it
   would be faster and more efficient to disable them when running
   `cbindgen`.

 - Some features may require external libraries and/or hardware (e.g.
   dependencies on GPU libraries such as CUDA) that may not be available
   on the current machine without affecting the FFI surface.

To alleviate this problem, this PR adds an extended version of the
`parse.expand` configuration key, allowing control over the features
used when expanding in a way similar to the way cargo handles extended
dependencies (although note that there is a single version of each key,
since the features refer to the features of the current crate). So for
instance instead of writing `expand = ["euclid"]` one would write:

```
[parse.expand]
crates = ["euclid"]
```

which is equivalent to:

```
[parse.expand]
crates = ["euclid"]
all_features = false
default_features = true
features = ["feature1", "feature2"]
```

Note that `all_features` is set to `false` by default in order to match
cargo's behavior.

For backwards compatibility, the old syntax `expand = ["euclid"]` is
still supported and is equivalent to:

```
[parse.expand]
crates = ["euclid"]
all_features = true
default_features = true
features = null
```

In this case, `all_features` is set to `true` in order to match the
previous behavior of cbindgen.
2018-07-31 08:31:43 -05:00
Emilio Cobos Álvarez
c1c0205905 config: Add a configuration option to control which kinds of items are generated. 2018-07-25 13:54:10 -05:00
Ryan Hunt
155b54004f Use rustfmt 2018-05-31 11:50:03 -05:00
Alexis Beingessner
da550f53b2 Implement optional convenience constructors for tagged enums 2018-04-25 13:40:58 -05:00
Markus Unterwaditzer
d8e5ee69ed Add CLI and toml config option 2018-04-05 06:43:21 -05:00
Johan Anderholm
608a67b4b2 Introduce declaration styles on C structs and enums
Allow structs, enums and unions to be declared as:

struct Name {};
typedef struct {} Name;
typedef struct Name {} Name;

Opaque enums will be declared as:
struct Name;
typedef struct Name Name;
2018-03-27 10:05:45 -05:00
Kartikaya Gupta
2ccaa3e956 Add a derive_constructor option to generate struct constructors 2018-01-25 12:22:01 -06:00
Ryan Hunt
60d95258ba Add item renaming, prefixing, force including, and excluding 2018-01-04 23:29:21 -06:00
Ryan Hunt
1ae43feaaf Add the ability to specify additional includes 2018-01-04 17:25:43 -06:00
Ryan Hunt
58d3178dc5 Format with rustfmt-nightly 2017-11-18 21:44:33 -05:00
Ingvar Stepanyan
4ee1a8bcc8 Remove obsolete template specialization 2017-11-18 14:40:42 -06:00
Ryan Hunt
cdb1eefb96 Rename some types and cleanup documentation 2017-11-09 18:04:22 -05:00
Ryan Hunt
d38ffa5f7d Add support for const items 2017-10-19 00:45:24 -04:00
Ryan Hunt
8be00519d3 Improve errors and warnings 2017-10-09 21:34:00 -05:00
Ryan Hunt
20de78c79c Don't output the version number by default
It's not that useful outside of Gecko.
2017-09-29 15:33:55 -04:00
Ryan Hunt
1f2d69947b Emit #ifdef's for #[cfg] attributes 2017-08-17 20:11:09 -04:00
Ryan Hunt
b8a0bfe0ca Cleanup import statements 2017-08-12 01:53:11 -04:00
Ryan Hunt
7aff3166f8 Move annotation.rs into ir/ 2017-08-12 01:13:38 -04:00
Georg Semmler
b1990ba440 Rename config option 2017-08-03 12:20:48 -05:00
Georg Semmler
a37ff855c4 Add a option the prefix enum values by the enum name
This is mostly usefull for generated c headers because enums values
will live in the global namespace there
2017-08-03 12:20:48 -05:00
Georg Semmler
8793c227e4 Allow to translate doc comments
This adds an option to translate rust doc comments into documentation
comments in the generated c/c++ header
2017-08-03 03:50:34 -05:00
Ryan Hunt
58caa33f09 Put template specialization behind a config 2017-07-17 22:57:43 -04:00
Ryan Hunt
3fdeb4578b Allow multiple namespaces 2017-06-27 19:15:06 -04:00
Ryan Hunt
eb71d0daff Move parse configs to their own struct 2017-06-26 10:12:16 -04:00
Ryan Hunt
a78c7ff490 Add option for adding a root namespace 2017-06-21 13:46:05 -04:00
Ryan Hunt
068f9e563a Update README.md with some configuration options 2017-06-21 04:39:02 -04:00
Ryan Hunt
7a60c528f3 Only parse dependencies when specifically enabled 2017-06-21 04:20:17 -04:00
Ryan Hunt
370ed26906 Find a cbindgen.toml from the binding crate directory 2017-06-21 01:18:50 -04:00
Ryan Hunt
0cd95007a6 Add an optional whitelist for crate parsing 2017-06-20 11:16:17 -04:00
Ryan Hunt
01d88aa09b Allow excluding specific crates from being parsed 2017-06-20 01:48:34 -04:00
Ryan Hunt
a957bc2787 Add source code licenses 2017-06-20 01:28:18 -04:00
Ryan Hunt
4064a09238 Do a bunch of clean up and add some comments 2017-06-20 01:25:42 -04:00
Ryan Hunt
3f8229efb7 Use a whitelist for deciding when to use rustc --pretty=expanded 2017-05-24 21:23:21 -04:00
Ryan Hunt
2c244f3f4f Fix some doc comments 2017-05-11 13:47:52 -04:00
Ryan Hunt
38fea4ee10 Write some documentation 2017-05-11 04:16:48 -04:00
Ryan Hunt
b04df026d9 Rename directive to annotation 2017-05-11 03:57:57 -04:00
Ryan Hunt
1f5a229ac7 Default to generating C++
I don't have time to for the correct solution for C enums so I'm
reverting to generating C++ bindings for this release.
2017-05-09 18:16:48 -04:00
Ryan Hunt
723f95e16f Remove legacy config features 2017-05-08 01:21:25 -04:00
Ryan Hunt
dc6f19d645 Update WebRender config properties 2017-05-08 00:55:41 -04:00