780 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez
a519f1bda4 Actually use the temp dir for temporary compiled objects.
If the cbindgen_output is an absolute path, then join() will just return it.

Really fixes #499.
2020-04-04 23:46:42 +02:00
Emilio Cobos Álvarez
4a38a48937 Release 0.14.0
* Minor tweak at how [export.exclude] is handled to allow excluding generic
   instantiations in C mode. (#501)
 * Documented cpp_compat option. (#496)
 * Fixed a panic when parsing associated constants for a built-in type. (#494)
2020-04-04 23:32:40 +02:00
Emilio Cobos Álvarez
39bae60ad7 Generate test object files in a temporary directory instead of in-tree
Closes #499

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2020-04-04 17:54:52 +02:00
Emilio Cobos Álvarez
ec1631f3e4 Allow excluding monomorph structs in C mode.
Fixes #500.
2020-04-01 11:45:53 +02:00
Evgeniy Reizner
6fd245096d Add missing cpp_compat documentation. 2020-03-23 10:54:49 +01:00
Emilio Cobos Álvarez
c265a7562a parser: Don't panic when finding associated constants to a primitive.
We don't handle it, but no reason to panic.

Fixes #493
2020-03-21 17:23:02 +01:00
Emilio Cobos Álvarez
17d7aad7d0 Release v0.13.2 2020-03-21 03:31:26 +01:00
Emilio Cobos Álvarez
fc577f2a28
support large integer constants (#490)
Avoid gcc warning by appending ULL suffix to integer literals that are too big to fit in a signed 64-bit integer.
2020-03-11 15:34:33 +01:00
Joe Devietti
6218281443 updated constant_big test case with large negative numbers 2020-03-11 09:58:10 -04:00
Joe Devietti
8638652d1d ran rustfmt 2020-03-09 23:13:54 -04:00
Joe Devietti
7101465403 avoid gcc warning by appending ULL suffix to integer literals that are too big to fit in a signed 64-bit integer 2020-03-09 23:11:51 -04:00
TheKK
5a4d74b911 ir: escape export_name while writing source of EnumVariant 2020-03-09 15:58:56 +01:00
TheKK
e2b2c81221 ir: escape tagged union's field name 2020-03-09 15:58:56 +01:00
Emilio Cobos Álvarez
c3442809b9 tests: Add tests for cell and refcell. 2020-03-09 01:49:14 +01:00
Emilio Cobos Álvarez
249b41ce8a ir: Add support for RefCell and Cell.
RefCell is opaque. Cell is repr(transparent) so can just be the inner type.

Simplify it the same way as we simplify Option<&mut T> and such.

Fixes #488
2020-03-09 01:49:14 +01:00
Emilio Cobos Álvarez
6654f99251
main: Provide a somewhat-useful error message for --verify changes. 2020-03-04 00:58:45 +01:00
Emilio Cobos Álvarez
06b1608eff
tests: Add missing expectations to 462871695d621a055d32644f9bbdb4f9f9cdb38e. 2020-03-04 00:52:15 +01:00
Emilio Cobos Álvarez
93f1fc2666
Blind-ish attempt to fix CI 2020-03-04 00:11:50 +01:00
Emilio Cobos Álvarez
910e1ee88f
template: Add allow_constexpr to template.toml. 2020-03-03 21:15:27 +01:00
Emilio Cobos Álvarez
3483359374
remove a test which was causing CI to go red. 2020-03-03 21:14:06 +01:00
Emilio Cobos Álvarez
b6c2f3c59d
constant: Fix the interaction of allow_constexpr and inline consts. 2020-03-03 21:10:47 +01:00
Emilio Cobos Álvarez
f50fbda469
parser: Fix a warning that somehow didn't turn the build red. 2020-03-03 20:47:18 +01:00
AlaskanEmily
462871695d
Add option to output constexpr generated constant primitive values
This is controlled by the [const] allow_constexpr option, similar to the
allow_static_const option.

It's only applied to primitives currently.
2020-03-03 20:46:12 +01:00
TheKK
61e55ce4d9 ir: write declaration of global variable like struct fields 2020-02-25 21:06:43 +01:00
AlaskanEmily
dfa6e5f982 Check for CFLAGS and CXXFLAGS when running tests
This is needed when running tests with clang/clang++, as some of the tests have
errors that clang reports which gcc does not such as unused static const
variables.
2020-02-25 01:24:27 +01:00
yingrueil
3b6647ba04 parser: warn when function is partial exported
Functions will be fully exported when they are `pub, `no_mangle`, and `extern
"C"`. Only two cases we should not generate warning which are `pub, `no_mangle`,
and `extern "C"` are all enabled or disabled.
2020-02-24 14:37:30 +01:00
yingrueil
b4d3b393c3 parser: don't warn when function is not extern c and not no_mangle 2020-02-24 14:37:30 +01:00
yingrueil
4463267bd2 parser: use match statement to replace nested if-else statement 2020-02-24 14:37:30 +01:00
yingrueil
bd2e43001e parser: extract condition for abstractions 2020-02-24 14:37:30 +01:00
Emilio Cobos Álvarez
69b3d20a92
Add tests for #475. 2020-02-22 14:17:00 +01:00
Jeff Gilbert
776d010aab Only write default cases if the switch is not exhaustive.
This fixes C++ -Wcovered-switch-default warnings.
2020-02-22 14:16:28 +01:00
Emilio Cobos Álvarez
c83137f366
cargo: don't read cargo.toml if not needed. 2020-02-20 23:21:47 +01:00
Emilio Cobos Álvarez
97ab4345f1
cdecl: pass config instead of recomputing void_prototype all over the place. 2020-02-17 22:50:48 +01:00
Emilio Cobos Álvarez
953390ba5e
bindgen: enable "void prototype" while writing struct field (#473)
This fixs typedef's signature in C as well because a typedef statement is
constructed like, "typedef " + field_like_string.
2020-02-17 22:37:11 +01:00
yingrueil
4c44e8a382 ty: decide if using void prototype in field by checking language 2020-02-17 13:23:30 +08:00
yingrueil
0163b83d76 bindgen: enable "void prototype" while writing struct field
This fixs typedef's signature in C as well because a typedef statement is
constructed like, "typedef " + field_like_string.
2020-02-15 13:03:44 +08:00
Arnav Singh
c6809b00fb
Emit documentation on constants (#471)
Fixes #403
2020-02-11 01:51:57 +01:00
Emilio Cobos Álvarez
3b97f4ff6b
Release 0.13.1.
* Support #[cfg] on individual enum variants. (#469)
2020-02-09 15:48:11 +01:00
Emilio Cobos Álvarez
5c2fab7919
ir: Minor fix for conditions around enums. 2020-02-08 23:21:42 +01:00
Emilio Cobos Álvarez
4d2b2026b6
ir: cfg: Cleanup the cfg code a bit more. 2020-02-02 19:48:14 +01:00
Emilio Cobos Álvarez
0f0ea8596d
ir: cfg: Deindent some code. 2020-02-02 19:42:51 +01:00
Emilio Cobos Álvarez
b27b76978e ir: Always write #if and #endif at the beginning of the line. 2020-02-02 18:29:29 +01:00
Emilio Cobos Álvarez
0ba79888ea ir: enum: Generate all the per-variant helpers together. 2020-02-02 18:29:29 +01:00
Emilio Cobos Álvarez
ee21bfc1f0 ir: Simplify and make slightly more efficient the ToCondition trait. 2020-02-02 18:29:29 +01:00
Emilio Cobos Álvarez
854172561a ir: Handle cfg in enum variants. 2020-02-02 18:29:29 +01:00
Emilio Cobos Álvarez
5e667158a1
Release v0.13.0
* Support 'swift_name' attributes on generated functions (#449)
 * Add [export.pre_body] to config (#452)
 * Handle new line in doc attribute (#454)
 * Add support for `Self` in tagged enums, structs and unions (#455, #455, #456)
 * Make sentinel variant respect regular config (#459)
 * Fix layout of tagged enums with size under some configurations (#463)
 * Add an option to allow configuring the order of function names in generated headers (#466)

Thanks to all the awesome contributors.
2020-01-31 01:54:19 +01:00
Andreas Dinter
723e690027 Add test cases for 'sort_by' option 2020-01-27 16:03:12 +01:00
Andreas Dinter
f5edc2c2ab Document usage of 'sort_by' option 2020-01-27 16:03:12 +01:00
Andreas Dinter
2fb3e1d9c4 Add option to specify ordering of generated C function prototypes 2020-01-27 16:03:12 +01:00
John VanEnk
4cb762ec8f Do not emit enum TagName tag when a sized representation is present.
This affected cases where the style was set to `Stle::Tag`.

In enumerations, do not emut the tag type name with an `enum`
prefix. C treats the `enum` type as an `int` even if the
representation should be something else.

Here's an example non-C-like-enumeration:

    #[repr(C, u8)]
    enum P {
        P1(u8),
        P2(u8, u8),
        P3(u8, u8, u8),
    }

Without this patch, this is what's generated:

    enum P_Tag {
      P1,
      P2,
      P3,
    };
    typedef uint8_t P_Tag;

    typedef struct {
      uint8_t _0;
    } P1_Body;

    typedef struct {
      uint8_t _0;
      uint8_t _1;
    } P2_Body;

    typedef struct {
      uint8_t _0;
      uint8_t _1;
      uint8_t _2;
    } P3_Body;

    typedef struct {
      enum P_Tag tag;
      union {
        P1_Body p1;
        P2_Body p2;
        P3_Body p3;
      };
    } P;

Rust expects the size of the type to be 4 (one for the discriminant,
and 3 for the widest alternative. C, however, treats the `enum P_Tag
tag` field as an `int` rather than a `uint8_t`. This puts the size
(with padding) of of `P` to 8 bytes instead of 4. When passing this
type between Rust and C, they will disagree on the size.

After the patch is applied, the `P` struct is properly defined:

    typedef struct {
      P_Tag tag;
      union {
        P1_Body p1;
        P2_Body p2;
        P3_Body p3;
      };
    } P;
2020-01-26 04:43:27 +01:00