299 Commits

Author SHA1 Message Date
Mrmaxmeier
161d83c0b1 add lifetime_arg test 2018-10-16 15:50:23 -05:00
Emilio Cobos Álvarez
02c1cbad79 Keep prefixing the body of tagged enums in C since it has no scoping. 2018-10-04 10:08:25 -05:00
Emilio Cobos Álvarez
15d7cb8904 Fix tagged enum's interactions with prefixing. 2018-10-04 10:08:25 -05:00
konstin
8faf7011ae Add no_includes option 2018-10-01 16:53:09 -05:00
IGI-111
110c3e481c Add support for associated constants and struct literals (#170)
* handle associated constants and struct literals

This aims to fix #100 by adding parsing support for associated constants, and
struct literal expressions.

It duplicates some of the parsing for constants, but sadly ImplItemConst and
ImplConst (as well as their children) don't share a common trait
that would allow for genericity.

It also uses the same namespace for both constants and associated
constants, which could cause conflicts in valid Rust with shared const names in
different scopes.

The struct literals use the standard C99 syntax. Do mind that the
limitations on literal expressions still apply.

* added test cases

* fix formatting
2018-10-01 16:37:51 -05:00
Vincent Esche
5e6d58dfe3 Added support for #[repr(transparent)] 2018-08-28 16:35:04 -05:00
Emilio Cobos Álvarez
52270a23af Apply renaming rules to the generated eq/neq impls. 2018-08-17 23:15:50 -05:00
Emilio Cobos Álvarez
863a49f64f Don't compare the tag on tagged structs.
We could assert, I guess, should it be wanted.
2018-08-17 23:15:50 -05:00
Emilio Cobos Álvarez
1e4b90bb1a Honor derive_eq / derive_neq for unions. 2018-08-17 23:15:50 -05:00
Vincent Esche
68a22aac3c Added test mod_attr project
Added impl of `fmt::Display` for `Cfg`

Added  `fn matched_defines(…)` for filtering for matches in `[defines]`

Changes semantic of `has_defines` from `∀` to `∃` (i.e. all -> one or more)

Changed `write_before` to use `matched_defines`

Added logging of warning for omitted `#[cfg(…)]`s

Added expectations for `mod_attr` test project

Renamed function arguments in `mod_attr` test project

Rustfmt

Introduced `Condition` type to ensure correct API usage of `Cfg`

Merged `Condition::Boolean` and `Condition::Named` into `Condition::Define`

Removed `DefineConfig` and `MissingDefineBehavior`.

(Was getting a bit ahead of myself with these.)

Rustfmt
2018-08-17 23:15:16 -05:00
Vincent Esche
b07046d28a Fixed missing prefix for named consts in [T; <Const>] types 2018-08-14 00:47:35 -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
Basile Clement
ba589a868e Use Cargo.lock from workspace root
cbindgen currently assumes that the `Cargo.lock` is in directly in the
crate directory as a sibling to `Cargo.toml`; however that is usually
not the case inside a workspace.

Instead, this PR extracts the workspace root from the output of `cargo
metadata` [1] (already used to get a list of packages) and uses the
`Cargo.lock` from there.

 1. This is available since Rust 1.24; see rust-lang/cargo#4940
2018-07-30 22:02:56 -05:00
Emilio Cobos Álvarez
5da9ae98d3 Basic item_types test. 2018-07-25 13:54:10 -05:00
Emilio Cobos Álvarez
e3e1bb82bf bindings: Don't generate redundant autogen warnings or extern blocks. 2018-07-25 13:54:10 -05:00
Ryan Hunt
d192544c7f Add two parsing only tests for #164 and #169 2018-05-31 10:46:28 -05:00
Alexis Beingessner
cabe1055c4 Add tests for optional enum convenience constructors 2018-04-25 13:40:58 -05:00
Alexis Beingessner
da550f53b2 Implement optional convenience constructors for tagged enums 2018-04-25 13:40:58 -05:00
Johan Anderholm
3a9bb17e8a Modify test to run all three styles for C. 2018-03-27 10:05:45 -05:00
Ryan Hunt
1693519e39 Update test expectations from size_t to uintptr_t changes 2018-03-14 14:40:40 -05:00
Ryan Hunt
cf3529fa84 Don't use extern crate aliases when searching for dependencies 2018-03-14 14:40:40 -05:00
Dan Robertson
0c9c32ecdb Improve module path parsing
If a module has a path attribute use this as the module path to parse.
2018-03-14 13:42:18 -05:00
Dan Robertson
22fa8b0824 Ensure that a constants cfg is preserved
When writing out constants the cfg attribute is not written out around
the defined constant.
2018-03-12 12:44:57 -04:00
Ryan Hunt
e336f80ff8 Update syn to 0.12.6 2018-01-31 23:28:20 -06:00
Ingvar Stepanyan
70d8b95f78 Disallow unknown and conflicting repr markers 2018-01-31 09:35:29 -06:00
Ingvar Stepanyan
f9b8512dc2 Wrap tag into anonymous struct in C++
Fixes #122
2018-01-31 09:35:29 -06:00
Ingvar Stepanyan
0ebcf99d31 Fix wrapper kind for C-like tagged enum
Fixes #126
2018-01-31 09:35:29 -06:00
Ingvar Stepanyan
07eae4c171 Implement support for repr(C, Int)
Fixes #119
2018-01-31 09:35:29 -06:00
Ryan Hunt
33407202e1 Specify --lib with cargo expand and add crate testing 2018-01-29 15:17:23 -06:00
Ryan Hunt
4e481c1338 Add dependencies for tagged enums 2018-01-29 14:08:02 -06:00
Ingvar Stepanyan
bd494d4646 Simplify enum variant handling 2018-01-29 11:36:59 -06:00
Ingvar Stepanyan
3355f2b1ff Rename fields generated by tagged enum 2018-01-29 11:36:59 -06:00
Ingvar Stepanyan
905b9a09aa Add support for repr(C) tagged enums too 2018-01-29 11:36:59 -06:00
Ingvar Stepanyan
3b61c8ead5 Initial support for tagged enums 2018-01-29 11:36:59 -06:00
Kartikaya Gupta
2ccaa3e956 Add a derive_constructor option to generate struct constructors 2018-01-25 12:22:01 -06:00
Mrmaxmeier
d4ae7fcafd update tests 2018-01-10 08:24:14 -06:00
Ryan Hunt
b0d4578214 Fix broken test 2018-01-04 23:30:53 -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
21d917b723 Check for no_mangle and pub on functions and static items 2018-01-04 14:52:02 -06:00
Ingvar Stepanyan
fada89c7f4 Remove Specialization in favour of generic typedef 2017-11-18 14:40:42 -06:00
Ingvar Stepanyan
4ee1a8bcc8 Remove obsolete template specialization 2017-11-18 14:40:42 -06:00
Ingvar Stepanyan
8fddc5d0a9 Emit generics as native templates in C++ 2017-11-18 14:40:42 -06:00
Ingvar Stepanyan
f0bef30daa Simplify opaque struct output in C
There is no need for a separate forward struct declaration, just like in case with regular structures.
2017-11-16 23:26:07 -06:00
Ryan Hunt
864b4a22f9 Use Parser for single source mode 2017-11-14 02:00:04 -05:00
Ryan Hunt
aa9c20bc03 Do not emit const char* for &str 2017-11-13 23:05:00 -05:00
Ryan Hunt
6a02ec4a7f Commit test expectations 2017-11-09 18:04:22 -05:00
Ryan Hunt
a711eb45b2 Move tests to compile-tests 2017-05-11 01:34:43 -04:00
Ryan Hunt
0aada672cd Add a test harness
Fixes #3
2017-05-11 01:16:27 -04:00