summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--CONTRIBUTING.md9
-rw-r--r--Cargo.lock479
-rw-r--r--Cargo.toml13
-rw-r--r--README.md19
-rw-r--r--bindgen-integration/build.rs2
-rw-r--r--bindgen-integration/cpp/Test.h6
-rw-r--r--src/codegen/mod.rs126
-rw-r--r--src/ir/comp.rs4
-rw-r--r--src/ir/function.rs8
-rw-r--r--src/ir/item.rs9
-rw-r--r--src/ir/ty.rs23
-rw-r--r--src/lib.rs43
-rw-r--r--src/options.rs21
-rw-r--r--tests/expectations/tests/16-byte-alignment.rs (renamed from libbindgen/tests/expectations/tests/16-byte-alignment.rs)0
-rw-r--r--tests/expectations/tests/bitfield-enum-basic.rs8
-rw-r--r--tests/expectations/tests/bitfield_method_mangling.rs2
-rw-r--r--tests/expectations/tests/constify-all-enums.rs23
-rw-r--r--tests/expectations/tests/inherit_typedef.rs2
-rw-r--r--tests/expectations/tests/issue-410.rs41
-rw-r--r--tests/expectations/tests/no-derive-debug.rs26
-rw-r--r--tests/expectations/tests/reparented_replacement.rs2
-rw-r--r--tests/expectations/tests/template.rs14
-rw-r--r--tests/expectations/tests/union_fields.rs2
-rw-r--r--tests/expectations/tests/unknown_attr.rs2
-rw-r--r--tests/headers/16-byte-alignment.h (renamed from libbindgen/tests/headers/16-byte-alignment.h)0
-rw-r--r--tests/headers/constify-all-enums.h11
-rw-r--r--tests/headers/issue-410.hpp12
-rw-r--r--tests/headers/no-derive-debug.h15
29 files changed, 839 insertions, 86 deletions
diff --git a/.gitignore b/.gitignore
index 049fbc4a..e9421ffc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
# Cargo
target/
-Cargo.lock
*~
+./bindgen-integration/Cargo.lock
+./tests/expectations/Cargo.lock
#*#
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index d30df68d..cfcee653 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -42,19 +42,12 @@ issue, provide us with:
## Building
-To build `bindgen`:
+To build the `bindgen` library and the `bindgen` executable:
```
$ cargo build
```
-To build the `bindgen` executable:
-
-```
-$ cd bindgen/bindgen
-$ cargo build
-```
-
If you installed multiple versions of llvm, it may not be able to locate the
latest version of libclang. In that case, you may want to either uninstall other
versions of llvm, or specify the path of the desired libclang explicitly:
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 00000000..4624cf51
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,479 @@
+[root]
+name = "bindgen"
+version = "0.20.2"
+dependencies = [
+ "aster 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clang-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quasi 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quasi_codegen 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "aho-corasick"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "ansi_term"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "aster"
+version = "0.38.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bitflags"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cexpr"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cfg-if"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "clang-sys"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "clap"
+version = "2.19.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-segmentation 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "diff"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "dtoa"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "env_logger"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "glob"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "itoa"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "kernel32-sys"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "lazy_static"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libc"
+version = "0.2.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "libloading"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "log"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "memchr"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "nom"
+version = "1.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "num-traits"
+version = "0.1.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "phf"
+version = "0.7.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "phf_codegen"
+version = "0.7.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "phf_generator"
+version = "0.7.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.7.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quasi"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_errors 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quasi_codegen"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "aster 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_errors 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand"
+version = "0.3.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "regex"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "aho-corasick 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "thread_local 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rustc-serialize"
+version = "0.3.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde"
+version = "0.8.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde_json"
+version = "0.8.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "shlex"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "siphasher"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "strsim"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "syntex"
+version = "0.54.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "syntex_errors 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syntex_errors"
+version = "0.54.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_pos 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syntex_pos"
+version = "0.54.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syntex_syntax"
+version = "0.54.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_errors 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syntex_pos 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "target_build_utils"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "term"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "term_size"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "thread-id"
+version = "3.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "thread_local"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unicode-width"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unicode-xid"
+version = "0.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "unreachable"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "utf8-ranges"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "vec_map"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "void"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-build"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum aho-corasick 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f660b942762979b56c9f07b4b36bb559776fbad102f05d6771e1b629e8fd5bf"
+"checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6"
+"checksum aster 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c9b49e42a449c0b79d8acb91db37621de0978064dca7d3288ddcf030123e5b3"
+"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
+"checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d"
+"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
+"checksum clang-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "822ea22bbbef9f5934e9477860545fb0311a1759e43a276de42e2856c605aa2b"
+"checksum clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95b78f3fe0fc94c13c731714363260e04b557a637166f33a4570d3189d642374"
+"checksum diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e48977eec6d3b7707462c2dc2e1363ad91b5dd822cf942537ccdc2085dc87587"
+"checksum dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0dd841b58510c9618291ffa448da2e4e0f699d984d436122372f446dae62263d"
+"checksum env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99971fb1b635fe7a0ee3c4d065845bb93cca80a23b5613b5613391ece5de4144"
+"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
+"checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1"
+"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
+"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
+"checksum libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "84816a8c6ed8163dfe0dbdd2b09d35c6723270ea77a4c7afa4bedf038a36cb99"
+"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
+"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
+"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
+"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
+"checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc"
+"checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f"
+"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03"
+"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2"
+"checksum quasi 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcbf815446dc6a0afbc72d88f9a8aa71b608d10b168e09437c80c0fd6fd410c9"
+"checksum quasi_codegen 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b06172e92ab0099427609854ffb1512c377be5fc4beaf572ae5d5a01b8359596"
+"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
+"checksum regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4278c17d0f6d62dfef0ab00028feb45bd7d2102843f80763474eeb1be8a10c01"
+"checksum regex-syntax 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9191b1f57603095f105d317e375d19b1c9c5c3185ea9633a99a6dcbed04457"
+"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
+"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
+"checksum serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "67f7d2e9edc3523a9c8ec8cd6ec481b3a27810aafee3e625d311febd3e656b4c"
+"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
+"checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84"
+"checksum strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "67f84c44fbb2f91db7fef94554e6b2ac05909c9c0b0bc23bb98d3a1aebfe7f7c"
+"checksum syntex 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb3f52553a966675982404dc34028291b347e0c9a9c0b0b34f2da6be8a0443f8"
+"checksum syntex_errors 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dee2f6e49c075f71332bb775219d5982bee6732d26227fa1ae1b53cdb12f5cc5"
+"checksum syntex_pos 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df3921c7945dfb9ffc53aa35adb2cf4313b5ab5f079c3619b3d4eb82a0efc2b"
+"checksum syntex_syntax 0.54.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc960085bae44591e22d01f6c0e82a8aec832f8659aca556cdf8ecbdac2bb47b"
+"checksum target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54c550e226618cd35334b75e92bfa5437c61474bdb75c38bf330ab5a8037b77c"
+"checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a"
+"checksum term_size 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7f5f3f71b0040cecc71af239414c23fd3c73570f5ff54cf50e03cef637f2a0"
+"checksum thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437c97558c70d129e40629a5b385b3fb1ffac301e63941335e4d354081ec14a"
+"checksum thread_local 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7793b722f0f77ce716e7f1acf416359ca32ff24d04ffbac4269f44a4a83be05d"
+"checksum unicode-segmentation 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3bc443ded17b11305ffffe6b37e2076f328a5a8cb6aa877b1b98f77699e98b5"
+"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
+"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
+"checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91"
+"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
+"checksum vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac5efe5cb0fa14ec2f84f83c701c562ee63f6dcc680861b21d65c682adfb05f"
+"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
diff --git a/Cargo.toml b/Cargo.toml
index 2187a196..19695919 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,18 +2,23 @@
authors = [
"Jyun-Yan You <jyyou.tw@gmail.com>",
"Emilio Cobos Álvarez <emilio@crisal.io>",
+ "Nick Fitzgerald <fitzgen@gmail.com>",
"The Servo project developers",
]
-description = "A binding generator for Rust"
-homepage = "https://github.com/servo/rust-bindgen"
+description = "Automatically generates Rust FFI bindings to C and C++ libraries."
keywords = ["bindings", "ffi", "code-generation"]
+categories = ["external-ffi-bindings", "development-tools::ffi"]
license = "BSD-3-Clause"
name = "bindgen"
readme = "README.md"
repository = "https://github.com/servo/rust-bindgen"
-version = "0.20.0"
+documentation = "https://docs.rs/bindgen"
+version = "0.20.2"
build = "build.rs"
+[badges]
+travis-ci = { repository = "servo/rust-bindgen" }
+
[lib]
path = "src/lib.rs"
@@ -27,7 +32,7 @@ clap = "2"
shlex = "0.1"
[build-dependencies]
-quasi_codegen = "0.26"
+quasi_codegen = "0.29"
[dependencies]
cexpr = "0.2"
diff --git a/README.md b/README.md
index 2f36d115..f0104fc9 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,6 @@ Automatically generates Rust FFI bindings to C and C++ libraries.
- [`hide`](#hide)
- [`replaces`](#replaces)
- [`nocopy`](#nocopy)
-- [Building From Source](#building-from-source)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -88,6 +87,8 @@ Those instructions list optional steps. For bindgen:
### Library usage with `build.rs`
+💡 This is the recommended way to use `bindgen`. 💡
+
#### `build.rs` Tutorial
[Here is a step-by-step tutorial for generating FFI bindings to the `bzip2` C library.][tutorial]
@@ -154,11 +155,23 @@ There are a few options documented when running `./bindgen --help`.
### C++
-This fork of rust-bindgen can handle a number of C++ features.
+`bindgen` can handle most C++ features, but not all of them (C++ is hard!)
+
+Notable C++ features that are unsupported or only partially supported:
+
+* Partial template specialization
+* Traits templates
+* SFINAE
+* Instantiating new template specializations
When passing in header files, the file will automatically be treated as C++ if
it ends in ``.hpp``. If it doesn't, ``-x c++`` can be used to force C++ mode.
+You must use whitelisting when working with C++ to avoid pulling in all of the
+`std::*` types, some of which `bindgen` cannot handle. Additionally, you may
+want to blacklist other types that `bindgen` stumbles on, or make `bindgen`
+treat certain types as opaque.
+
### Annotations
The translation of classes, structs, enums, and typedefs can be adjusted using
@@ -179,7 +192,7 @@ a struct/class.
The `hide` annotation instructs bindgen to ignore the struct/class/field/enum
completely.
-```
+```cpp
/// <div rustbindgen hide></div>
```
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 2c18c94a..9b157c5a 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -13,6 +13,8 @@ fn main() {
let bindings = Builder::default()
.no_unstable_rust()
+ .enable_cxx_namespaces()
+ .raw_line("pub use self::root::*;")
.header("cpp/Test.h")
.clang_arg("-x")
.clang_arg("c++")
diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h
index ebd58649..f1e38c40 100644
--- a/bindgen-integration/cpp/Test.h
+++ b/bindgen-integration/cpp/Test.h
@@ -9,4 +9,10 @@ public:
Test(double foo);
};
+namespace testing {
+
typedef Test TypeAlias;
+
+} // namespace testing
+
+typedef testing::TypeAlias TypeAlias;
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 0cc5a637..c92e95fa 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -23,7 +23,6 @@ use std::cell::Cell;
use std::collections::{HashSet, VecDeque};
use std::collections::hash_map::{Entry, HashMap};
use std::fmt::Write;
-use std::iter;
use std::mem;
use std::ops;
use syntax::abi::Abi;
@@ -31,23 +30,39 @@ use syntax::ast;
use syntax::codemap::{Span, respan};
use syntax::ptr::P;
+fn root_import_depth(ctx: &BindgenContext, item: &Item) -> usize {
+ if !ctx.options().enable_cxx_namespaces {
+ return 0;
+ }
+
+ item.ancestors(ctx)
+ .filter(|id| ctx.resolve_item(*id).is_module())
+ .fold(1, |i, _| i + 1)
+}
+
+fn top_level_path(ctx: &BindgenContext, item: &Item) -> Vec<ast::Ident> {
+ let mut path = vec![ctx.rust_ident_raw("self")];
+
+ if ctx.options().enable_cxx_namespaces {
+ let super_ = ctx.rust_ident_raw("super");
+
+ for _ in 0..root_import_depth(ctx, item) {
+ path.push(super_.clone());
+ }
+ }
+
+ path
+}
+
fn root_import(ctx: &BindgenContext, module: &Item) -> P<ast::Item> {
assert!(ctx.options().enable_cxx_namespaces, "Somebody messed it up");
assert!(module.is_module());
+ let mut path = top_level_path(ctx, module);
+
let root = ctx.root_module().canonical_name(ctx);
let root_ident = ctx.rust_ident(&root);
-
- let super_ = aster::AstBuilder::new().id("super");
- let supers = module.ancestors(ctx)
- .filter(|id| ctx.resolve_item(*id).is_module())
- .map(|_| super_.clone())
- .chain(iter::once(super_));
-
- let self_ = iter::once(aster::AstBuilder::new().id("self"));
- let root_ident = iter::once(root_ident);
-
- let path = self_.chain(supers).chain(root_ident);
+ path.push(root_ident);
let use_root = aster::AstBuilder::new()
.item()
@@ -528,7 +543,7 @@ impl CodeGenerator for Type {
let simple_enum_path = match inner_rust_type.node {
ast::TyKind::Path(None, ref p) => {
if applicable_template_args.is_empty() &&
- !inner_item.expect_type().canonical_type(ctx).is_builtin_or_named() &&
+ inner_item.expect_type().canonical_type(ctx).is_enum() &&
p.segments.iter().all(|p| p.parameters.is_none()) {
Some(p.clone())
} else {
@@ -539,9 +554,9 @@ impl CodeGenerator for Type {
};
let typedef = if let Some(mut p) = simple_enum_path {
- if p.segments.len() == 1 {
+ for ident in top_level_path(ctx, item).into_iter().rev() {
p.segments.insert(0, ast::PathSegment {
- identifier: ctx.ext_cx().ident_of("self"),
+ identifier: ident,
parameters: None,
});
}
@@ -1478,6 +1493,7 @@ enum EnumBuilder<'a> {
canonical_name: &'a str,
aster: P<ast::Item>,
},
+ Consts { aster: P<ast::Item>, }
}
impl<'a> EnumBuilder<'a> {
@@ -1485,21 +1501,25 @@ impl<'a> EnumBuilder<'a> {
/// the representation, and whether it should be represented as a rust enum.
fn new(aster: aster::item::ItemBuilder<aster::invoke::Identity>,
name: &'a str,
- repr_name: &str,
- is_rust: bool)
+ repr: P<ast::Ty>,
+ bitfield_like: bool,
+ constify: bool)
-> Self {
- if is_rust {
- EnumBuilder::Rust(aster.enum_(name))
- } else {
+ if bitfield_like {
EnumBuilder::Bitfield {
canonical_name: name,
aster: aster.tuple_struct(name)
.field()
.pub_()
- .ty()
- .id(repr_name)
+ .build_ty(repr)
.build(),
}
+ } else if constify {
+ EnumBuilder::Consts {
+ aster: aster.type_(name).build_ty(repr),
+ }
+ } else {
+ EnumBuilder::Rust(aster.enum_(name))
}
}
@@ -1549,6 +1569,25 @@ impl<'a> EnumBuilder<'a> {
result.push(constant);
self
}
+ EnumBuilder::Consts { .. } => {
+ let constant_name = match mangling_prefix {
+ Some(prefix) => {
+ Cow::Owned(format!("{}_{}", prefix, variant_name))
+ }
+ None => variant_name,
+ };
+
+ let constant = aster::AstBuilder::new()
+ .item()
+ .pub_()
+ .const_(&*constant_name)
+ .expr()
+ .build(expr)
+ .build(rust_ty);
+
+ result.push(constant);
+ self
+ }
}
}
@@ -1578,6 +1617,7 @@ impl<'a> EnumBuilder<'a> {
result.push(impl_);
aster
}
+ EnumBuilder::Consts { aster, .. } => aster,
}
}
}
@@ -1633,6 +1673,8 @@ impl CodeGenerator for Enum {
let mut builder = aster::AstBuilder::new().item().pub_();
+ // FIXME(emilio): These should probably use the path so it can
+ // disambiguate between namespaces, just like is_opaque etc.
let is_bitfield = {
ctx.options().bitfield_enums.matches(&name) ||
(enum_ty.name().is_none() &&
@@ -1641,15 +1683,25 @@ impl CodeGenerator for Enum {
.any(|v| ctx.options().bitfield_enums.matches(&v.name())))
};
- let is_rust_enum = !is_bitfield;
+ let is_constified_enum = {
+ ctx.options().constified_enums.matches(&name) ||
+ (enum_ty.name().is_none() &&
+ self.variants()
+ .iter()
+ .any(|v| ctx.options().constified_enums.matches(&v.name())))
+ };
+
+ let is_rust_enum = !is_bitfield && !is_constified_enum;
// FIXME: Rust forbids repr with empty enums. Remove this condition when
// this is allowed.
+ //
+ // TODO(emilio): Delegate this to the builders?
if is_rust_enum {
if !self.variants().is_empty() {
builder = builder.with_attr(attributes::repr(repr_name));
}
- } else {
+ } else if is_bitfield {
builder = builder.with_attr(attributes::repr("C"));
}
@@ -1657,14 +1709,16 @@ impl CodeGenerator for Enum {
builder = builder.with_attr(attributes::doc(comment));
}
- let derives = attributes::derives(&["Debug",
- "Copy",
- "Clone",
- "PartialEq",
- "Eq",
- "Hash"]);
+ if !is_constified_enum {
+ let derives = attributes::derives(&["Debug",
+ "Copy",
+ "Clone",
+ "PartialEq",
+ "Eq",
+ "Hash"]);
- builder = builder.with_attr(derives);
+ builder = builder.with_attr(derives);
+ }
fn add_constant<'a>(enum_: &Type,
// Only to avoid recomputing every time.
@@ -1694,8 +1748,16 @@ impl CodeGenerator for Enum {
result.push(constant);
}
+ let repr = self.repr()
+ .map(|repr| repr.to_rust_ty(ctx))
+ .unwrap_or_else(|| helpers::ast_ty::raw_type(ctx, repr_name));
+
let mut builder =
- EnumBuilder::new(builder, &name, repr_name, is_rust_enum);
+ EnumBuilder::new(builder,
+ &name,
+ repr,
+ is_bitfield,
+ is_constified_enum);
// A map where we keep a value -> variant relation.
let mut seen_values = HashMap::<_, String>::new();
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index ada6c064..4eea1d7a 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -975,6 +975,8 @@ impl TypeCollector for CompInfo {
types.insert(var);
}
- // FIXME(emilio): Methods, VTable?
+ for method in self.methods() {
+ types.insert(method.signature);
+ }
}
}
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 50c442db..6e205f1b 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -165,8 +165,7 @@ impl FunctionSig {
let name = arg.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
- let ty = Item::from_ty(&arg_ty, Some(*arg), None, ctx)
- .expect("Argument?");
+ let ty = Item::from_ty_or_ref(arg_ty, Some(*arg), None, ctx);
(name, ty)
})
.collect()
@@ -178,8 +177,7 @@ impl FunctionSig {
cursor.visit(|c| {
if c.kind() == CXCursor_ParmDecl {
let ty =
- Item::from_ty(&c.cur_type(), Some(c), None, ctx)
- .expect("ParmDecl?");
+ Item::from_ty_or_ref(c.cur_type(), Some(c), None, ctx);
let name = c.spelling();
let name =
if name.is_empty() { None } else { Some(name) };
@@ -218,7 +216,7 @@ impl FunctionSig {
}
let ty_ret_type = try!(ty.ret_type().ok_or(ParseError::Continue));
- let ret = try!(Item::from_ty(&ty_ret_type, None, None, ctx));
+ let ret = Item::from_ty_or_ref(ty_ret_type, None, None, ctx);
let abi = get_abi(ty.call_conv());
Ok(Self::new(ret, args, ty.is_variadic(), abi))
diff --git a/src/ir/item.rs b/src/ir/item.rs
index df8fd222..7b18b331 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -205,7 +205,12 @@ impl TypeCollector for Item {
ItemKind::Var(ref var) => {
types.insert(var.ty());
}
- _ => {} // FIXME.
+ ItemKind::Module(_) => {
+ // Module -> children edges are "weak", and we do not want to
+ // trace them. If we did, then whitelisting wouldn't work as
+ // expected: everything in every module would end up
+ // whitelisted.
+ }
}
}
}
@@ -214,7 +219,7 @@ impl CanDeriveDebug for Item {
type Extra = ();
fn can_derive_debug(&self, ctx: &BindgenContext, _: ()) -> bool {
- match self.kind {
+ ctx.options().derive_debug && match self.kind {
ItemKind::Type(ref ty) => {
if self.is_opaque(ctx) {
ty.layout(ctx)
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index c1ed5b64..1e87beb4 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -914,13 +914,24 @@ impl TypeCollector for Type {
TypeKind::Function(ref sig) => {
sig.collect_types(context, types, item)
}
- TypeKind::Named(_) => {}
- // FIXME: Pending types!
- ref other @ _ => {
- debug!("<Type as TypeCollector>::collect_types: Ignoring: \
- {:?}",
- other);
+ TypeKind::Enum(ref en) => {
+ if let Some(repr) = en.repr() {
+ types.insert(repr);
+ }
+ }
+ TypeKind::UnresolvedTypeRef(_, _, Some(id)) => {
+ types.insert(id);
}
+
+ // None of these variants have edges to other items and types.
+ TypeKind::UnresolvedTypeRef(_, _, None) |
+ TypeKind::Named(_) |
+ TypeKind::Void |
+ TypeKind::NullPtr |
+ TypeKind::Int(_) |
+ TypeKind::Float(_) |
+ TypeKind::Complex(_) |
+ TypeKind::BlockPointer => {}
}
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 60b750de..5052bb56 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -182,48 +182,64 @@ impl Builder {
self
}
- /// Hide the given type from the generated bindings.
+ /// Hide the given type from the generated bindings. Regular expressions are
+ /// supported.
pub fn hide_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.hidden_types.insert(arg);
self
}
- /// Treat the given type as opaque in the generated bindings.
+ /// Treat the given type as opaque in the generated bindings. Regular
+ /// expressions are supported.
pub fn opaque_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.opaque_types.insert(arg);
self
}
/// Whitelist the given type so that it (and all types that it transitively
- /// refers to) appears in the generated bindings.
+ /// refers to) appears in the generated bindings. Regular expressions are
+ /// supported.
pub fn whitelisted_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.whitelisted_types.insert(arg);
self
}
/// Whitelist the given function so that it (and all types that it
- /// transitively refers to) appears in the generated bindings.
+ /// transitively refers to) appears in the generated bindings. Regular
+ /// expressions are supported.
pub fn whitelisted_function<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.whitelisted_functions.insert(arg);
self
}
/// Whitelist the given variable so that it (and all types that it
- /// transitively refers to) appears in the generated bindings.
+ /// transitively refers to) appears in the generated bindings. Regular
+ /// expressions are supported.
pub fn whitelisted_var<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.whitelisted_vars.insert(arg);
self
}
/// Mark the given enum (or set of enums, if using a pattern) as being
- /// bitfield-like.
+ /// bitfield-like. Regular expressions are supported.
///
- /// This makes bindgen generate a type that isn't a rust `enum`.
+ /// This makes bindgen generate a type that isn't a rust `enum`. Regular
+ /// expressions are supported.
pub fn bitfield_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.bitfield_enums.insert(arg);
self
}
+ /// Mark the given enum (or set of enums, if using a pattern) as being
+ /// constant.
+ ///
+ /// This makes bindgen generate constants instead of enums. Regular
+ /// expressions are supported.
+ pub fn constified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
+ self.options.constified_enums.insert(arg);
+ self
+ }
+
/// Add a string to prepend to the generated bindings. The string is passed
/// through without any modification.
pub fn raw_line<T: Into<String>>(mut self, arg: T) -> Builder {
@@ -268,6 +284,12 @@ impl Builder {
self
}
+ /// Set whether `Debug` should be derived by default.
+ pub fn derive_debug(mut self, doit: bool) -> Self {
+ self.options.derive_debug = doit;
+ self
+ }
+
/// Emit Clang AST.
pub fn emit_clang_ast(mut self) -> Builder {
self.options.emit_ast = true;
@@ -350,7 +372,7 @@ impl Builder {
self
}
- /// Avoid generating any unstable Rust in the generated bindings.
+ /// Avoid generating any unstable Rust, such as Rust unions, in the generated bindings.
pub fn no_unstable_rust(mut self) -> Builder {
self.options.unstable_rust = false;
self
@@ -418,6 +440,9 @@ pub struct BindgenOptions {
/// The enum patterns to mark an enum as bitfield.
pub bitfield_enums: RegexSet,
+ /// The enum patterns to mark an enum as constant.
+ pub constified_enums: RegexSet,
+
/// Whether we should generate builtins or not.
pub builtins: bool,
@@ -496,6 +521,7 @@ impl BindgenOptions {
self.hidden_types.build();
self.opaque_types.build();
self.bitfield_enums.build();
+ self.constified_enums.build();
}
}
@@ -508,6 +534,7 @@ impl Default for BindgenOptions {
whitelisted_functions: Default::default(),
whitelisted_vars: Default::default(),
bitfield_enums: Default::default(),
+ constified_enums: Default::default(),
builtins: false,
links: vec![],
emit_ast: false,
diff --git a/src/options.rs b/src/options.rs
index 3456bfea..fa69ecba 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -24,6 +24,14 @@ pub fn builder_from_flags<I>(args: I)
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("constified-enum")
+ .long("constified-enum")
+ .help("Mark any enum whose name matches <regex> as a set of \
+ constants instead of an enumeration.")
+ .value_name("regex")
+ .takes_value(true)
+ .multiple(true)
+ .number_of_values(1),
Arg::with_name("blacklist-type")
.long("blacklist-type")
.help("Mark a type as hidden.")
@@ -31,6 +39,9 @@ pub fn builder_from_flags<I>(args: I)
.takes_value(true)
.multiple(true)
.number_of_values(1),
+ Arg::with_name("no-derive-debug")
+ .long("no-derive-debug")
+ .help("Avoid deriving Debug on any type."),
Arg::with_name("builtins")
.long("builtins")
.help("Output bindings for builtin definitions, e.g. \
@@ -171,6 +182,12 @@ pub fn builder_from_flags<I>(args: I)
}
}
+ if let Some(bitfields) = matches.values_of("constified-enum") {
+ for regex in bitfields {
+ builder = builder.constified_enum(regex);
+ }
+ }
+
if let Some(hidden_types) = matches.values_of("blacklist-type") {
for ty in hidden_types {
builder = builder.hide_type(ty);
@@ -181,6 +198,10 @@ pub fn builder_from_flags<I>(args: I)
builder = builder.emit_builtins();
}
+ if matches.is_present("no-derive-debug") {
+ builder = builder.derive_debug(false);
+ }
+
if let Some(prefix) = matches.value_of("ctypes-prefix") {
builder = builder.ctypes_prefix(prefix);
}
diff --git a/libbindgen/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs
index b28c0537..b28c0537 100644
--- a/libbindgen/tests/expectations/tests/16-byte-alignment.rs
+++ b/tests/expectations/tests/16-byte-alignment.rs
diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs
index 03e07de6..7674af8b 100644
--- a/tests/expectations/tests/bitfield-enum-basic.rs
+++ b/tests/expectations/tests/bitfield-enum-basic.rs
@@ -18,7 +18,7 @@ impl ::std::ops::BitOr<Foo> for Foo {
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Foo(pub i32);
+pub struct Foo(pub ::std::os::raw::c_int);
pub const Buz_Bar: Buz = Buz(2);
pub const Buz_Baz: Buz = Buz(4);
pub const Buz_Duplicated: Buz = Buz(4);
@@ -33,7 +33,7 @@ impl ::std::ops::BitOr<Buz> for Buz {
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Buz(pub i8);
+pub struct Buz(pub ::std::os::raw::c_char);
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
@@ -46,7 +46,7 @@ impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct _bindgen_ty_1(pub u32);
+pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Dummy {
@@ -66,7 +66,7 @@ impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Dummy__bindgen_ty_1(pub u32);
+pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint);
#[test]
fn bindgen_test_layout_Dummy() {
assert_eq!(::std::mem::size_of::<Dummy>() , 1usize);
diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs
index b650a38f..5aba8abb 100644
--- a/tests/expectations/tests/bitfield_method_mangling.rs
+++ b/tests/expectations/tests/bitfield_method_mangling.rs
@@ -46,4 +46,4 @@ impl _bindgen_ty_1 {
((val as u32 as u32) << 24u32) & (4278190080usize as u32);
}
}
-pub use self::_bindgen_ty_1 as mach_msg_type_descriptor_t;
+pub type mach_msg_type_descriptor_t = _bindgen_ty_1;
diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs
new file mode 100644
index 00000000..a676bb10
--- /dev/null
+++ b/tests/expectations/tests/constify-all-enums.rs
@@ -0,0 +1,23 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+pub const foo_THIS: foo = 0;
+pub const foo_SHOULD_BE: foo = 1;
+pub const foo_A_CONSTANT: foo = 2;
+pub type foo = ::std::os::raw::c_uint;
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct bar {
+ pub this_should_work: foo,
+}
+#[test]
+fn bindgen_test_layout_bar() {
+ assert_eq!(::std::mem::size_of::<bar>() , 4usize);
+ assert_eq!(::std::mem::align_of::<bar>() , 4usize);
+}
+impl Clone for bar {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs
index 2b974223..ca9041e2 100644
--- a/tests/expectations/tests/inherit_typedef.rs
+++ b/tests/expectations/tests/inherit_typedef.rs
@@ -17,7 +17,7 @@ fn bindgen_test_layout_Foo() {
impl Clone for Foo {
fn clone(&self) -> Self { *self }
}
-pub use self::Foo as TypedefedFoo;
+pub type TypedefedFoo = Foo;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Bar {
diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs
new file mode 100644
index 00000000..0c91e2b7
--- /dev/null
+++ b/tests/expectations/tests/issue-410.rs
@@ -0,0 +1,41 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+pub mod root {
+ #[allow(unused_imports)]
+ use self::super::root;
+ pub mod JS {
+ #[allow(unused_imports)]
+ use self::super::super::root;
+ #[repr(C)]
+ #[derive(Debug, Copy)]
+ pub struct Value {
+ pub _address: u8,
+ }
+ #[test]
+ fn bindgen_test_layout_Value() {
+ assert_eq!(::std::mem::size_of::<Value>() , 1usize);
+ assert_eq!(::std::mem::align_of::<Value>() , 1usize);
+ }
+ extern "C" {
+ #[link_name = "_ZN2JS5Value1aE10JSWhyMagic"]
+ pub fn Value_a(this: *mut root::JS::Value,
+ arg1: root::JSWhyMagic);
+ }
+ impl Clone for Value {
+ fn clone(&self) -> Self { *self }
+ }
+ impl Value {
+ #[inline]
+ pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) {
+ Value_a(&mut *self, arg1)
+ }
+ }
+ }
+ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+ pub enum _bindgen_ty_1 { }
+ pub use self::super::root::_bindgen_ty_1 as JSWhyMagic;
+}
diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs
new file mode 100644
index 00000000..e45b2678
--- /dev/null
+++ b/tests/expectations/tests/no-derive-debug.rs
@@ -0,0 +1,26 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }
+
+/**
+ * bar should compile. It will normally derive debug, but our blacklist of foo
+ * and replacement for another type that doesn't implement it would prevent it
+ * from building if --no-derive-debug didn't work.
+ */
+#[repr(C)]
+#[derive(Copy)]
+pub struct bar {
+ pub foo: foo,
+ pub baz: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_bar() {
+ assert_eq!(::std::mem::size_of::<bar>() , 8usize);
+ assert_eq!(::std::mem::align_of::<bar>() , 4usize);
+}
+impl Clone for bar {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs
index e8ccc931..74ee229c 100644
--- a/tests/expectations/tests/reparented_replacement.rs
+++ b/tests/expectations/tests/reparented_replacement.rs
@@ -25,5 +25,5 @@ pub mod root {
fn clone(&self) -> Self { *self }
}
}
- pub use root::foo::Bar as ReferencesBar;
+ pub type ReferencesBar = root::foo::Bar;
}
diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs
index 5864ac73..22e5a087 100644
--- a/tests/expectations/tests/template.rs
+++ b/tests/expectations/tests/template.rs
@@ -12,13 +12,6 @@ pub struct Foo<T, U> {
pub m_member_arr: [T; 1usize],
pub _phantom_1: ::std::marker::PhantomData<U>,
}
-#[test]
-fn __bindgen_test_layout_template_1() {
- assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
- , 24usize);
- assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
- , 8usize);
-}
extern "C" {
#[link_name = "_Z3bar3FooIiiE"]
pub fn bar(foo: Foo<::std::os::raw::c_int, ::std::os::raw::c_int>);
@@ -176,6 +169,13 @@ pub struct TemplateWithVar<T> {
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
+fn __bindgen_test_layout_template_1() {
+ assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
+ , 24usize);
+ assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
+ , 8usize);
+}
+#[test]
fn __bindgen_test_layout_template_2() {
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
4usize);
diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs
index 21d87919..495e80f9 100644
--- a/tests/expectations/tests/union_fields.rs
+++ b/tests/expectations/tests/union_fields.rs
@@ -44,4 +44,4 @@ fn bindgen_test_layout__bindgen_ty_1() {
impl Clone for _bindgen_ty_1 {
fn clone(&self) -> Self { *self }
}
-pub use self::_bindgen_ty_1 as nsStyleUnion;
+pub type nsStyleUnion = _bindgen_ty_1;
diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs
index 541bee5d..fd9cce45 100644
--- a/tests/expectations/tests/unknown_attr.rs
+++ b/tests/expectations/tests/unknown_attr.rs
@@ -13,4 +13,4 @@ pub struct _bindgen_ty_1 {
impl Clone for _bindgen_ty_1 {
fn clone(&self) -> Self { *self }
}
-pub use self::_bindgen_ty_1 as max_align_t;
+pub type max_align_t = _bindgen_ty_1;
diff --git a/libbindgen/tests/headers/16-byte-alignment.h b/tests/headers/16-byte-alignment.h
index 7a7f7548..7a7f7548 100644
--- a/libbindgen/tests/headers/16-byte-alignment.h
+++ b/tests/headers/16-byte-alignment.h
diff --git a/tests/headers/constify-all-enums.h b/tests/headers/constify-all-enums.h
new file mode 100644
index 00000000..7138bf20
--- /dev/null
+++ b/tests/headers/constify-all-enums.h
@@ -0,0 +1,11 @@
+// bindgen-flags: --constified-enum foo
+
+enum foo {
+ THIS,
+ SHOULD_BE,
+ A_CONSTANT,
+};
+
+struct bar {
+ enum foo this_should_work;
+};
diff --git a/tests/headers/issue-410.hpp b/tests/headers/issue-410.hpp
new file mode 100644
index 00000000..a7a834cf
--- /dev/null
+++ b/tests/headers/issue-410.hpp
@@ -0,0 +1,12 @@
+// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value
+
+namespace JS {
+class Value;
+}
+typedef enum {} JSWhyMagic;
+namespace JS {
+class Value {
+public:
+ void a(JSWhyMagic);
+};
+}
diff --git a/tests/headers/no-derive-debug.h b/tests/headers/no-derive-debug.h
new file mode 100644
index 00000000..4a49e404
--- /dev/null
+++ b/tests/headers/no-derive-debug.h
@@ -0,0 +1,15 @@
+// bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone)] pub struct foo { bar: ::std::os::raw::c_int, }"
+
+struct foo {
+ int bar;
+};
+
+/**
+ * bar should compile. It will normally derive debug, but our blacklist of foo
+ * and replacement for another type that doesn't implement it would prevent it
+ * from building if --no-derive-debug didn't work.
+ */
+struct bar {
+ struct foo foo;
+ int baz;
+};