Commit Graph

488 Commits

Author SHA1 Message Date
Emilio Cobos Álvarez dad36fef3d Test the interaction between include and prefix configurations.
This broke mozilla-central once, hopefully not twice :)
2018-11-05 08:46:56 -06:00
Emilio Cobos Álvarez e49cabfd43 ir: Cleanup get_items. 2018-11-05 08:46:56 -06:00
Luca Barbato ae964aad6c Add ptrdiff_t to the primitive types (#242) 2018-11-05 08:44:26 -06:00
Ryan Hunt ad2dc376e1 Release 0.6.7 2018-10-30 13:21:39 -05:00
Ryan Hunt 1ff333e66f Fix bustage from borked merge 2018-10-24 14:51:20 -05:00
IGI-111 436eaea8bf Add associated constant prefix (#234)
Fix for #232
This adds a type prefix for associated constants to avoid namespace
collisions. It also adds error invocation in the rare but existing
cases where an collisions still happens in the constant namespace.
2018-10-24 12:10:09 -05:00
IGI-111 d32127e3d7 Fix #229
Place constants back inside namespace and add a test to make sure they
are namespaced correctly.
2018-10-24 11:50:03 -05:00
Vincent Esche 26828c9f3e Replaced Items’ String-based names with proper Paths 2018-10-24 11:48:41 -05:00
Ryan Hunt 54424c5474 Release 0.6.6 2018-10-17 16:34:56 -05:00
Emilio Cobos Álvarez ab9e3b814c ir: Fix generic enums with untagged bodies.
Boris hit this because he used #[repr(C)] instead of #[repr(u8)].

We were incorrectly writing the generic arguments twice for those.

I missed this difference in #219.

Fixes #225.
2018-10-17 14:11:37 -05:00
Emilio Cobos Álvarez 5ac196d3ef ty: Add support for simplifying NonNull<T>.
I want this to move around slices and boxes across the style system, while
preserving the option size optimizations when they're fully in a repr(Rust)
data-structure.

This is sound because NonNull is repr(transparent):

  https://doc.rust-lang.org/src/core/ptr.rs.html#2847

I renamed simplify_option_to_ptr to simplify_standard_types because that's what
it does now.

ABI-wise for NonNull<T> it's guaranteed via repr(transparent). For
Option<NonNull<T>> it is as well, though I've asked in #rustc to confirm.

The LLVM IR of:

```
pub extern "C" fn foo(ptr: Option<::std::ptr::NonNull<i32>>) {}
```

is:

```
define void @foo(i32*) unnamed_addr #0 !dbg !310 {
start:
  %ptr = alloca i32*, align 8
	store i32* %0, i32** %ptr, align 8
	call void @llvm.dbg.declare(metadata i32** %ptr, metadata !327, metadata
	!DIExpression()), !dbg !328
	ret void, !dbg !329
}
```

Which is the same as for:

```
pub extern "C" fn foo(ptr: ::std::ptr::NonNull<i32>) {}
```

Except without the nonnull annotation.

And the same as for:

```
pub extern "C" fn foo(ptr: *mut i32) {}
```
2018-10-17 09:24:22 -05:00
Ryan Hunt 2d65f8f10b Release 0.6.5 2018-10-16 16:45:04 -05:00
Ryan Hunt a4f4d0bf95 Update README.md to reference cbindgen::generate()
Fixes issue #218
2018-10-16 16:24:22 -05:00
Emilio Cobos Álvarez 43f6f7108e Add support for generic enums.
Going to need this if I ever aim to generate TransformOperation bindings and
remove a bunch of slow and ugly Gecko code:

  https://searchfox.org/mozilla-central/rev/80ac71c1c54af788b32e851192dfd2de2ec18e18/servo/components/style/values/generics/transform.rs#189

With the caveat that I'll need to remove the options, but I can manage to do
that.

This also fixes a bunch of renaming bugs that I found while at it.

This patch has the gotcha that we need to remove the assertion of no-underscores
in mangled names... But I think it should be fine, and I'd rather not do a more
breaking change.

You can generate conflicting names in C using enum variants with the same name
as a struct regardless, for example, so I don't think this is terribly
important.
2018-10-16 16:19:06 -05:00
Mrmaxmeier 161d83c0b1 add lifetime_arg test 2018-10-16 15:50:23 -05:00
Mrmaxmeier 4162173a76 allow lifetimes in generic args 2018-10-16 15:50:23 -05:00
Sylvestre Ledru 5c6da04883 Ship the tests too
Packagers would like to have access to the test suite to make sure they don't regress
2018-10-15 22:22:19 -05:00
Ryan Hunt e5cd04aff3 Release 0.6.4 2018-10-04 13:53:10 -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
Ryan Hunt 961ed1dd93 Update issue number for serde_derive pinning workaround 2018-10-01 16:51:15 -05:00
Josh Stone de6c08c057 Bump to serde_derive 1.0.58
This will in turn build with `syn 0.13` and `quote 0.5`, which is still
distinct from cbindgen's own dependencies, so it won't get "infected" by
the proc-macro feature.
2018-10-01 16:49:06 -05:00
Rahul Gurung ad33aae017 added installation 2018-10-01 16:38:47 -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
Ryan Hunt 545f81e01b Release 0.6.3 2018-08-28 18:28:43 -05:00
Vincent Esche 5e6d58dfe3 Added support for #[repr(transparent)] 2018-08-28 16:35:04 -05:00
Vincent Esche 090b8154dd Implemented detection/omission of #[cfg(test)] and #[test] items 2018-08-28 16:11:23 -05:00
kpcyrd 67370efbcf Bump log dependency 2018-08-28 16:06:45 -05:00
kpcyrd a22c9a9798 Replace deprecated tempdir with tempfile 2018-08-28 16:06:45 -05:00
Ryan Hunt 101e025e49 Release 0.6.2 2018-08-21 17:11:37 -05:00
Emilio Cobos Álvarez a156a913cf Point to a solution when we hit a parse error.
When I hit this, I initially started bisecting my changes to see where the error
was.

It'd be much nicer if somebody had told me that `rustc -Z parse-only` existed.
2018-08-17 23:16:47 -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 7109cdd872 Rustfmt. 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 b627b8f6da Rustfmt 2018-08-14 00:47:35 -05:00
Vincent Esche b07046d28a Fixed missing prefix for named consts in [T; <Const>] types 2018-08-14 00:47:35 -05:00
Vincent Esche 6df2fcb316 Added [defines] to sample ‘cbindgen.toml’ file in ‘README.md’ 2018-08-14 00:32:28 -05:00
Emilio Cobos Álvarez 8b4a271714 Provide a better error when parsing a module fails.
I was hitting this today :)
2018-08-14 00:30:47 -05:00
Basile Clement dc558ecf2c Rustfmt 2018-07-31 08:31:43 -05:00
Basile Clement 7a88f0b6a6 Fix typos in the README 2018-07-31 08:31:43 -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
Ryan Hunt fb49cc60a1 Update contributing documentation 2018-07-30 23:40:19 -05:00
Ryan Hunt 5fb8d16db1 Rustfmt. 2018-07-30 22:47:48 -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
Boncheol Gu 2f9d3cd499 Add Builder.with_lockfile 2018-07-30 21:52:52 -05:00
Ryan Hunt c2aae5b07f Release 0.6.1 2018-07-25 14:09:01 -05:00
Emilio Cobos Álvarez 5620de7756 Rustfmt. 2018-07-25 13:54:10 -05:00