bindgen-cli-0.66.1/.cargo_vcs_info.json0000644000000001510000000000100132760ustar { "git": { "sha1": "38a779c61734c134429dfb99da3499173a848c17" }, "path_in_vcs": "bindgen-cli" }bindgen-cli-0.66.1/Cargo.lock0000644000000356270000000000100112710ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] [[package]] name = "annotate-snippets" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3b9d411ecbaf79885c6df4d75fff75858d5995ff25385657a28af47e82f9c36" dependencies = [ "unicode-width", "yansi-term", ] [[package]] name = "bindgen" version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ "annotate-snippets", "bitflags 2.2.1", "cexpr", "clang-sys", "lazy_static", "lazycell", "log", "peeking_take_while", "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", "syn 2.0.7", "which", ] [[package]] name = "bindgen-cli" version = "0.66.1" dependencies = [ "bindgen", "clap", "clap_complete", "env_logger", "log", "shlex", ] [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" [[package]] name = "cc" version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cexpr" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ "nom", ] [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", "libloading", ] [[package]] name = "clap" version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ "bitflags 1.3.2", "clap_derive", "clap_lex", "is-terminal", "once_cell", "strsim", "termcolor", ] [[package]] name = "clap_complete" version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd" dependencies = [ "clap", ] [[package]] name = "clap_derive" version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.107", ] [[package]] name = "clap_lex" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" dependencies = [ "os_str_bytes", ] [[package]] name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "env_logger" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", "log", "regex", "termcolor", ] [[package]] name = "errno" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", "winapi", ] [[package]] name = "errno-dragonfly" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ "cc", "libc", ] [[package]] name = "glob" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "heck" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "io-lifetimes" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", "windows-sys", ] [[package]] name = "is-terminal" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ "hermit-abi", "io-lifetimes", "rustix", "windows-sys", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", "winapi", ] [[package]] name = "linux-raw-sys" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "nom" version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", ] [[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "os_str_bytes" version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "peeking_take_while" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "prettyplease" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4508c0eff4d1e708551034de4bddd61bf8bda8c7b5ae72bd844cf68ea21117ac" dependencies = [ "proc-macro2", "syn 2.0.7", ] [[package]] name = "proc-macro-error" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", "syn 1.0.107", "version_check", ] [[package]] name = "proc-macro-error-attr" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", "version_check", ] [[package]] name = "proc-macro2" version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] [[package]] name = "regex" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags 1.3.2", "errno", "io-lifetimes", "libc", "linux-raw-sys", "windows-sys", ] [[package]] name = "shlex" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a9a90d19f27bb60792270bb90225f96d97fc5705395134b2ca1dcbb3acc27f4" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "termcolor" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-width" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "which" version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", "libc", "once_cell", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "yansi-term" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" dependencies = [ "winapi", ] bindgen-cli-0.66.1/Cargo.toml0000644000000035300000000000100113000ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" rust-version = "1.64.0" name = "bindgen-cli" version = "0.66.1" authors = ["The rust-bindgen project contributors"] description = "Automatically generates Rust FFI bindings to C and C++ libraries." homepage = "https://rust-lang.github.io/rust-bindgen/" documentation = "https://docs.rs/bindgen" readme = "README.md" keywords = [ "bindings", "ffi", "code-generation", ] categories = [ "external-ffi-bindings", "development-tools::ffi", ] license = "BSD-3-Clause" repository = "https://github.com/rust-lang/rust-bindgen" [[bin]] name = "bindgen" path = "main.rs" [dependencies.bindgen] version = "=0.66.1" features = [ "__cli", "experimental", ] [dependencies.clap] version = "4" features = ["derive"] [dependencies.clap_complete] version = "4" [dependencies.env_logger] version = "0.10.0" optional = true [dependencies.log] version = "0.4" optional = true [dependencies.shlex] version = "1" [features] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] default = [ "logging", "runtime", "which-rustfmt", ] logging = [ "bindgen/logging", "dep:env_logger", "dep:log", ] runtime = ["bindgen/runtime"] static = ["bindgen/static"] which-rustfmt = ["bindgen/which-rustfmt"] bindgen-cli-0.66.1/Cargo.toml.orig000064400000000000000000000027541046102023000147700ustar 00000000000000[package] authors = [ "The rust-bindgen project contributors", ] 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-cli" readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.66.1" edition = "2018" rust-version = "1.64.0" [[bin]] path = "main.rs" name = "bindgen" [dependencies] bindgen = { path = "../bindgen", version = "=0.66.1", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } shlex = "1" [features] default = ["logging", "runtime", "which-rustfmt"] logging = ["bindgen/logging", "dep:env_logger", "dep:log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] ## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen # Features used for CI testing __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] __testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] bindgen-cli-0.66.1/LICENSE000064400000000000000000000027501046102023000131020ustar 00000000000000BSD 3-Clause License Copyright (c) 2013, Jyun-Yan You All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. bindgen-cli-0.66.1/README.md000064400000000000000000000063421046102023000133550ustar 00000000000000[![crates.io](https://img.shields.io/crates/v/bindgen.svg)](https://crates.io/crates/bindgen) [![docs.rs](https://docs.rs/bindgen/badge.svg)](https://docs.rs/bindgen/) # `bindgen` **`bindgen` automatically generates Rust FFI bindings to C (and some C++) libraries.** For example, given the C header `doggo.h`: ```c typedef struct Doggo { int many; char wow; } Doggo; void eleven_out_of_ten_majestic_af(Doggo* pupper); ``` `bindgen` produces Rust FFI code allowing you to call into the `doggo` library's functions and use its types: ```rust /* automatically generated by rust-bindgen 0.99.9 */ #[repr(C)] pub struct Doggo { pub many: ::std::os::raw::c_int, pub wow: ::std::os::raw::c_char, } extern "C" { pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo); } ``` ## Users Guide [📚 Read the `bindgen` users guide here! 📚](https://rust-lang.github.io/rust-bindgen) ## MSRV The `bindgen` minimum supported Rust version is **1.60.0**. The `bindgen-cli` minimum supported Rust version is **1.64.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. The MSRV is the minimum Rust version that can be used to *compile* each crate. However, `bindgen` and `bindgen-cli` can generate bindings that are compatible with Rust versions below the current MSRV. Most of the time, the `bindgen-cli` crate will have a more recent MSRV than `bindgen` as crates such as `clap` require it. ## API Reference [API reference documentation is on docs.rs](https://docs.rs/bindgen) ## Environment Variables In addition to the [library API](https://docs.rs/bindgen) and [executable command-line API][bindgen-cmdline], `bindgen` can be controlled through environment variables. End-users should set these environment variables to modify `bindgen`'s behavior without modifying the source code of direct consumers of `bindgen`. - `BINDGEN_EXTRA_CLANG_ARGS`: extra arguments to pass to `clang` - Arguments are whitespace-separated - Use shell-style quoting to pass through whitespace - Examples: - Specify alternate sysroot: `--sysroot=/path/to/sysroot` - Add include search path with spaces: `-I"/path/with spaces"` - `BINDGEN_EXTRA_CLANG_ARGS_`: similar to `BINDGEN_EXTRA_CLANG_ARGS`, but used to set per-target arguments to pass to clang. Useful to set system include directories in a target-specific way in cross-compilation environments with multiple targets. Has precedence over `BINDGEN_EXTRA_CLANG_ARGS`. Additionally, `bindgen` uses `libclang` to parse C and C++ header files. To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env]. For more details on how `bindgen` uses `libclang`, see the [`bindgen` users guide][bindgen-book-clang]. ## Releases We don't follow a specific release calendar, but if you need a release please file an issue requesting that (ping `@emilio` for increased effectiveness). ## Contributing [See `CONTRIBUTING.md` for hacking on `bindgen`!](./CONTRIBUTING.md) [bindgen-cmdline]: https://rust-lang.github.io/rust-bindgen/command-line-usage.html [clang-sys-env]: https://github.com/KyleMayes/clang-sys#environment-variables [bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang bindgen-cli-0.66.1/main.rs000064400000000000000000000037251046102023000133720ustar 00000000000000extern crate bindgen; extern crate clap; #[cfg(feature = "logging")] extern crate env_logger; #[cfg(feature = "logging")] extern crate log; use std::env; mod options; use crate::options::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { let version = bindgen::clang_version(); let expected_version = if cfg!(feature = "__testing_only_libclang_9") { Some((9, 0)) } else if cfg!(feature = "__testing_only_libclang_5") { Some((5, 0)) } else { None }; log::info!( "Clang Version: {}, parsed: {:?}", version.full, version.parsed ); if expected_version.is_some() { // assert_eq!(version.parsed, version.parsed); } } pub fn main() { #[cfg(feature = "logging")] env_logger::init(); match builder_from_flags(env::args()) { Ok((builder, output, verbose)) => { #[cfg(feature = "logging")] clang_version_check(); std::panic::set_hook(Box::new(move |info| { if verbose { print_verbose_err() } println!("{}", info); })); let bindings = builder.generate().expect("Unable to generate bindings"); let _ = std::panic::take_hook(); bindings.write(output).expect("Unable to write output"); } Err(error) => { println!("{}", error); std::process::exit(1); } }; } fn print_verbose_err() { println!("Bindgen unexpectedly panicked"); println!( "This may be caused by one of the known-unsupported \ things (https://rust-lang.github.io/rust-bindgen/cpp.html), \ please modify the bindgen flags to work around it as \ described in https://rust-lang.github.io/rust-bindgen/cpp.html" ); println!( "Otherwise, please file an issue at \ https://github.com/rust-lang/rust-bindgen/issues/new" ); } bindgen-cli-0.66.1/options.rs000064400000000000000000001040341046102023000141340ustar 00000000000000use bindgen::callbacks::TypeKind; use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::{CommandFactory, Parser}; use std::fs::File; use std::io::{self, Error, ErrorKind}; use std::path::PathBuf; use std::process::exit; fn rust_target_help() -> String { format!( "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {:?}.", RUST_TARGET_STRINGS, String::from(RustTarget::default()) ) } fn parse_codegen_config(what_to_generate: &str) -> io::Result { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(',') { match what { "functions" => config.insert(CodegenConfig::FUNCTIONS), "types" => config.insert(CodegenConfig::TYPES), "vars" => config.insert(CodegenConfig::VARS), "methods" => config.insert(CodegenConfig::METHODS), "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), "destructors" => config.insert(CodegenConfig::DESTRUCTORS), otherwise => { return Err(Error::new( ErrorKind::Other, format!("Unknown generate item: {}", otherwise), )); } } } Ok(config) } #[derive(Parser, Debug)] #[clap( about = "Generates Rust bindings from C/C++ headers.", override_usage = "bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...", trailing_var_arg = true )] struct BindgenCommand { /// C or C++ header file. header: Option, /// Path to write depfile to. #[arg(long)] depfile: Option, /// The default style of code used to generate enums. #[arg(long, value_name = "VARIANT")] default_enum_style: Option, /// Mark any enum whose name matches REGEX as a set of bitfield flags. #[arg(long, value_name = "REGEX")] bitfield_enum: Vec, /// Mark any enum whose name matches REGEX as a newtype. #[arg(long, value_name = "REGEX")] newtype_enum: Vec, /// Mark any enum whose name matches REGEX as a global newtype. #[arg(long, value_name = "REGEX")] newtype_global_enum: Vec, /// Mark any enum whose name matches REGEX as a Rust enum. #[arg(long, value_name = "REGEX")] rustified_enum: Vec, /// Mark any enum whose name matches REGEX as a series of constants. #[arg(long, value_name = "REGEX")] constified_enum: Vec, /// Mark any enum whose name matches REGEX as a module of constants. #[arg(long, value_name = "REGEX")] constified_enum_module: Vec, /// The default signed/unsigned type for C macro constants. #[arg(long, value_name = "VARIANT")] default_macro_constant_type: Option, /// The default style of code used to generate typedefs. #[arg(long, value_name = "VARIANT")] default_alias_style: Option, /// Mark any typedef alias whose name matches REGEX to use normal type aliasing. #[arg(long, value_name = "REGEX")] normal_alias: Vec, /// Mark any typedef alias whose name matches REGEX to have a new type generated for it. #[arg(long, value_name = "REGEX")] new_type_alias: Vec, /// Mark any typedef alias whose name matches REGEX to have a new type with Deref and DerefMut to the inner type. #[arg(long, value_name = "REGEX")] new_type_alias_deref: Vec, /// The default style of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. #[arg(long, value_name = "STYLE")] default_non_copy_union_style: Option, /// Mark any union whose name matches REGEX and who has a non-Copy member to use a bindgen-generated wrapper for fields. #[arg(long, value_name = "REGEX")] bindgen_wrapper_union: Vec, /// Mark any union whose name matches REGEX and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. #[arg(long, value_name = "REGEX")] manually_drop_union: Vec, /// Mark TYPE as hidden. #[arg(long, value_name = "TYPE")] blocklist_type: Vec, /// Mark FUNCTION as hidden. #[arg(long, value_name = "FUNCTION")] blocklist_function: Vec, /// Mark ITEM as hidden. #[arg(long, value_name = "ITEM")] blocklist_item: Vec, /// Mark FILE as hidden. #[arg(long, value_name = "FILE")] blocklist_file: Vec, /// Avoid generating layout tests for any type. #[arg(long)] no_layout_tests: bool, /// Avoid deriving Copy on any type. #[arg(long)] no_derive_copy: bool, /// Avoid deriving Debug on any type. #[arg(long)] no_derive_debug: bool, /// Avoid deriving Default on any type. #[arg(long, hide = true)] no_derive_default: bool, /// Create a Debug implementation if it cannot be derived automatically. #[arg(long)] impl_debug: bool, /// Create a PartialEq implementation if it cannot be derived automatically. #[arg(long)] impl_partialeq: bool, /// Derive Default on any type. #[arg(long)] with_derive_default: bool, /// Derive Hash on any type. #[arg(long)] with_derive_hash: bool, /// Derive PartialEq on any type. #[arg(long)] with_derive_partialeq: bool, /// Derive PartialOrd on any type. #[arg(long)] with_derive_partialord: bool, /// Derive Eq on any type. #[arg(long)] with_derive_eq: bool, /// Derive Ord on any type. #[arg(long)] with_derive_ord: bool, /// Avoid including doc comments in the output, see: #[arg(long)] no_doc_comments: bool, /// Disable allowlisting types recursively. This will cause bindgen to emit Rust code that won't compile! See the `bindgen::Builder::allowlist_recursively` method's documentation for details. #[arg(long)] no_recursive_allowlist: bool, /// Use extern crate instead of use for objc. #[arg(long)] objc_extern_crate: bool, /// Generate block signatures instead of void pointers. #[arg(long)] generate_block: bool, /// Generate string constants as `&CStr` instead of `&[u8]`. #[arg(long)] generate_cstr: bool, /// Use extern crate instead of use for block. #[arg(long)] block_extern_crate: bool, /// Do not trust the libclang-provided mangling #[arg(long)] distrust_clang_mangling: bool, /// Output bindings for builtin definitions, e.g. __builtin_va_list. #[arg(long)] builtins: bool, /// Use the given prefix before raw types instead of ::std::os::raw. #[arg(long, value_name = "PREFIX")] ctypes_prefix: Option, /// Use the given prefix for anonymous fields. #[arg(long, default_value = DEFAULT_ANON_FIELDS_PREFIX, value_name = "PREFIX")] anon_fields_prefix: String, /// Time the different bindgen phases and print to stderr #[arg(long)] time_phases: bool, /// Output the Clang AST for debugging purposes. #[arg(long)] emit_clang_ast: bool, /// Output our internal IR for debugging purposes. #[arg(long)] emit_ir: bool, /// Dump graphviz dot file. #[arg(long, value_name = "PATH")] emit_ir_graphviz: Option, /// Enable support for C++ namespaces. #[arg(long)] enable_cxx_namespaces: bool, /// Disable namespacing via mangling, causing bindgen to generate names like `Baz` instead of `foo_bar_Baz` for an input name `foo::bar::Baz`. #[arg(long)] disable_name_namespacing: bool, /// Disable nested struct naming, causing bindgen to generate names like `bar` instead of `foo_bar` for a nested definition `struct foo { struct bar { } b; };`. #[arg(long)] disable_nested_struct_naming: bool, /// Disable support for native Rust unions. #[arg(long)] disable_untagged_union: bool, /// Suppress insertion of bindgen's version identifier into generated bindings. #[arg(long)] disable_header_comment: bool, /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts. #[arg(long)] ignore_functions: bool, /// Generate only given items, split by commas. Valid values are `functions`,`types`, `vars`, `methods`, `constructors` and `destructors`. #[arg(long, value_parser = parse_codegen_config)] generate: Option, /// Do not generate bindings for methods. #[arg(long)] ignore_methods: bool, /// Do not automatically convert floats to f32/f64. #[arg(long)] no_convert_floats: bool, /// Do not prepend the enum name to constant or newtype variants. #[arg(long)] no_prepend_enum_name: bool, /// Do not try to detect default include paths #[arg(long)] no_include_path_detection: bool, /// Try to fit macro constants into types smaller than u32/i32 #[arg(long)] fit_macro_constant_types: bool, /// Mark TYPE as opaque. #[arg(long, value_name = "TYPE")] opaque_type: Vec, /// Write Rust bindings to OUTPUT. #[arg(long, short, value_name = "OUTPUT")] output: Option, /// Add a raw line of Rust code at the beginning of output. #[arg(long)] raw_line: Vec, /// Add a raw line of Rust code to a given module. #[arg(long, number_of_values = 2, value_names = ["MODULE-NAME", "RAW-LINE"])] module_raw_line: Vec, #[arg(long, help = rust_target_help())] rust_target: Option, /// Use types from Rust core instead of std. #[arg(long)] use_core: bool, /// Conservatively generate inline namespaces to avoid name conflicts. #[arg(long)] conservative_inline_namespaces: bool, /// Allowlist all the free-standing functions matching REGEX. Other non-allowlisted functions will not be generated. #[arg(long, value_name = "REGEX")] allowlist_function: Vec, /// Generate inline functions. #[arg(long)] generate_inline_functions: bool, /// Only generate types matching REGEX. Other non-allowlisted types will not be generated. #[arg(long, value_name = "REGEX")] allowlist_type: Vec, /// Allowlist all the free-standing variables matching REGEX. Other non-allowlisted variables will not be generated. #[arg(long, value_name = "REGEX")] allowlist_var: Vec, /// Allowlist all contents of PATH. #[arg(long, value_name = "PATH")] allowlist_file: Vec, /// Print verbose error messages. #[arg(long)] verbose: bool, /// Preprocess and dump the input header files to disk. Useful when debugging bindgen, using C-Reduce, or when filing issues. The resulting file will be named something like `__bindgen.i` or `__bindgen.ii`. #[arg(long)] dump_preprocessed_input: bool, /// Do not record matching items in the regex sets. This disables reporting of unused items. #[arg(long)] no_record_matches: bool, /// Do not bind size_t as usize (useful on platforms where those types are incompatible). #[arg(long = "no-size_t-is-usize")] no_size_t_is_usize: bool, /// Do not format the generated bindings with rustfmt. This option is deprecated, please use /// `--formatter=none` instead. #[arg(long)] no_rustfmt_bindings: bool, /// Which tool should be used to format the bindings #[arg( long, value_name = "FORMATTER", conflicts_with = "no_rustfmt_bindings" )] formatter: Option, /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings")] rustfmt_configuration_file: Option, /// Avoid deriving PartialEq for types matching REGEX. #[arg(long, value_name = "REGEX")] no_partialeq: Vec, /// Avoid deriving Copy and Clone for types matching REGEX. #[arg(long, value_name = "REGEX")] no_copy: Vec, /// Avoid deriving Debug for types matching REGEX. #[arg(long, value_name = "REGEX")] no_debug: Vec, /// Avoid deriving/implementing Default for types matching REGEX. #[arg(long, value_name = "REGEX")] no_default: Vec, /// Avoid deriving Hash for types matching REGEX. #[arg(long, value_name = "REGEX")] no_hash: Vec, /// Add `#[must_use]` annotation to types matching REGEX. #[arg(long, value_name = "REGEX")] must_use_type: Vec, /// Enables detecting unexposed attributes in functions (slow). Used to generate `#[must_use]` annotations. #[arg(long)] enable_function_attribute_detection: bool, /// Use `*const [T; size]` instead of `*const T` for C arrays #[arg(long)] use_array_pointers_in_arguments: bool, /// The name to be used in a #[link(wasm_import_module = ...)] statement #[arg(long, value_name = "NAME")] wasm_import_module_name: Option, /// Use dynamic loading mode with the given library name. #[arg(long, value_name = "NAME")] dynamic_loading: Option, /// Require successful linkage to all functions in the library. #[arg(long)] dynamic_link_require_all: bool, /// Prefix the name of exported symbols. #[arg(long)] prefix_link_name: Option, /// Makes generated bindings `pub` only for items if the items are publically accessible in C++. #[arg(long)] respect_cxx_access_specs: bool, /// Always translate enum integer types to native Rust integer types. #[arg(long)] translate_enum_integer_types: bool, /// Generate types with C style naming. #[arg(long)] c_naming: bool, /// Always output explicit padding fields. #[arg(long)] explicit_padding: bool, /// Enables generation of vtable functions. #[arg(long)] vtable_generation: bool, /// Enables sorting of code generation in a predefined manner. #[arg(long)] sort_semantically: bool, /// Deduplicates extern blocks. #[arg(long)] merge_extern_blocks: bool, /// Overrides the ABI of functions matching REGEX. The OVERRIDE value must be of the shape REGEX=ABI where ABI can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind. #[arg(long, value_name = "OVERRIDE")] override_abi: Vec, /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom: Vec, /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_struct: Vec, /// Derive custom traits on an `enum. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_enum: Vec, /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_union: Vec, /// Generate wrappers for `static` and `static inline` functions. #[arg(long, requires = "experimental")] wrap_static_fns: bool, /// Sets the path for the source file that must be created due to the presence of `static` and /// `static inline` functions. #[arg(long, requires = "experimental", value_name = "PATH")] wrap_static_fns_path: Option, /// Sets the suffix added to the extern wrapper functions generated for `static` and `static /// inline` functions. #[arg(long, requires = "experimental", value_name = "SUFFIX")] wrap_static_fns_suffix: Option, /// Set the default visibility of fields, including bitfields and accessor methods for /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. #[arg(long, value_name = "VISIBILITY")] default_visibility: Option, /// Whether to emit diagnostics or not. #[arg(long, requires = "experimental")] emit_diagnostics: bool, /// Generates completions for the specified SHELL, sends them to `stdout` and exits. #[arg(long, value_name = "SHELL")] generate_shell_completions: Option, /// Enables experimental features. #[arg(long)] experimental: bool, /// Prints the version, and exits #[arg(short = 'V', long)] version: bool, /// Arguments to be passed straight through to clang. clang_args: Vec, } /// Construct a new [`Builder`](./struct.Builder.html) from command line flags. pub fn builder_from_flags( args: I, ) -> Result<(Builder, Box, bool), io::Error> where I: Iterator, { let command = BindgenCommand::parse_from(args); let BindgenCommand { header, depfile, default_enum_style, bitfield_enum, newtype_enum, newtype_global_enum, rustified_enum, constified_enum, constified_enum_module, default_macro_constant_type, default_alias_style, normal_alias, new_type_alias, new_type_alias_deref, default_non_copy_union_style, bindgen_wrapper_union, manually_drop_union, blocklist_type, blocklist_function, blocklist_item, blocklist_file, no_layout_tests, no_derive_copy, no_derive_debug, no_derive_default, impl_debug, impl_partialeq, with_derive_default, with_derive_hash, with_derive_partialeq, with_derive_partialord, with_derive_eq, with_derive_ord, no_doc_comments, no_recursive_allowlist, objc_extern_crate, generate_block, generate_cstr, block_extern_crate, distrust_clang_mangling, builtins, ctypes_prefix, anon_fields_prefix, time_phases, emit_clang_ast, emit_ir, emit_ir_graphviz, enable_cxx_namespaces, disable_name_namespacing, disable_nested_struct_naming, disable_untagged_union, disable_header_comment, ignore_functions, generate, ignore_methods, no_convert_floats, no_prepend_enum_name, no_include_path_detection, fit_macro_constant_types, opaque_type, output, raw_line, module_raw_line, rust_target, use_core, conservative_inline_namespaces, allowlist_function, generate_inline_functions, allowlist_type, allowlist_var, allowlist_file, verbose, dump_preprocessed_input, no_record_matches, no_size_t_is_usize, no_rustfmt_bindings, formatter, rustfmt_configuration_file, no_partialeq, no_copy, no_debug, no_default, no_hash, must_use_type, enable_function_attribute_detection, use_array_pointers_in_arguments, wasm_import_module_name, dynamic_loading, dynamic_link_require_all, prefix_link_name, respect_cxx_access_specs, translate_enum_integer_types, c_naming, explicit_padding, vtable_generation, sort_semantically, merge_extern_blocks, override_abi, wrap_unsafe_ops, with_derive_custom, with_derive_custom_struct, with_derive_custom_enum, with_derive_custom_union, wrap_static_fns, wrap_static_fns_path, wrap_static_fns_suffix, default_visibility, emit_diagnostics, generate_shell_completions, experimental: _, version, clang_args, } = command; if let Some(shell) = generate_shell_completions { clap_complete::generate( shell, &mut BindgenCommand::command(), "bindgen", &mut std::io::stdout(), ); exit(0); } if version { println!( "bindgen {}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") ); if verbose { println!("Clang: {}", bindgen::clang_version().full); } std::process::exit(0); } let mut builder = builder(); if let Some(header) = header { builder = builder.header(header); } else { return Err(Error::new(ErrorKind::Other, "Header not found")); } if let Some(rust_target) = rust_target { builder = builder.rust_target(rust_target); } if let Some(variant) = default_enum_style { builder = builder.default_enum_style(variant); } for regex in bitfield_enum { builder = builder.bitfield_enum(regex); } for regex in newtype_enum { builder = builder.newtype_enum(regex); } for regex in newtype_global_enum { builder = builder.newtype_global_enum(regex); } for regex in rustified_enum { builder = builder.rustified_enum(regex); } for regex in constified_enum { builder = builder.constified_enum(regex); } for regex in constified_enum_module { builder = builder.constified_enum_module(regex); } if let Some(default_macro_constant_type) = default_macro_constant_type { builder = builder.default_macro_constant_type(default_macro_constant_type) } if let Some(variant) = default_alias_style { builder = builder.default_alias_style(variant); } for regex in normal_alias { builder = builder.type_alias(regex); } for regex in new_type_alias { builder = builder.new_type_alias(regex); } for regex in new_type_alias_deref { builder = builder.new_type_alias_deref(regex); } if let Some(variant) = default_non_copy_union_style { builder = builder.default_non_copy_union_style(variant); } for regex in bindgen_wrapper_union { builder = builder.bindgen_wrapper_union(regex); } for regex in manually_drop_union { builder = builder.manually_drop_union(regex); } for ty in blocklist_type { builder = builder.blocklist_type(ty); } for fun in blocklist_function { builder = builder.blocklist_function(fun); } for id in blocklist_item { builder = builder.blocklist_item(id); } for file in blocklist_file { builder = builder.blocklist_file(file); } if builtins { builder = builder.emit_builtins(); } if no_layout_tests { builder = builder.layout_tests(false); } if no_derive_copy { builder = builder.derive_copy(false); } if no_derive_debug { builder = builder.derive_debug(false); } if impl_debug { builder = builder.impl_debug(true); } if impl_partialeq { builder = builder.impl_partialeq(true); } if with_derive_default { builder = builder.derive_default(true); } if with_derive_hash { builder = builder.derive_hash(true); } if with_derive_partialeq { builder = builder.derive_partialeq(true); } if with_derive_partialord { builder = builder.derive_partialord(true); } if with_derive_eq { builder = builder.derive_eq(true); } if with_derive_ord { builder = builder.derive_ord(true); } if no_derive_default { builder = builder.derive_default(false); } if no_prepend_enum_name { builder = builder.prepend_enum_name(false); } if no_include_path_detection { builder = builder.detect_include_paths(false); } if fit_macro_constant_types { builder = builder.fit_macro_constants(true); } if time_phases { builder = builder.time_phases(true); } if use_array_pointers_in_arguments { builder = builder.array_pointers_in_arguments(true); } if let Some(wasm_import_name) = wasm_import_module_name { builder = builder.wasm_import_module_name(wasm_import_name); } if let Some(prefix) = ctypes_prefix { builder = builder.ctypes_prefix(prefix); } builder = builder.anon_fields_prefix(anon_fields_prefix); if let Some(config) = generate { builder = builder.with_codegen_config(config); } if emit_clang_ast { builder = builder.emit_clang_ast(); } if emit_ir { builder = builder.emit_ir(); } if let Some(path) = emit_ir_graphviz { builder = builder.emit_ir_graphviz(path); } if enable_cxx_namespaces { builder = builder.enable_cxx_namespaces(); } if enable_function_attribute_detection { builder = builder.enable_function_attribute_detection(); } if disable_name_namespacing { builder = builder.disable_name_namespacing(); } if disable_nested_struct_naming { builder = builder.disable_nested_struct_naming(); } if disable_untagged_union { builder = builder.disable_untagged_union(); } if disable_header_comment { builder = builder.disable_header_comment(); } if ignore_functions { builder = builder.ignore_functions(); } if ignore_methods { builder = builder.ignore_methods(); } if no_convert_floats { builder = builder.no_convert_floats(); } if no_doc_comments { builder = builder.generate_comments(false); } if no_recursive_allowlist { builder = builder.allowlist_recursively(false); } if objc_extern_crate { builder = builder.objc_extern_crate(true); } if generate_block { builder = builder.generate_block(true); } if generate_cstr { builder = builder.generate_cstr(true); } if block_extern_crate { builder = builder.block_extern_crate(true); } for ty in opaque_type { builder = builder.opaque_type(ty); } for line in raw_line { builder = builder.raw_line(line); } let mut values = module_raw_line.into_iter(); while let Some(module) = values.next() { let line = values.next().unwrap(); builder = builder.module_raw_line(module, line); } if use_core { builder = builder.use_core(); } if distrust_clang_mangling { builder = builder.trust_clang_mangling(false); } if conservative_inline_namespaces { builder = builder.conservative_inline_namespaces(); } if generate_inline_functions { builder = builder.generate_inline_functions(true); } for regex in allowlist_function { builder = builder.allowlist_function(regex); } for regex in allowlist_type { builder = builder.allowlist_type(regex); } for regex in allowlist_var { builder = builder.allowlist_var(regex); } for file in allowlist_file { builder = builder.allowlist_file(file); } for arg in clang_args { builder = builder.clang_arg(arg); } let output = if let Some(path) = &output { let file = File::create(path)?; if let Some(depfile) = depfile { builder = builder.depfile(path, depfile); } Box::new(io::BufWriter::new(file)) as Box } else { if let Some(depfile) = depfile { builder = builder.depfile("-", depfile); } Box::new(io::BufWriter::new(io::stdout())) as Box }; if dump_preprocessed_input { builder.dump_preprocessed_input()?; } if no_record_matches { builder = builder.record_matches(false); } if no_size_t_is_usize { builder = builder.size_t_is_usize(false); } if no_rustfmt_bindings { builder = builder.formatter(Formatter::None); } if let Some(formatter) = formatter { builder = builder.formatter(formatter); } if let Some(path_str) = rustfmt_configuration_file { let path = PathBuf::from(path_str); if !path.is_absolute() { return Err(Error::new( ErrorKind::Other, "--rustfmt-configuration-file needs to be an absolute path!", )); } if path.to_str().is_none() { return Err(Error::new( ErrorKind::Other, "--rustfmt-configuration-file contains non-valid UTF8 characters.", )); } builder = builder.rustfmt_configuration_file(Some(path)); } for regex in no_partialeq { builder = builder.no_partialeq(regex); } for regex in no_copy { builder = builder.no_copy(regex); } for regex in no_debug { builder = builder.no_debug(regex); } for regex in no_default { builder = builder.no_default(regex); } for regex in no_hash { builder = builder.no_hash(regex); } for regex in must_use_type { builder = builder.must_use_type(regex); } if let Some(dynamic_library_name) = dynamic_loading { builder = builder.dynamic_library_name(dynamic_library_name); } if dynamic_link_require_all { builder = builder.dynamic_link_require_all(true); } if let Some(prefix_link_name) = prefix_link_name { #[derive(Debug)] struct PrefixLinkNameCallback { prefix: String, } impl bindgen::callbacks::ParseCallbacks for PrefixLinkNameCallback { fn generated_link_name_override( &self, item_info: bindgen::callbacks::ItemInfo<'_>, ) -> Option { let mut prefix = self.prefix.clone(); prefix.push_str(item_info.name); Some(prefix) } } builder = builder.parse_callbacks(Box::new(PrefixLinkNameCallback { prefix: prefix_link_name, })) } if respect_cxx_access_specs { builder = builder.respect_cxx_access_specs(true); } if translate_enum_integer_types { builder = builder.translate_enum_integer_types(true); } if c_naming { builder = builder.c_naming(true); } if explicit_padding { builder = builder.explicit_padding(true); } if vtable_generation { builder = builder.vtable_generation(true); } if sort_semantically { builder = builder.sort_semantically(true); } if merge_extern_blocks { builder = builder.merge_extern_blocks(true); } for abi_override in override_abi { let (regex, abi_str) = abi_override .rsplit_once('=') .expect("Invalid ABI override: Missing `=`"); let abi = abi_str .parse() .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); builder = builder.override_abi(abi, regex); } if wrap_unsafe_ops { builder = builder.wrap_unsafe_ops(true); } #[derive(Debug)] struct CustomDeriveCallback { derives: Vec, kind: Option, regex_set: bindgen::RegexSet, } impl bindgen::callbacks::ParseCallbacks for CustomDeriveCallback { fn cli_args(&self) -> Vec { let mut args = vec![]; let flag = match &self.kind { None => "--with-derive-custom", Some(TypeKind::Struct) => "--with-derive-custom-struct", Some(TypeKind::Enum) => "--with-derive-custom-enum", Some(TypeKind::Union) => "--with-derive-custom-union", }; let derives = self.derives.join(","); for item in self.regex_set.get_items() { args.extend_from_slice(&[ flag.to_owned(), format!("{}={}", item, derives), ]); } args } fn add_derives( &self, info: &bindgen::callbacks::DeriveInfo<'_>, ) -> Vec { if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && self.regex_set.matches(info.name) { return self.derives.clone(); } vec![] } } for (custom_derives, kind, name) in [ (with_derive_custom, None, "--with-derive-custom"), ( with_derive_custom_struct, Some(TypeKind::Struct), "--with-derive-custom-struct", ), ( with_derive_custom_enum, Some(TypeKind::Enum), "--with-derive-custom-enum", ), ( with_derive_custom_union, Some(TypeKind::Union), "--with-derive-custom-union", ), ] { let name = emit_diagnostics.then_some(name); for custom_derive in custom_derives { let (regex, derives) = custom_derive .rsplit_once('=') .expect("Invalid custom derive argument: Missing `=`"); let derives = derives.split(',').map(|s| s.to_owned()).collect(); let mut regex_set = RegexSet::new(); regex_set.insert(regex); regex_set.build_with_diagnostics(false, name); builder = builder.parse_callbacks(Box::new(CustomDeriveCallback { derives, kind, regex_set, })); } } if wrap_static_fns { builder = builder.wrap_static_fns(true); } if let Some(path) = wrap_static_fns_path { builder = builder.wrap_static_fns_path(path); } if let Some(suffix) = wrap_static_fns_suffix { builder = builder.wrap_static_fns_suffix(suffix); } if let Some(visibility) = default_visibility { builder = builder.default_visibility(visibility); } if emit_diagnostics { builder = builder.emit_diagnostics(); } Ok((builder, output, verbose)) }