Gen bindings with rustc --pretty=expanded instead of reading files
authorMatt Corallo <git@bluematt.me>
Sun, 7 Feb 2021 05:58:36 +0000 (00:58 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 11 Feb 2021 18:23:02 +0000 (13:23 -0500)
commit2462e4306349623c9165ed0d36d7e9cd9115cfcb
tree358639c252b93ee66385f51837e21fdee20ec7ff
parent82cf71199dcbd866177f5e91abb852cdc1d221e8
Gen bindings with rustc --pretty=expanded instead of reading files

Instead of walking individual rust files and reading the AST from
those, we instead call
`RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded`
and let it create one giant lib.rs which we can parse as a whole.
This allows us to parse a post-macro crate, working with structs
and functions created inside macros just fine. It does require
handling a few things that we didn't previously, most notably Clone
via `impl ::core::clone::Clone` blocks instead of just looking for
`#![derive(Clone)]`.

This ends up resolving a few types slightly differently, resulting
in different bindings, but only in ways which don't impact the
runtime.
c-bindings-gen/Cargo.toml
c-bindings-gen/src/main.rs
c-bindings-gen/src/types.rs
genbindings.sh