299 Commits

Author SHA1 Message Date
John VanEnk
70188bb3b2 Enable most warnings, and make them errors.
This adds `-Wall` and `-Werror` to the C and C++ compiler flags. It
also adds `-Wno-attributes` to disable warnings about unrecognized
attributes. This is needed because the `swift_name` test relies on
`__attribute__((swift_name(some_name)))` attribute.
2020-01-24 11:22:39 +01:00
John VanEnk
fb348d91e8 Change std=c++11 to std=c++17 to support inline variables.
The inline variables feature is used by the associated_in_body test.
2020-01-24 11:22:39 +01:00
John VanEnk
e8ff3f9b61 Use a magic value other than 42
Shifting a literal (which is an int when a suffix is not present)
generates a warning because the only possible result is 0, and the
programmer probably didn't intend to do that.

Change the shift to a value less than 32. The test exhibiting the
warning wasn't aiming to test integer promotion rules, so I've opted
to change the constant.
2020-01-24 11:22:39 +01:00
yingrueil
8a5662b4a7 Add support for handling line break in document attribute 2020-01-20 14:34:14 +01:00
Emilio Cobos Álvarez
ff8e5d591d ir: Add support for Self on struct and union fields. 2020-01-16 21:07:34 +01:00
Emilio Cobos Álvarez
44d7cb4214 ir: Add support for Self in enum variant bodies. 2020-01-16 15:45:05 +01:00
Elliott Mahler
5b227c1062 Add [export.pre_body] to config (#452) 2020-01-13 14:26:21 +01:00
Emilio Cobos Álvarez
688407c7c9 ir: simplify a bit the previous patch. 2020-01-12 16:54:30 +01:00
Alastair Daivis
cf406e9640
Support 'swift_name' attributes on generated functions
Fixes #420
2020-01-12 16:18:17 +01:00
Bas Zalmstra
8fabbfa4b5 Fix for finding dependency version in lockfile v2
With lockfile v2 a version is not required for dependencies if the lock
file only contains a single entry for a specified crate.  However, without
a version present, at a later stage, a dependant crate will not be found
in the metadata cache which causes the dependency to be ignored completely.
This commit tries to infer the version of dependant crates when the
version specifier is missing from the contents of the lockfile.
2020-01-09 10:42:03 +01:00
Alastair Daivis
9df58e7ecd Add support for the export_name function attribute 2020-01-07 21:44:17 +01:00
Emilio Cobos Álvarez
0a80f0716d Commit the expectations of the testcase that used to panic. 2019-12-29 12:56:49 +01:00
Emilio Cobos Álvarez
b912c04a7d Add a test for expanding dependencies with Cargo.lock v2, with both conflicting and non-conflicting deps. 2019-12-29 12:56:49 +01:00
Evan Shaw
6a9066f7cd Add enum_class option
This option allows specifying that a C++ enum should be emitted with
plain `enum` rather than `enum class`. It's true that `enum class` should
generally be preferred, but sometimes there's existing code which is
already using plain `enum`, and porting that code to Rust becomes easier when
`cbindgen` can emit plain `enum`.

This option can be overridden on a per-enum basis using a `cbindgen:` annotation.

It defaults to true for two reasons:

* Backward compatibility.
* `enum class` is probably actually what you want, in general.
2019-12-29 12:55:59 +01:00
Aleksa Sarai
8c66c0c1dc tests: enum: add #[repr(u64)] test
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-12-22 14:06:12 +01:00
Emilio Cobos Álvarez
48f1038918 enum: Add an option to generate copy-assignments.
And recommend its usage if copy-constructors are being generated, as otherwise
C++ in its whole glory would do a bitwise copy, which is not really what you
want if you have constructors / destructors around.
2019-12-16 13:20:02 +01:00
Aleksa Sarai
f23d4ee6e8 tests: add tests for #[repr(packed)] and #[repr(align(...))]
The tests are very straightforward, and effecitvely are just ensuring
that the formatting works correctly and is included in all of the
important cases.

It's also very important to ensure we do not generate laid-out structs
for layouts which we cannot reasonably represent in C (such as in cases
where we weren't told what annotation to use for packed and
specifically-aligned structures). Thus, add some tests to verify that
this is the case.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2019-12-15 11:52:23 +01:00
Emilio Cobos Álvarez
230042b753 Implement more operators for bitflags. 2019-12-08 22:15:04 +01:00
Jaseem Abid
e0fe4e4c44 Add tests for expressions like (0 << SHIFT) | BOOL
Fixes https://github.com/eqrion/cbindgen/issues/412
2019-12-08 12:34:59 +01:00
Jaseem Abid
df347d984a Handle parenthesized literals like (1 << 5)
To keep things simple, this patch always adds a () around binary operations in
literals as suggested by @emilio here
https://github.com/eqrion/cbindgen/pull/425#discussion_r353740669

Some tests obviously had to be regenerated, those are included as well.
2019-12-08 12:34:59 +01:00
Emilio Cobos Álvarez
9b5dd80d84 Stop including <uchar.h>, and instead map Rust char to uint32_t.
This is technically a breaking change for C++, unfortunately.

Fixes #423.
2019-12-04 00:03:38 +01:00
Adrian Wong
8a7fbbe1ff Add test for char to char32_t mapping 2019-12-02 19:55:04 +01:00
Adrian Wong
9b1fd8ecca Fix missing C header for char32_t 2019-12-02 19:55:04 +01:00
Gyusun Yeom
3f9e54b775 Initialize struct literal with list-initializer for C++11 standard (#401)
* Emit struct literal with list-initializer when language is Cxx

* Update test results

* Add test case - struct literal order

* Memoize struct field names

* Specify struct type at front of initializer
2019-11-17 19:28:40 +01:00
Adam Wilson
01adab71d2 Surround namespace with __cplusplus ifdef in cpp_compat mode 2019-11-04 17:16:52 +01:00
Adrian Wong
087d36f32a Map char to char32_t
Rust's `char` is 32 bits wide, but `wchar_t` on Windows is 16.
Avoid truncation by mapping `char` to `char32_t`.
2019-10-04 10:39:31 +02:00
Volker Mische
7f3b8f4dcd Add tests for parser fix
The tests are based on https://github.com/vmx/cbindgen-expand-dep-bug
2019-09-21 22:42:17 +09:00
Rasmus Eneman
4415614b99 Remove using namespace from cpp compat 2019-09-02 21:50:10 +02:00
Rasmus Eneman
f1433bd3b9 Rename using => using_namespaces 2019-09-02 21:50:10 +02:00
Rasmus Eneman
4bd7b07d2f Add support for adding "using namespace" statements 2019-09-02 21:50:10 +02:00
Emilio Cobos Álvarez
959131e79b Add newlines to not generate such ugly code. 2019-08-25 17:05:22 +02:00
Emilio Cobos Álvarez
bdc560d18a Add tests for private_default_tagged_enum_constructor. 2019-08-25 17:05:22 +02:00
Bruno Kirschner
1450e39d8f Preserve indentation on comments.
As indentation is a very handy way to structure comments and increase
their readability as much of it as possible should be preserved.

This removes any trimming of leading white spaces and ensures that
any cbindgen annotations are still recognized afterwards.

... fixes #184
2019-08-08 14:07:04 +02:00
Bruno Kirschner
47e831753b Avoid trimming non whitespace characters.
Rustc already removes all leading `/` symbols during the conversion
from doc-comments into annotations. Any additional trimming of non
whitespace characters just reduces the formatting flexibility of a
comment.

... fixes #374
2019-08-08 14:07:04 +02:00
Bruno Kirschner
b4b82a500c Preserve empty lines in doc comments.
This required two changes in parallel.

As a first and obvious step it removes a check that skipped emptys
lines during documentation loading, but it was also necessary to
refactore the `get_comment_lines()` utility method as a second step.

This second refactoring was necessary as each line in a doc comment
is trimmed and transformed in its own doc attribute. The attribute
of an empty line therefore contains an empty string as value. If we
now call `lines()` on such an empty string we end up with an empty
iterator as the method is internally configured to ignore trailing
empty lines.
2019-08-03 17:38:59 +02:00
Emilio Cobos Álvarez
5f8e027290
rename to extra_bindings per IRC discussion. 2019-06-25 21:33:19 +02:00
Emilio Cobos Álvarez
16b2a25442
Turn the option into a whitelist rather than an on / off switch. 2019-06-25 21:28:12 +02:00
Emilio Cobos Álvarez
0bcd54f9c3
Add an option to generate consts / globals / fn from parsed dependencies.
This is a limitation that may not be useful if you're using it to parse known
dependencies.
2019-06-25 21:28:11 +02:00
Emilio Cobos Álvarez
2a7496c81b
Properly indent a test. 2019-06-16 22:02:26 -07:00
Gyusun Yeom
583ed40c20 Add test - custom header with no_includes 2019-06-08 19:27:58 +09:00
Gyusun Yeom
f29a525202 Add test - include_guard with no_includes config 2019-06-08 19:27:58 +09:00
Wodann
24f69ecc9b Update test expecations based on newline change 2019-06-01 10:59:47 +09:00
Wodann
af95d87c05 Improve verbosity of cpp_compat test cases 2019-06-01 10:59:43 +09:00
Wodann
82da3c0afa Add separate test expectations for C headers with C++ compatibility 2019-06-01 10:57:52 +09:00
Wodann
bbeff3e3aa Add option to generate C headers with C++ compatibility
By default C++ compatibility is disabled.
2019-06-01 10:57:50 +09:00
Wodann
767fce25d1 Add support for selection of a custom C++ compiler 2019-06-01 10:56:09 +09:00
Wodann
7970564887 Add stderr output of cbindgen to a tests error log upon failure 2019-06-01 10:56:09 +09:00
Emilio Cobos Álvarez
357f34460d Do a better job at detecting the final binary location.
Still not great, I guess we should convert the tests to run the library version
of cbindgen, but this trivially-fixes #342.
2019-05-23 16:40:06 +02:00
Alexis Beingessner
ee2af57499 require c++11 to run the test suite
fixes #330
2019-05-10 17:58:52 -04:00
Emilio Cobos Álvarez
5861271d8e ir: Add the ability to automatically derive copy-constructors for tagged enums. 2019-05-10 20:37:12 +02:00