Add an option to output a depfile for outside build-systems to learn
the source file dependencies of the bindings.
This can be used by 3rd party build system integrations to only rerun
bindgen when necessary.
Testing is done via CMake integration tests, since CMake
is a 3rd party buildsystem which supports depfiles.
Since our MSRV is now Rust 1.54, we can rely on cargo setting `CARGO_BIN_EXE_cbindgen`
to the cbindgen path in integration tests.
This is more reliable than guessing the path, since cargo knows where it placed the bin.
Following the example of `.skip_warning_as_error`, this patch
introduces a `.skip_cpp` suffix to skip the generation of `.cpp`
files.
This patch also simplifies the code. Ideally, we would create and
implement a new trait offering an API like `is_cpp_skipped`,
`is_warning_as_error_skipped`, and `normalize` (to remove all
suffixes), but it's a little bit overkill for our needs right now.
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.
This will be useful to add static assertion to some tests like #463 wants to do.
For example, in the case of the test for #463, the test would need something
like:
trailer = """
#include <assert.h>
#if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
static_assert(sizeof(struct P) == 4, "unexpected size for P");
#else
static_assert(sizeof(P) == 4, "unexpected size for P");
#endif
"""
As more of these tests are added it may be worth just adding a helper header
like this to avoid some duplication:
#include <assert.h>
#if defined(CBINDGEN_STYLE_TAG) && !defined(__cplusplus)
#define CBINDGEN_STRUCT(name) struct name
#else
#define CBINDGEN_STRUCT(name) name
#endif
And so on, so the previous configuration would become just:
trailer = """
#include "testing-helpers.h" // Or whatever
static_assert(sizeof(CBINDGEN_STRUCT(P)) == 4, "unexpected size for P");
"""
That may or may not be overkill to do as part of #463.
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.