зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1855631 - Upgrade bindgen to 0.68.1. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D189457
This commit is contained in:
Родитель
05fcca29c3
Коммит
83f4904aca
|
@ -408,21 +408,28 @@ dependencies = [
|
|||
name = "bindgen"
|
||||
version = "0.63.999"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.66.999",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.64.999"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.66.999",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.66.1"
|
||||
version = "0.66.999"
|
||||
dependencies = [
|
||||
"bindgen 0.68.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.68.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
|
||||
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
|
||||
dependencies = [
|
||||
"bitflags 2.4.0",
|
||||
"cexpr",
|
||||
|
@ -567,7 +574,7 @@ dependencies = [
|
|||
name = "builtins-static"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.68.1",
|
||||
"mozilla-central-workspace-hack",
|
||||
"nom",
|
||||
"pkcs11-bindings",
|
||||
|
@ -2008,7 +2015,7 @@ name = "gecko-profiler"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.68.1",
|
||||
"lazy_static",
|
||||
"mozbuild",
|
||||
"profiler-macros",
|
||||
|
@ -2548,7 +2555,7 @@ name = "http3server"
|
|||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"base64 0.21.3",
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.68.1",
|
||||
"cfg-if 1.0.0",
|
||||
"http",
|
||||
"hyper",
|
||||
|
@ -3618,7 +3625,7 @@ name = "mozilla-central-workspace-hack"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.68.1",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"env_logger",
|
||||
|
@ -3923,7 +3930,7 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c17aec6d4e1822c023689899f09311592a36cbf6de8f85dfaf5f01976790d8d"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.66.999",
|
||||
"mozbuild",
|
||||
"once_cell",
|
||||
"pkcs11-bindings",
|
||||
|
@ -4275,7 +4282,7 @@ version = "0.1.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0fabbdbe64b22820753da90995b3a73d02907eaeeac6f2414962a566aaa18ea"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.66.999",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -5186,7 +5193,7 @@ dependencies = [
|
|||
"app_units",
|
||||
"arrayvec",
|
||||
"atomic_refcell",
|
||||
"bindgen 0.66.1",
|
||||
"bindgen 0.68.1",
|
||||
"bitflags 2.4.0",
|
||||
"byteorder",
|
||||
"cssparser",
|
||||
|
|
|
@ -132,8 +132,9 @@ base64 = { path = "build/rust/base64" }
|
|||
# Patch wasi 0.10 to 0.11
|
||||
wasi = { path = "build/rust/wasi" }
|
||||
|
||||
# Patch bindgen 0.63 and 0.64 to 0.66
|
||||
# Patch bindgen 0.63, 0.64 and 0.66 to 0.68
|
||||
bindgen_0_63 = { package = "bindgen", path = "build/rust/bindgen-0.63" }
|
||||
bindgen_0_64 = { package = "bindgen", path = "build/rust/bindgen-0.64" }
|
||||
bindgen = { path = "build/rust/bindgen" }
|
||||
|
||||
# Patch nix 0.24 to 0.26
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "bindgen"
|
||||
version = "0.64.999"
|
||||
edition = "2018"
|
||||
license = "BSD-3-Clause"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies.bindgen]
|
||||
version = "0.66.0"
|
||||
default-features = false
|
||||
|
||||
[features]
|
||||
logging = ["bindgen/logging"]
|
||||
runtime = ["bindgen/runtime"]
|
||||
static = ["bindgen/static"]
|
||||
which-rustfmt = ["bindgen/which-rustfmt"]
|
|
@ -0,0 +1,26 @@
|
|||
// 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.
|
||||
|
||||
pub use bindgen::*;
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bindgen"
|
||||
version = "0.64.999"
|
||||
version = "0.66.999"
|
||||
edition = "2018"
|
||||
license = "BSD-3-Clause"
|
||||
|
||||
|
@ -8,7 +8,7 @@ license = "BSD-3-Clause"
|
|||
path = "lib.rs"
|
||||
|
||||
[dependencies.bindgen]
|
||||
version = "0.66.0"
|
||||
version = "0.68.0"
|
||||
default-features = false
|
||||
|
||||
[features]
|
||||
|
|
|
@ -49,7 +49,7 @@ uuid = { version = "1", features = ["serde", "v4"], optional = true }
|
|||
scopeguard = { version = "1", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = { version = "0.66", default-features = false, features = ["runtime"], optional = true }
|
||||
bindgen = { version = "0.68", default-features = false, features = ["runtime"], optional = true }
|
||||
libc = "0.2"
|
||||
memchr = { version = "2", optional = true }
|
||||
nom = { version = "7", optional = true }
|
||||
|
|
|
@ -28,7 +28,7 @@ features = ["gecko"]
|
|||
|
||||
# Make sure to use bindgen's runtime-loading of libclang, as it allows for a wider range of clang versions to be used
|
||||
[build-dependencies]
|
||||
bindgen = {version = "0.66", default-features = false, features = ["runtime"] }
|
||||
bindgen = {version = "0.68", default-features = false, features = ["runtime"] }
|
||||
|
||||
[[bin]]
|
||||
name = "http3server"
|
||||
|
|
|
@ -11,7 +11,7 @@ smallvec = { version = "1.9.0", features = ["const_new"] }
|
|||
mozilla-central-workspace-hack = { version = "0.1", features = ["builtins-static"], optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = { default-features = false, features = ["runtime"], version = "0.66" }
|
||||
bindgen = { default-features = false, features = ["runtime"], version = "0.68" }
|
||||
nom = "7.1.1"
|
||||
|
||||
[lib]
|
||||
|
|
|
@ -84,7 +84,7 @@ gecko-profiler = { path = "../../../tools/profiler/rust-api" }
|
|||
[build-dependencies]
|
||||
lazy_static = "1"
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
bindgen = {version = "0.66", optional = true, default-features = false}
|
||||
bindgen = {version = "0.68", optional = true, default-features = false}
|
||||
regex = {version = "1.0", optional = true, default-features = false, features = ["perf", "std"]}
|
||||
walkdir = "2.1.4"
|
||||
toml = {version = "0.5", optional = true, default-features = false}
|
||||
|
|
|
@ -676,6 +676,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
|
|||
criteria = "safe-to-deploy"
|
||||
delta = "0.64.0 -> 0.66.1"
|
||||
|
||||
[[audits.bindgen]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.66.1 -> 0.68.1"
|
||||
|
||||
[[audits.bit-set]]
|
||||
who = "Aria Beingessner <a.beingessner@gmail.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -13,7 +13,7 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.60.0"
|
||||
name = "bindgen"
|
||||
version = "0.66.1"
|
||||
version = "0.68.1"
|
||||
authors = [
|
||||
"Jyun-Yan You <jyyou.tw@gmail.com>",
|
||||
"Emilio Cobos Álvarez <emilio@crisal.io>",
|
||||
|
@ -37,6 +37,12 @@ categories = [
|
|||
license = "BSD-3-Clause"
|
||||
repository = "https://github.com/rust-lang/rust-bindgen"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["experimental"]
|
||||
|
||||
[package.metadata.release]
|
||||
release = true
|
||||
|
||||
[lib]
|
||||
name = "bindgen"
|
||||
path = "lib.rs"
|
||||
|
@ -70,7 +76,8 @@ optional = true
|
|||
version = "0.1.2"
|
||||
|
||||
[dependencies.prettyplease]
|
||||
version = "0.2.0"
|
||||
version = "0.2.7"
|
||||
features = ["verbatim"]
|
||||
optional = true
|
||||
|
||||
[dependencies.proc-macro2]
|
||||
|
|
|
@ -1813,14 +1813,14 @@ impl TranslationUnit {
|
|||
pub(crate) fn parse(
|
||||
ix: &Index,
|
||||
file: &str,
|
||||
cmd_args: &[String],
|
||||
cmd_args: &[Box<str>],
|
||||
unsaved: &[UnsavedFile],
|
||||
opts: CXTranslationUnit_Flags,
|
||||
) -> Option<TranslationUnit> {
|
||||
let fname = CString::new(file).unwrap();
|
||||
let _c_args: Vec<CString> = cmd_args
|
||||
.iter()
|
||||
.map(|s| CString::new(s.clone()).unwrap())
|
||||
.map(|s| CString::new(s.clone().into_boxed_bytes()).unwrap())
|
||||
.collect();
|
||||
let c_args: Vec<*const c_char> =
|
||||
_c_args.iter().map(|s| s.as_ptr()).collect();
|
||||
|
@ -1923,9 +1923,9 @@ pub(crate) struct UnsavedFile {
|
|||
|
||||
impl UnsavedFile {
|
||||
/// Construct a new unsaved file with the given `name` and `contents`.
|
||||
pub(crate) fn new(name: String, contents: String) -> UnsavedFile {
|
||||
let name = CString::new(name).unwrap();
|
||||
let contents = CString::new(contents).unwrap();
|
||||
pub(crate) fn new(name: &str, contents: &str) -> UnsavedFile {
|
||||
let name = CString::new(name.as_bytes()).unwrap();
|
||||
let contents = CString::new(contents.as_bytes()).unwrap();
|
||||
let x = CXUnsavedFile {
|
||||
Filename: name.as_ptr(),
|
||||
Contents: contents.as_ptr(),
|
||||
|
|
|
@ -601,7 +601,10 @@ impl CodeGenerator for Module {
|
|||
let inner_items = result.inner(|result| {
|
||||
result.push(root_import(ctx, item));
|
||||
|
||||
let path = item.namespace_aware_canonical_path(ctx).join("::");
|
||||
let path = item
|
||||
.namespace_aware_canonical_path(ctx)
|
||||
.join("::")
|
||||
.into_boxed_str();
|
||||
if let Some(raw_lines) = ctx.options().module_lines.get(&path) {
|
||||
for raw_line in raw_lines {
|
||||
found_any = true;
|
||||
|
@ -714,18 +717,18 @@ impl CodeGenerator for Var {
|
|||
let len = proc_macro2::Literal::usize_unsuffixed(
|
||||
cstr_bytes.len(),
|
||||
);
|
||||
let cstr = CStr::from_bytes_with_nul(&cstr_bytes).unwrap();
|
||||
|
||||
// TODO: Here we ignore the type we just made up, probably
|
||||
// we should refactor how the variable type and ty ID work.
|
||||
let array_ty = quote! { [u8; #len] };
|
||||
let cstr_ty = quote! { ::#prefix::ffi::CStr };
|
||||
|
||||
let bytes = proc_macro2::Literal::byte_string(
|
||||
cstr.to_bytes_with_nul(),
|
||||
);
|
||||
let bytes = proc_macro2::Literal::byte_string(&cstr_bytes);
|
||||
|
||||
if rust_features.const_cstr && options.generate_cstr {
|
||||
if options.generate_cstr &&
|
||||
rust_features.const_cstr &&
|
||||
CStr::from_bytes_with_nul(&cstr_bytes).is_ok()
|
||||
{
|
||||
result.push(quote! {
|
||||
#(#attrs)*
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -4348,7 +4351,7 @@ fn unsupported_abi_diagnostic(
|
|||
.add_annotation(
|
||||
format!(
|
||||
"The configured Rust version is {}.",
|
||||
String::from(ctx.options().rust_target)
|
||||
ctx.options().rust_target
|
||||
),
|
||||
Level::Note,
|
||||
);
|
||||
|
@ -4912,7 +4915,7 @@ pub(crate) mod utils {
|
|||
|
||||
let items = vec![use_objc, id_type];
|
||||
let old_items = mem::replace(result, items);
|
||||
result.extend(old_items.into_iter());
|
||||
result.extend(old_items);
|
||||
}
|
||||
|
||||
pub(crate) fn prepend_block_header(
|
||||
|
@ -4931,7 +4934,7 @@ pub(crate) mod utils {
|
|||
|
||||
let items = vec![use_block];
|
||||
let old_items = mem::replace(result, items);
|
||||
result.extend(old_items.into_iter());
|
||||
result.extend(old_items);
|
||||
}
|
||||
|
||||
pub(crate) fn prepend_union_types(
|
||||
|
@ -4990,7 +4993,7 @@ pub(crate) mod utils {
|
|||
impl<T> ::#prefix::clone::Clone for __BindgenUnionField<T> {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
Self::new()
|
||||
*self
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -5043,7 +5046,7 @@ pub(crate) mod utils {
|
|||
];
|
||||
|
||||
let old_items = mem::replace(result, items);
|
||||
result.extend(old_items.into_iter());
|
||||
result.extend(old_items);
|
||||
}
|
||||
|
||||
pub(crate) fn prepend_incomplete_array_types(
|
||||
|
@ -5119,7 +5122,7 @@ pub(crate) mod utils {
|
|||
];
|
||||
|
||||
let old_items = mem::replace(result, items);
|
||||
result.extend(old_items.into_iter());
|
||||
result.extend(old_items);
|
||||
}
|
||||
|
||||
pub(crate) fn prepend_complex_type(
|
||||
|
@ -5136,7 +5139,7 @@ pub(crate) mod utils {
|
|||
|
||||
let items = vec![complex_type];
|
||||
let old_items = mem::replace(result, items);
|
||||
result.extend(old_items.into_iter());
|
||||
result.extend(old_items);
|
||||
}
|
||||
|
||||
pub(crate) fn build_path(
|
||||
|
|
|
@ -8,11 +8,11 @@ pub(crate) struct DepfileSpec {
|
|||
}
|
||||
|
||||
impl DepfileSpec {
|
||||
pub fn write(&self, deps: &BTreeSet<String>) -> std::io::Result<()> {
|
||||
pub fn write(&self, deps: &BTreeSet<Box<str>>) -> std::io::Result<()> {
|
||||
std::fs::write(&self.depfile_path, self.to_string(deps))
|
||||
}
|
||||
|
||||
fn to_string(&self, deps: &BTreeSet<String>) -> String {
|
||||
fn to_string(&self, deps: &BTreeSet<Box<str>>) -> String {
|
||||
// Transforms a string by escaping spaces and backslashes.
|
||||
let escape = |s: &str| s.replace('\\', "\\\\").replace(' ', "\\ ");
|
||||
|
||||
|
@ -35,14 +35,14 @@ mod tests {
|
|||
depfile_path: PathBuf::new(),
|
||||
};
|
||||
|
||||
let deps: BTreeSet<String> = vec![
|
||||
r"/absolute/path".to_owned(),
|
||||
r"C:\win\absolute\path".to_owned(),
|
||||
r"../relative/path".to_owned(),
|
||||
r"..\win\relative\path".to_owned(),
|
||||
r"../path/with spaces/in/it".to_owned(),
|
||||
r"..\win\path\with spaces\in\it".to_owned(),
|
||||
r"path\with/mixed\separators".to_owned(),
|
||||
let deps: BTreeSet<_> = vec![
|
||||
r"/absolute/path".into(),
|
||||
r"C:\win\absolute\path".into(),
|
||||
r"../relative/path".into(),
|
||||
r"..\win\relative\path".into(),
|
||||
r"../path/with spaces/in/it".into(),
|
||||
r"..\win\path\with spaces\in\it".into(),
|
||||
r"path\with/mixed\separators".into(),
|
||||
]
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
/// Simple macro that forwards to assert! when using
|
||||
/// __testing_only_extra_assertions.
|
||||
#[macro_export]
|
||||
macro_rules! extra_assert {
|
||||
( $cond:expr ) => {
|
||||
if cfg!(feature = "__testing_only_extra_assertions") {
|
||||
|
@ -16,19 +15,3 @@ macro_rules! extra_assert {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Simple macro that forwards to assert_eq! when using
|
||||
/// __testing_only_extra_assertions.
|
||||
#[macro_export]
|
||||
macro_rules! extra_assert_eq {
|
||||
( $lhs:expr , $rhs:expr ) => {
|
||||
if cfg!(feature = "__testing_only_extra_assertions") {
|
||||
assert_eq!($lhs, $rhs);
|
||||
}
|
||||
};
|
||||
( $lhs:expr , $rhs:expr , $( $arg:tt )+ ) => {
|
||||
if cfg!(feature = "__testing_only_extra_assertions") {
|
||||
assert!($lhs, $rhs, $( $arg )* );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,266 +4,227 @@
|
|||
#![deny(clippy::missing_docs_in_private_items)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::io;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Define RustTarget struct definition, Default impl, and conversions
|
||||
/// between RustTarget and String.
|
||||
macro_rules! rust_target_def {
|
||||
( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => {
|
||||
/// This macro defines the [`RustTarget`] and [`RustFeatures`] types.
|
||||
macro_rules! define_rust_targets {
|
||||
(
|
||||
Nightly => {$($nightly_feature:ident $(: #$issue:literal)?),* $(,)?} $(,)?
|
||||
$(
|
||||
$(#[$attrs:meta])*
|
||||
$variant:ident($minor:literal) => {$($feature:ident $(: #$pull:literal)?),* $(,)?},
|
||||
)*
|
||||
$(,)?
|
||||
) => {
|
||||
/// Represents the version of the Rust language to target.
|
||||
///
|
||||
/// To support a beta release, use the corresponding stable release.
|
||||
///
|
||||
/// This enum will have more variants added as necessary.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Hash)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum RustTarget {
|
||||
/// Rust Nightly
|
||||
$(#[doc = concat!(
|
||||
"- [`", stringify!($nightly_feature), "`]",
|
||||
"(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")",
|
||||
)])*
|
||||
Nightly,
|
||||
$(
|
||||
$(
|
||||
#[$attr]
|
||||
)*
|
||||
$release,
|
||||
#[doc = concat!("Rust 1.", stringify!($minor))]
|
||||
$(#[doc = concat!(
|
||||
"- [`", stringify!($feature), "`]",
|
||||
"(", $("https://github.com/rust-lang/rust/pull/", stringify!($pull),)* ")",
|
||||
)])*
|
||||
$(#[$attrs])*
|
||||
$variant,
|
||||
)*
|
||||
}
|
||||
|
||||
impl Default for RustTarget {
|
||||
/// Gives the latest stable Rust version
|
||||
fn default() -> RustTarget {
|
||||
LATEST_STABLE_RUST
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for RustTarget {
|
||||
type Err = io::Error;
|
||||
|
||||
/// Create a `RustTarget` from a string.
|
||||
///
|
||||
/// * The stable/beta versions of Rust are of the form "1.0",
|
||||
/// "1.19", etc.
|
||||
/// * The nightly version should be specified with "nightly".
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.as_ref() {
|
||||
$(
|
||||
stringify!($value) => Ok(RustTarget::$release),
|
||||
)*
|
||||
_ => Err(
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
concat!(
|
||||
"Got an invalid rust target. Accepted values ",
|
||||
"are of the form ",
|
||||
"\"1.0\" or \"nightly\"."))),
|
||||
impl RustTarget {
|
||||
fn minor(self) -> Option<u64> {
|
||||
match self {
|
||||
$( Self::$variant => Some($minor),)*
|
||||
Self::Nightly => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RustTarget> for String {
|
||||
fn from(target: RustTarget) -> Self {
|
||||
match target {
|
||||
$(
|
||||
RustTarget::$release => stringify!($value),
|
||||
)*
|
||||
}.into()
|
||||
const fn stable_releases() -> [(Self, u64); [$($minor,)*].len()] {
|
||||
[$((Self::$variant, $minor),)*]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Defines an array slice with all RustTarget values
|
||||
macro_rules! rust_target_values_def {
|
||||
( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => {
|
||||
#[cfg(feature = "__cli")]
|
||||
/// Strings of allowed `RustTarget` values
|
||||
pub static RUST_TARGET_STRINGS: &'static [&str] = &[
|
||||
$(
|
||||
stringify!($value),
|
||||
)*
|
||||
];
|
||||
}
|
||||
}
|
||||
pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*];
|
||||
|
||||
/// Defines macro which takes a macro
|
||||
macro_rules! rust_target_base {
|
||||
( $x_macro:ident ) => {
|
||||
$x_macro!(
|
||||
/// Rust stable 1.0
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_0 => 1.0;
|
||||
/// Rust stable 1.17
|
||||
/// * Static lifetime elision ([RFC 1623](https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_17 => 1.17;
|
||||
/// Rust stable 1.19
|
||||
/// * Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_19 => 1.19;
|
||||
/// Rust stable 1.20
|
||||
/// * Associated constants ([PR](https://github.com/rust-lang/rust/pull/42809))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_20 => 1.20;
|
||||
/// Rust stable 1.21
|
||||
/// * Builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_21 => 1.21;
|
||||
/// Rust stable 1.25
|
||||
/// * `repr(align)` ([PR](https://github.com/rust-lang/rust/pull/47006))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_25 => 1.25;
|
||||
/// Rust stable 1.26
|
||||
/// * [i128 / u128 support](https://doc.rust-lang.org/std/primitive.i128.html)
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_26 => 1.26;
|
||||
/// Rust stable 1.27
|
||||
/// * `must_use` attribute on functions ([PR](https://github.com/rust-lang/rust/pull/48925))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_27 => 1.27;
|
||||
/// Rust stable 1.28
|
||||
/// * `repr(transparent)` ([PR](https://github.com/rust-lang/rust/pull/51562))
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_28 => 1.28;
|
||||
/// Rust stable 1.30
|
||||
/// * `const fn` support for limited cases ([PR](https://github.com/rust-lang/rust/pull/54835/)
|
||||
/// * [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html)
|
||||
#[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_30 => 1.30;
|
||||
/// Rust stable 1.33
|
||||
/// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049))
|
||||
=> Stable_1_33 => 1.33;
|
||||
/// Rust stable 1.36
|
||||
/// * `MaybeUninit` instead of `mem::uninitialized()` ([PR](https://github.com/rust-lang/rust/pull/60445))
|
||||
=> Stable_1_36 => 1.36;
|
||||
/// Rust stable 1.40
|
||||
/// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109))
|
||||
=> Stable_1_40 => 1.40;
|
||||
/// Rust stable 1.47
|
||||
/// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060))
|
||||
=> Stable_1_47 => 1.47;
|
||||
/// Rust stable 1.59
|
||||
/// * `CStr::from_bytes_with_nul_unchecked` in `const` contexts ([PR](https://github.com/rust-lang/rust/pull/54745))
|
||||
=> Stable_1_59 => 1.59;
|
||||
/// Rust stable 1.64
|
||||
/// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501))
|
||||
=> Stable_1_64 => 1.64;
|
||||
/// Rust stable 1.68
|
||||
/// * `abi_efiapi` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/65815))
|
||||
=> Stable_1_68 => 1.68;
|
||||
/// Nightly rust
|
||||
/// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202))
|
||||
/// * `vectorcall` calling convention (no tracking issue)
|
||||
/// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990))
|
||||
=> Nightly => nightly;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
rust_target_base!(rust_target_def);
|
||||
rust_target_base!(rust_target_values_def);
|
||||
|
||||
/// Latest stable release of Rust
|
||||
pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_68;
|
||||
|
||||
/// Create RustFeatures struct definition, new(), and a getter for each field
|
||||
macro_rules! rust_feature_def {
|
||||
(
|
||||
$( $rust_target:ident {
|
||||
$( $( #[$attr:meta] )* => $feature:ident; )*
|
||||
} )*
|
||||
) => {
|
||||
/// Features supported by a rust target
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
#[allow(missing_docs)] // Documentation should go into the relevant variants.
|
||||
pub(crate) struct RustFeatures {
|
||||
$( $(
|
||||
$(
|
||||
#[$attr]
|
||||
)*
|
||||
pub $feature: bool,
|
||||
)* )*
|
||||
}
|
||||
|
||||
impl RustFeatures {
|
||||
/// Gives a RustFeatures struct with all features disabled
|
||||
fn new() -> Self {
|
||||
RustFeatures {
|
||||
$( $(
|
||||
$feature: false,
|
||||
)* )*
|
||||
}
|
||||
}
|
||||
$($(pub(crate) $feature: bool,)*)*
|
||||
$(pub(crate) $nightly_feature: bool,)*
|
||||
}
|
||||
|
||||
impl From<RustTarget> for RustFeatures {
|
||||
fn from(rust_target: RustTarget) -> Self {
|
||||
let mut features = RustFeatures::new();
|
||||
|
||||
$(
|
||||
if rust_target >= RustTarget::$rust_target {
|
||||
$(
|
||||
features.$feature = true;
|
||||
)*
|
||||
fn from(target: RustTarget) -> Self {
|
||||
if target == RustTarget::Nightly {
|
||||
return Self {
|
||||
$($($feature: true,)*)*
|
||||
$($nightly_feature: true,)*
|
||||
};
|
||||
}
|
||||
)*
|
||||
|
||||
let mut features = Self {
|
||||
$($($feature: false,)*)*
|
||||
$($nightly_feature: false,)*
|
||||
};
|
||||
|
||||
$(if target >= RustTarget::$variant {
|
||||
$(features.$feature = true;)*
|
||||
})*
|
||||
|
||||
features
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// NOTE: When adding or removing features here, make sure to add the stabilization PR
|
||||
// number for the feature if it has been stabilized or the tracking issue number if the feature is
|
||||
// not stable.
|
||||
define_rust_targets! {
|
||||
Nightly => {
|
||||
thiscall_abi: #42202,
|
||||
vectorcall_abi,
|
||||
},
|
||||
Stable_1_71(71) => { c_unwind_abi: #106075 },
|
||||
Stable_1_68(68) => { abi_efiapi: #105795 },
|
||||
Stable_1_64(64) => { core_ffi_c: #94503 },
|
||||
Stable_1_59(59) => { const_cstr: #54745 },
|
||||
Stable_1_47(47) => { larger_arrays: #74060 },
|
||||
Stable_1_40(40) => { non_exhaustive: #44109 },
|
||||
Stable_1_36(36) => { maybe_uninit: #60445 },
|
||||
Stable_1_33(33) => { repr_packed_n: #57049 },
|
||||
#[deprecated]
|
||||
Stable_1_30(30) => {
|
||||
core_ffi_c_void: #53910,
|
||||
min_const_fn: #54835,
|
||||
},
|
||||
#[deprecated]
|
||||
Stable_1_28(28) => { repr_transparent: #51562 },
|
||||
#[deprecated]
|
||||
Stable_1_27(27) => { must_use_function: #48925 },
|
||||
#[deprecated]
|
||||
Stable_1_26(26) => { i128_and_u128: #49101 },
|
||||
#[deprecated]
|
||||
Stable_1_25(25) => { repr_align: #47006 },
|
||||
#[deprecated]
|
||||
Stable_1_21(21) => { builtin_clone_impls: #43690 },
|
||||
#[deprecated]
|
||||
Stable_1_20(20) => { associated_const: #42809 },
|
||||
#[deprecated]
|
||||
Stable_1_19(19) => { untagged_union: #42068 },
|
||||
#[deprecated]
|
||||
Stable_1_17(17) => { static_lifetime_elision: #39265 },
|
||||
#[deprecated]
|
||||
Stable_1_0(0) => {},
|
||||
}
|
||||
|
||||
/// Latest stable release of Rust
|
||||
pub const LATEST_STABLE_RUST: RustTarget = {
|
||||
// FIXME: replace all this code by
|
||||
// ```
|
||||
// RustTarget::stable_releases()
|
||||
// .into_iter()
|
||||
// .max_by_key(|(_, m)| m)
|
||||
// .map(|(t, _)| t)
|
||||
// .unwrap_or(RustTarget::Nightly)
|
||||
// ```
|
||||
// once those operations can be used in constants.
|
||||
let targets = RustTarget::stable_releases();
|
||||
|
||||
let mut i = 0;
|
||||
let mut latest_target = None;
|
||||
let mut latest_minor = 0;
|
||||
|
||||
while i < targets.len() {
|
||||
let (target, minor) = targets[i];
|
||||
|
||||
if latest_minor < minor {
|
||||
latest_minor = minor;
|
||||
latest_target = Some(target);
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
match latest_target {
|
||||
Some(target) => target,
|
||||
None => unreachable!(),
|
||||
}
|
||||
};
|
||||
|
||||
impl Default for RustTarget {
|
||||
fn default() -> Self {
|
||||
LATEST_STABLE_RUST
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(emilio): When adding or removing features here, make sure to update the
|
||||
// documentation for the relevant variant in the rust_target_base macro
|
||||
// definition.
|
||||
rust_feature_def!(
|
||||
Stable_1_17 {
|
||||
=> static_lifetime_elision;
|
||||
impl PartialOrd for RustTarget {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
Stable_1_19 {
|
||||
=> untagged_union;
|
||||
}
|
||||
|
||||
impl Ord for RustTarget {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
match (self.minor(), other.minor()) {
|
||||
(Some(a), Some(b)) => a.cmp(&b),
|
||||
(Some(_), None) => Ordering::Less,
|
||||
(None, Some(_)) => Ordering::Greater,
|
||||
(None, None) => Ordering::Equal,
|
||||
}
|
||||
}
|
||||
Stable_1_20 {
|
||||
=> associated_const;
|
||||
}
|
||||
|
||||
impl FromStr for RustTarget {
|
||||
type Err = io::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
if s == "nightly" {
|
||||
return Ok(Self::Nightly);
|
||||
}
|
||||
|
||||
if let Some(("1", str_minor)) = s.split_once('.') {
|
||||
if let Ok(minor) = str_minor.parse::<u64>() {
|
||||
for (target, target_minor) in Self::stable_releases() {
|
||||
if minor == target_minor {
|
||||
return Ok(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"Got an invalid Rust target. Accepted values are of the form \"1.71\" or \"nightly\"."
|
||||
))
|
||||
}
|
||||
Stable_1_21 {
|
||||
=> builtin_clone_impls;
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RustTarget {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self.minor() {
|
||||
Some(minor) => write!(f, "1.{}", minor),
|
||||
None => "nightly".fmt(f),
|
||||
}
|
||||
}
|
||||
Stable_1_25 {
|
||||
=> repr_align;
|
||||
}
|
||||
Stable_1_26 {
|
||||
=> i128_and_u128;
|
||||
}
|
||||
Stable_1_27 {
|
||||
=> must_use_function;
|
||||
}
|
||||
Stable_1_28 {
|
||||
=> repr_transparent;
|
||||
}
|
||||
Stable_1_30 {
|
||||
=> min_const_fn;
|
||||
=> core_ffi_c_void;
|
||||
}
|
||||
Stable_1_33 {
|
||||
=> repr_packed_n;
|
||||
}
|
||||
Stable_1_36 {
|
||||
=> maybe_uninit;
|
||||
}
|
||||
Stable_1_40 {
|
||||
=> non_exhaustive;
|
||||
}
|
||||
Stable_1_47 {
|
||||
=> larger_arrays;
|
||||
}
|
||||
Stable_1_59 {
|
||||
=> const_cstr;
|
||||
}
|
||||
Stable_1_64 {
|
||||
=> core_ffi_c;
|
||||
}
|
||||
Stable_1_68 {
|
||||
=> abi_efiapi;
|
||||
}
|
||||
Nightly {
|
||||
=> thiscall_abi;
|
||||
=> vectorcall_abi;
|
||||
=> c_unwind_abi;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
impl Default for RustFeatures {
|
||||
fn default() -> Self {
|
||||
let default_rust_target: RustTarget = Default::default();
|
||||
Self::from(default_rust_target)
|
||||
RustTarget::default().into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,6 +257,12 @@ mod test {
|
|||
!f_1_21.thiscall_abi &&
|
||||
!f_1_21.vectorcall_abi
|
||||
);
|
||||
let features = RustFeatures::from(RustTarget::Stable_1_71);
|
||||
assert!(
|
||||
features.c_unwind_abi &&
|
||||
features.abi_efiapi &&
|
||||
!features.thiscall_abi
|
||||
);
|
||||
let f_nightly = RustFeatures::from(RustTarget::Nightly);
|
||||
assert!(
|
||||
f_nightly.static_lifetime_elision &&
|
||||
|
@ -306,13 +273,12 @@ mod test {
|
|||
f_nightly.maybe_uninit &&
|
||||
f_nightly.repr_align &&
|
||||
f_nightly.thiscall_abi &&
|
||||
f_nightly.vectorcall_abi &&
|
||||
f_nightly.c_unwind_abi
|
||||
f_nightly.vectorcall_abi
|
||||
);
|
||||
}
|
||||
|
||||
fn test_target(target_str: &str, target: RustTarget) {
|
||||
let target_string: String = target.into();
|
||||
let target_string = target.to_string();
|
||||
assert_eq!(target_str, target_string);
|
||||
assert_eq!(target, RustTarget::from_str(target_str).unwrap());
|
||||
}
|
||||
|
@ -324,6 +290,7 @@ mod test {
|
|||
test_target("1.19", RustTarget::Stable_1_19);
|
||||
test_target("1.21", RustTarget::Stable_1_21);
|
||||
test_target("1.25", RustTarget::Stable_1_25);
|
||||
test_target("1.71", RustTarget::Stable_1_71);
|
||||
test_target("nightly", RustTarget::Nightly);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ pub(crate) struct BindgenContext {
|
|||
includes: StdHashMap<String, (String, usize)>,
|
||||
|
||||
/// A set of all the included filenames.
|
||||
deps: BTreeSet<String>,
|
||||
deps: BTreeSet<Box<str>>,
|
||||
|
||||
/// The active replacements collected from replaces="xxx" annotations.
|
||||
replacements: HashMap<Vec<String>, ItemId>,
|
||||
|
@ -664,12 +664,12 @@ If you encounter an error missing from this list, please file an issue or a PR!"
|
|||
}
|
||||
|
||||
/// Add an included file.
|
||||
pub(crate) fn add_dep(&mut self, dep: String) {
|
||||
pub(crate) fn add_dep(&mut self, dep: Box<str>) {
|
||||
self.deps.insert(dep);
|
||||
}
|
||||
|
||||
/// Get any included files.
|
||||
pub(crate) fn deps(&self) -> &BTreeSet<String> {
|
||||
pub(crate) fn deps(&self) -> &BTreeSet<Box<str>> {
|
||||
&self.deps
|
||||
}
|
||||
|
||||
|
@ -2343,7 +2343,8 @@ If you encounter an error missing from this list, please file an issue or a PR!"
|
|||
if self.options().allowlisted_types.is_empty() &&
|
||||
self.options().allowlisted_functions.is_empty() &&
|
||||
self.options().allowlisted_vars.is_empty() &&
|
||||
self.options().allowlisted_files.is_empty()
|
||||
self.options().allowlisted_files.is_empty() &&
|
||||
self.options().allowlisted_items.is_empty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -2373,6 +2374,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
|
|||
|
||||
let name = item.path_for_allowlisting(self)[1..].join("::");
|
||||
debug!("allowlisted_items: testing {:?}", name);
|
||||
|
||||
if self.options().allowlisted_items.matches(&name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
match *item.kind() {
|
||||
ItemKind::Module(..) => true,
|
||||
ItemKind::Function(_) => {
|
||||
|
@ -2496,6 +2502,10 @@ If you encounter an error missing from this list, please file an issue or a PR!"
|
|||
for item in self.options().allowlisted_types.unmatched_items() {
|
||||
unused_regex_diagnostic(item, "--allowlist-type", self);
|
||||
}
|
||||
|
||||
for item in self.options().allowlisted_items.unmatched_items() {
|
||||
unused_regex_diagnostic(item, "--allowlist-items", self);
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenient method for getting the prefix to use for most traits in
|
||||
|
|
|
@ -190,6 +190,8 @@ pub enum Abi {
|
|||
Win64,
|
||||
/// The "C-unwind" ABI.
|
||||
CUnwind,
|
||||
/// The "system" ABI.
|
||||
System,
|
||||
}
|
||||
|
||||
impl FromStr for Abi {
|
||||
|
@ -206,6 +208,7 @@ impl FromStr for Abi {
|
|||
"aapcs" => Ok(Self::Aapcs),
|
||||
"win64" => Ok(Self::Win64),
|
||||
"C-unwind" => Ok(Self::CUnwind),
|
||||
"system" => Ok(Self::System),
|
||||
_ => Err(format!("Invalid or unknown ABI {:?}", s)),
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +226,7 @@ impl std::fmt::Display for Abi {
|
|||
Self::Aapcs => "aapcs",
|
||||
Self::Win64 => "win64",
|
||||
Self::CUnwind => "C-unwind",
|
||||
Abi::System => "system",
|
||||
};
|
||||
|
||||
s.fmt(f)
|
||||
|
|
|
@ -1465,7 +1465,7 @@ impl Item {
|
|||
cb.include_file(&included_file);
|
||||
}
|
||||
|
||||
ctx.add_dep(included_file);
|
||||
ctx.add_dep(included_file.into_boxed_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,15 +257,21 @@ impl ObjCMethod {
|
|||
if name.is_empty() {
|
||||
None
|
||||
} else {
|
||||
// Try to parse the current name as an identifier. This might fail if the
|
||||
// name is a keyword so we try to prepend "r#" to it and parse again. If
|
||||
// this also fails, we panic with the first error.
|
||||
// Try to parse the current name as an identifier. This might fail if the name
|
||||
// is a keyword, so we try to "r#" to it and parse again, this could also fail
|
||||
// if the name is `crate`, `self`, `super` or `Self`, so we try to add the `_`
|
||||
// suffix to it and parse again. If this also fails, we panic with the first
|
||||
// error.
|
||||
Some(
|
||||
syn::parse_str::<Ident>(name)
|
||||
.or_else(|err| {
|
||||
syn::parse_str::<Ident>(&format!("r#{}", name))
|
||||
.map_err(|_| err)
|
||||
})
|
||||
.or_else(|err| {
|
||||
syn::parse_str::<Ident>(&format!("{}_", name))
|
||||
.map_err(|_| err)
|
||||
})
|
||||
.expect("Invalid identifier"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -210,9 +210,10 @@ impl Type {
|
|||
self.layout.or_else(|| {
|
||||
match self.kind {
|
||||
TypeKind::Comp(ref ci) => ci.layout(ctx),
|
||||
TypeKind::Array(inner, length) if length == 0 => Some(
|
||||
Layout::new(0, ctx.resolve_type(inner).layout(ctx)?.align),
|
||||
),
|
||||
TypeKind::Array(inner, 0) => Some(Layout::new(
|
||||
0,
|
||||
ctx.resolve_type(inner).layout(ctx)?.align,
|
||||
)),
|
||||
// FIXME(emilio): This is a hack for anonymous union templates.
|
||||
// Use the actual pointer size!
|
||||
TypeKind::Pointer(..) => Some(Layout::new(
|
||||
|
|
|
@ -52,7 +52,9 @@ mod regex_set;
|
|||
pub use codegen::{
|
||||
AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle,
|
||||
};
|
||||
pub use features::{RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS};
|
||||
#[cfg(feature = "__cli")]
|
||||
pub use features::RUST_TARGET_STRINGS;
|
||||
pub use features::{RustTarget, LATEST_STABLE_RUST};
|
||||
pub use ir::annotations::FieldVisibilityKind;
|
||||
pub use ir::function::Abi;
|
||||
pub use regex_set::RegexSet;
|
||||
|
@ -92,15 +94,15 @@ fn file_is_cpp(name_file: &str) -> bool {
|
|||
name_file.ends_with(".h++")
|
||||
}
|
||||
|
||||
fn args_are_cpp(clang_args: &[String]) -> bool {
|
||||
fn args_are_cpp(clang_args: &[Box<str>]) -> bool {
|
||||
for w in clang_args.windows(2) {
|
||||
if w[0] == "-xc++" || w[1] == "-xc++" {
|
||||
if w[0].as_ref() == "-xc++" || w[1].as_ref() == "-xc++" {
|
||||
return true;
|
||||
}
|
||||
if w[0] == "-x" && w[1] == "c++" {
|
||||
if w[0].as_ref() == "-x" && w[1].as_ref() == "c++" {
|
||||
return true;
|
||||
}
|
||||
if w[0] == "-include" && file_is_cpp(&w[1]) {
|
||||
if w[0].as_ref() == "-include" && file_is_cpp(w[1].as_ref()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -263,9 +265,9 @@ impl std::fmt::Display for Formatter {
|
|||
///
|
||||
/// # Regular expression arguments
|
||||
///
|
||||
/// Some [`Builder`] methods such as the `allowlist_*` and `blocklist_*` methods allow regular
|
||||
/// Some [`Builder`] methods, such as `allowlist_*` and `blocklist_*`, allow regular
|
||||
/// expressions as arguments. These regular expressions will be enclosed in parentheses and
|
||||
/// anchored with `^` and `$`. So if the argument passed is `<regex>`, the regular expression to be
|
||||
/// anchored with `^` and `$`. So, if the argument passed is `<regex>`, the regular expression to be
|
||||
/// stored will be `^(<regex>)$`.
|
||||
///
|
||||
/// As a consequence, regular expressions passed to `bindgen` will try to match the whole name of
|
||||
|
@ -273,16 +275,16 @@ impl std::fmt::Display for Formatter {
|
|||
/// `prefix`, the `prefix.*` regular expression must be used.
|
||||
///
|
||||
/// Certain methods, like [`Builder::allowlist_function`], use regular expressions over function
|
||||
/// names. To match C++ methods, prefix the name of the type where they belong followed by an
|
||||
/// underscore. So if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar`
|
||||
/// names. To match C++ methods, prefix the name of the type where they belong, followed by an
|
||||
/// underscore. So, if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar`
|
||||
/// regular expression.
|
||||
///
|
||||
/// Additionally, Objective-C interfaces can be matched by prefixing the regular expression with
|
||||
/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface and the `IFoo_foo`
|
||||
/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface, and the `IFoo_foo`
|
||||
/// regular expression matches the `foo` method of the `Foo` interface.
|
||||
///
|
||||
/// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard
|
||||
/// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*`
|
||||
/// pattern `*` as a valid regular expression. This behavior has been deprecated, and the `.*`
|
||||
/// regular expression must be used instead.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Builder {
|
||||
|
@ -317,22 +319,26 @@ impl Builder {
|
|||
/// Generate the Rust bindings using the options built up thus far.
|
||||
pub fn generate(mut self) -> Result<Bindings, BindgenError> {
|
||||
// Add any extra arguments from the environment to the clang command line.
|
||||
self.options
|
||||
.clang_args
|
||||
.extend(get_extra_clang_args(&self.options.parse_callbacks));
|
||||
self.options.clang_args.extend(
|
||||
get_extra_clang_args(&self.options.parse_callbacks)
|
||||
.into_iter()
|
||||
.map(String::into_boxed_str),
|
||||
);
|
||||
|
||||
// Transform input headers to arguments on the clang command line.
|
||||
self.options.clang_args.extend(
|
||||
self.options.input_headers
|
||||
[..self.options.input_headers.len().saturating_sub(1)]
|
||||
.iter()
|
||||
.flat_map(|header| ["-include".into(), header.to_string()]),
|
||||
.flat_map(|header| ["-include".into(), header.clone()]),
|
||||
);
|
||||
|
||||
let input_unsaved_files =
|
||||
std::mem::take(&mut self.options.input_header_contents)
|
||||
.into_iter()
|
||||
.map(|(name, contents)| clang::UnsavedFile::new(name, contents))
|
||||
.map(|(name, contents)| {
|
||||
clang::UnsavedFile::new(name.as_ref(), contents.as_ref())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Bindings::generate(self.options, input_unsaved_files)
|
||||
|
@ -399,7 +405,7 @@ impl Builder {
|
|||
.stdout(Stdio::piped());
|
||||
|
||||
for a in &self.options.clang_args {
|
||||
cmd.arg(a);
|
||||
cmd.arg(a.as_ref());
|
||||
}
|
||||
|
||||
for a in get_extra_clang_args(&self.options.parse_callbacks) {
|
||||
|
@ -429,18 +435,19 @@ impl Builder {
|
|||
|
||||
impl BindgenOptions {
|
||||
fn build(&mut self) {
|
||||
const REGEX_SETS_LEN: usize = 27;
|
||||
const REGEX_SETS_LEN: usize = 28;
|
||||
|
||||
let regex_sets: [_; REGEX_SETS_LEN] = [
|
||||
&mut self.allowlisted_vars,
|
||||
&mut self.allowlisted_types,
|
||||
&mut self.allowlisted_functions,
|
||||
&mut self.allowlisted_files,
|
||||
&mut self.blocklisted_types,
|
||||
&mut self.blocklisted_functions,
|
||||
&mut self.blocklisted_items,
|
||||
&mut self.blocklisted_files,
|
||||
&mut self.opaque_types,
|
||||
&mut self.allowlisted_vars,
|
||||
&mut self.allowlisted_types,
|
||||
&mut self.allowlisted_functions,
|
||||
&mut self.allowlisted_files,
|
||||
&mut self.allowlisted_items,
|
||||
&mut self.bitfield_enums,
|
||||
&mut self.constified_enums,
|
||||
&mut self.constified_enum_modules,
|
||||
|
@ -476,6 +483,7 @@ impl BindgenOptions {
|
|||
"--allowlist-function",
|
||||
"--allowlist-var",
|
||||
"--allowlist-file",
|
||||
"--allowlist-item",
|
||||
"--bitfield-enum",
|
||||
"--newtype-enum",
|
||||
"--newtype-global-enum",
|
||||
|
@ -568,8 +576,7 @@ impl BindgenOptions {
|
|||
}
|
||||
|
||||
fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) {
|
||||
let target = String::from(target);
|
||||
warn!("The {} Rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target,);
|
||||
warn!("The {} Rust target is deprecated. If you have a need to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target);
|
||||
|
||||
#[cfg(feature = "experimental")]
|
||||
if _options.emit_diagnostics {
|
||||
|
@ -667,16 +674,16 @@ pub(crate) const HOST_TARGET: &str =
|
|||
|
||||
// Some architecture triplets are different between rust and libclang, see #1211
|
||||
// and duplicates.
|
||||
fn rust_to_clang_target(rust_target: &str) -> String {
|
||||
fn rust_to_clang_target(rust_target: &str) -> Box<str> {
|
||||
if rust_target.starts_with("aarch64-apple-") {
|
||||
let mut clang_target = "arm64-apple-".to_owned();
|
||||
clang_target
|
||||
.push_str(rust_target.strip_prefix("aarch64-apple-").unwrap());
|
||||
return clang_target;
|
||||
return clang_target.into();
|
||||
} else if rust_target.starts_with("riscv64gc-") {
|
||||
let mut clang_target = "riscv64-".to_owned();
|
||||
clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap());
|
||||
return clang_target;
|
||||
return clang_target.into();
|
||||
} else if rust_target.ends_with("-espidf") {
|
||||
let mut clang_target =
|
||||
rust_target.strip_suffix("-espidf").unwrap().to_owned();
|
||||
|
@ -685,32 +692,32 @@ fn rust_to_clang_target(rust_target: &str) -> String {
|
|||
clang_target = "riscv32-".to_owned() +
|
||||
clang_target.strip_prefix("riscv32imc-").unwrap();
|
||||
}
|
||||
return clang_target;
|
||||
return clang_target.into();
|
||||
} else if rust_target.starts_with("riscv32imc-") {
|
||||
let mut clang_target = "riscv32-".to_owned();
|
||||
clang_target.push_str(rust_target.strip_prefix("riscv32imc-").unwrap());
|
||||
return clang_target;
|
||||
return clang_target.into();
|
||||
} else if rust_target.starts_with("riscv32imac-") {
|
||||
let mut clang_target = "riscv32-".to_owned();
|
||||
clang_target
|
||||
.push_str(rust_target.strip_prefix("riscv32imac-").unwrap());
|
||||
return clang_target;
|
||||
return clang_target.into();
|
||||
}
|
||||
rust_target.to_owned()
|
||||
rust_target.into()
|
||||
}
|
||||
|
||||
/// Returns the effective target, and whether it was explicitly specified on the
|
||||
/// clang flags.
|
||||
fn find_effective_target(clang_args: &[String]) -> (String, bool) {
|
||||
fn find_effective_target(clang_args: &[Box<str>]) -> (Box<str>, bool) {
|
||||
let mut args = clang_args.iter();
|
||||
while let Some(opt) = args.next() {
|
||||
if opt.starts_with("--target=") {
|
||||
let mut split = opt.split('=');
|
||||
split.next();
|
||||
return (split.next().unwrap().to_owned(), true);
|
||||
return (split.next().unwrap().into(), true);
|
||||
}
|
||||
|
||||
if opt == "-target" {
|
||||
if opt.as_ref() == "-target" {
|
||||
if let Some(target) = args.next() {
|
||||
return (target.clone(), true);
|
||||
}
|
||||
|
@ -755,9 +762,10 @@ impl Bindings {
|
|||
// opening libclang.so, it has to be the same architecture and thus the
|
||||
// check is fine.
|
||||
if !explicit_target && !is_host_build {
|
||||
options
|
||||
.clang_args
|
||||
.insert(0, format!("--target={}", effective_target));
|
||||
options.clang_args.insert(
|
||||
0,
|
||||
format!("--target={}", effective_target).into_boxed_str(),
|
||||
);
|
||||
};
|
||||
|
||||
fn detect_include_paths(options: &mut BindgenOptions) {
|
||||
|
@ -778,7 +786,7 @@ impl Bindings {
|
|||
return false;
|
||||
}
|
||||
|
||||
let arg = &**arg;
|
||||
let arg = arg.as_ref();
|
||||
|
||||
// https://clang.llvm.org/docs/ClangCommandLineReference.html
|
||||
// -isystem and -isystem-after are harmless.
|
||||
|
@ -795,7 +803,7 @@ impl Bindings {
|
|||
|
||||
true
|
||||
})
|
||||
.cloned()
|
||||
.map(|arg| arg.clone().into())
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
|
@ -827,8 +835,8 @@ impl Bindings {
|
|||
if let Some(search_paths) = search_paths {
|
||||
for path in search_paths.into_iter() {
|
||||
if let Ok(path) = path.into_os_string().into_string() {
|
||||
options.clang_args.push("-isystem".to_owned());
|
||||
options.clang_args.push(path);
|
||||
options.clang_args.push("-isystem".into());
|
||||
options.clang_args.push(path.into_boxed_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -848,7 +856,7 @@ impl Bindings {
|
|||
}
|
||||
|
||||
if let Some(h) = options.input_headers.last() {
|
||||
let path = Path::new(h);
|
||||
let path = Path::new(h.as_ref());
|
||||
if let Ok(md) = std::fs::metadata(path) {
|
||||
if md.is_dir() {
|
||||
return Err(BindgenError::FolderAsHeader(path.into()));
|
||||
|
@ -858,8 +866,7 @@ impl Bindings {
|
|||
path.into(),
|
||||
));
|
||||
}
|
||||
let h = h.clone();
|
||||
options.clang_args.push(h);
|
||||
options.clang_args.push(h.clone());
|
||||
} else {
|
||||
return Err(BindgenError::NotExist(path.into()));
|
||||
}
|
||||
|
@ -867,9 +874,9 @@ impl Bindings {
|
|||
|
||||
for (idx, f) in input_unsaved_files.iter().enumerate() {
|
||||
if idx != 0 || !options.input_headers.is_empty() {
|
||||
options.clang_args.push("-include".to_owned());
|
||||
options.clang_args.push("-include".into());
|
||||
}
|
||||
options.clang_args.push(f.name.to_str().unwrap().to_owned())
|
||||
options.clang_args.push(f.name.to_str().unwrap().into())
|
||||
}
|
||||
|
||||
debug!("Fixed-up options: {:?}", options);
|
||||
|
@ -912,10 +919,10 @@ impl Bindings {
|
|||
/// Write these bindings as source text to the given `Write`able.
|
||||
pub fn write<'a>(&self, mut writer: Box<dyn Write + 'a>) -> io::Result<()> {
|
||||
if !self.options.disable_header_comment {
|
||||
let version = option_env!("CARGO_PKG_VERSION");
|
||||
let version =
|
||||
option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)");
|
||||
let header = format!(
|
||||
"/* automatically generated by rust-bindgen {} */\n\n",
|
||||
version.unwrap_or("(unknown version)")
|
||||
"/* automatically generated by rust-bindgen {version} */\n\n",
|
||||
);
|
||||
writer.write_all(header.as_bytes())?;
|
||||
}
|
||||
|
@ -1244,7 +1251,7 @@ fn commandline_flag_unit_test_function() {
|
|||
let bindings = crate::builder();
|
||||
let command_line_flags = bindings.command_line_flags();
|
||||
|
||||
let test_cases = vec![
|
||||
let test_cases = [
|
||||
"--rust-target",
|
||||
"--no-derive-default",
|
||||
"--generate",
|
||||
|
@ -1263,7 +1270,7 @@ fn commandline_flag_unit_test_function() {
|
|||
.allowlist_function("safe_function");
|
||||
|
||||
let command_line_flags = bindings.command_line_flags();
|
||||
let test_cases = vec![
|
||||
let test_cases = [
|
||||
"--rust-target",
|
||||
"input_header",
|
||||
"--no-derive-default",
|
||||
|
@ -1284,21 +1291,24 @@ fn commandline_flag_unit_test_function() {
|
|||
|
||||
#[test]
|
||||
fn test_rust_to_clang_target() {
|
||||
assert_eq!(rust_to_clang_target("aarch64-apple-ios"), "arm64-apple-ios");
|
||||
assert_eq!(
|
||||
rust_to_clang_target("aarch64-apple-ios").as_ref(),
|
||||
"arm64-apple-ios"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rust_to_clang_target_riscv() {
|
||||
assert_eq!(
|
||||
rust_to_clang_target("riscv64gc-unknown-linux-gnu"),
|
||||
rust_to_clang_target("riscv64gc-unknown-linux-gnu").as_ref(),
|
||||
"riscv64-unknown-linux-gnu"
|
||||
);
|
||||
assert_eq!(
|
||||
rust_to_clang_target("riscv32imc-unknown-none-elf"),
|
||||
rust_to_clang_target("riscv32imc-unknown-none-elf").as_ref(),
|
||||
"riscv32-unknown-none-elf"
|
||||
);
|
||||
assert_eq!(
|
||||
rust_to_clang_target("riscv32imac-unknown-none-elf"),
|
||||
rust_to_clang_target("riscv32imac-unknown-none-elf").as_ref(),
|
||||
"riscv32-unknown-none-elf"
|
||||
);
|
||||
}
|
||||
|
@ -1306,11 +1316,11 @@ fn test_rust_to_clang_target_riscv() {
|
|||
#[test]
|
||||
fn test_rust_to_clang_target_espidf() {
|
||||
assert_eq!(
|
||||
rust_to_clang_target("riscv32imc-esp-espidf"),
|
||||
rust_to_clang_target("riscv32imc-esp-espidf").as_ref(),
|
||||
"riscv32-esp-elf"
|
||||
);
|
||||
assert_eq!(
|
||||
rust_to_clang_target("xtensa-esp32-espidf"),
|
||||
rust_to_clang_target("xtensa-esp32-espidf").as_ref(),
|
||||
"xtensa-esp32-elf"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ impl AsArgs for bool {
|
|||
impl AsArgs for RegexSet {
|
||||
fn as_args(&self, args: &mut Vec<String>, flag: &str) {
|
||||
for item in self.get_items() {
|
||||
args.extend_from_slice(&[flag.to_owned(), item.clone()]);
|
||||
args.extend_from_slice(&[flag.to_owned(), item.clone().into()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ macro_rules! options {
|
|||
let headers = match self.options.input_headers.split_last() {
|
||||
Some((header, headers)) => {
|
||||
// The last input header is passed as an argument in the first position.
|
||||
args.push(header.clone());
|
||||
args.push(header.clone().into());
|
||||
headers
|
||||
},
|
||||
None => &[]
|
||||
|
@ -135,13 +135,13 @@ macro_rules! options {
|
|||
args.push("--".to_owned());
|
||||
|
||||
if !self.options.clang_args.is_empty() {
|
||||
args.extend_from_slice(&self.options.clang_args);
|
||||
args.extend(self.options.clang_args.iter().map(|s| s.clone().into()));
|
||||
}
|
||||
|
||||
// We need to pass all but the last header via the `-include` clang argument.
|
||||
for header in headers {
|
||||
args.push("-include".to_owned());
|
||||
args.push(header.clone());
|
||||
args.push(header.clone().into());
|
||||
}
|
||||
|
||||
args
|
||||
|
@ -345,6 +345,23 @@ options! {
|
|||
},
|
||||
as_args: "--allowlist-file",
|
||||
},
|
||||
/// Items that have been allowlisted and should appear in the generated code.
|
||||
allowlisted_items: RegexSet {
|
||||
methods: {
|
||||
regex_option! {
|
||||
/// Generate bindings for the given item, regardless of whether it is a type,
|
||||
/// function, module, etc.
|
||||
///
|
||||
/// This option is transitive by default. Check the documentation of the
|
||||
/// [`Builder::allowlist_recursively`] method for further information.
|
||||
pub fn allowlist_item<T: AsRef<str>>(mut self, arg: T) -> Builder {
|
||||
self.options.allowlisted_items.insert(arg);
|
||||
self
|
||||
}
|
||||
}
|
||||
},
|
||||
as_args: "--allowlist-item",
|
||||
},
|
||||
/// The default style of for generated `enum`s.
|
||||
default_enum_style: EnumVariation {
|
||||
methods: {
|
||||
|
@ -1072,24 +1089,24 @@ options! {
|
|||
as_args: |value, args| (!value).as_args(args, "--no-convert-floats"),
|
||||
},
|
||||
/// The set of raw lines to be prepended to the top-level module of the generated Rust code.
|
||||
raw_lines: Vec<String> {
|
||||
raw_lines: Vec<Box<str>> {
|
||||
methods: {
|
||||
/// Add a line of Rust code at the beginning of the generated bindings. The string is
|
||||
/// passed through without any modification.
|
||||
pub fn raw_line<T: Into<String>>(mut self, arg: T) -> Self {
|
||||
self.options.raw_lines.push(arg.into());
|
||||
self.options.raw_lines.push(arg.into().into_boxed_str());
|
||||
self
|
||||
}
|
||||
},
|
||||
as_args: |raw_lines, args| {
|
||||
for line in raw_lines {
|
||||
args.push("--raw-line".to_owned());
|
||||
args.push(line.clone());
|
||||
args.push(line.clone().into());
|
||||
}
|
||||
},
|
||||
},
|
||||
/// The set of raw lines to prepend to different modules.
|
||||
module_lines: HashMap<String, Vec<String>> {
|
||||
module_lines: HashMap<Box<str>, Vec<Box<str>>> {
|
||||
methods: {
|
||||
/// Add a given line to the beginning of a given module.
|
||||
///
|
||||
|
@ -1102,9 +1119,9 @@ options! {
|
|||
{
|
||||
self.options
|
||||
.module_lines
|
||||
.entry(module.into())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(line.into());
|
||||
.entry(module.into().into_boxed_str())
|
||||
.or_default()
|
||||
.push(line.into().into_boxed_str());
|
||||
self
|
||||
}
|
||||
},
|
||||
|
@ -1112,14 +1129,14 @@ options! {
|
|||
for (module, lines) in module_lines {
|
||||
for line in lines.iter() {
|
||||
args.push("--module-raw-line".to_owned());
|
||||
args.push(module.clone());
|
||||
args.push(line.clone());
|
||||
args.push(module.clone().into());
|
||||
args.push(line.clone().into());
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
/// The input header files.
|
||||
input_headers: Vec<String> {
|
||||
input_headers: Vec<Box<str>> {
|
||||
methods: {
|
||||
/// Add an input C/C++ header to generate bindings for.
|
||||
///
|
||||
|
@ -1143,7 +1160,7 @@ options! {
|
|||
/// .unwrap();
|
||||
/// ```
|
||||
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
|
||||
self.options.input_headers.push(header.into());
|
||||
self.options.input_headers.push(header.into().into_boxed_str());
|
||||
self
|
||||
}
|
||||
},
|
||||
|
@ -1151,11 +1168,11 @@ options! {
|
|||
as_args: ignore,
|
||||
},
|
||||
/// The set of arguments to be passed straight through to Clang.
|
||||
clang_args: Vec<String> {
|
||||
clang_args: Vec<Box<str>> {
|
||||
methods: {
|
||||
/// Add an argument to be passed straight through to Clang.
|
||||
pub fn clang_arg<T: Into<String>>(self, arg: T) -> Builder {
|
||||
self.clang_args([arg.into()])
|
||||
self.clang_args([arg.into().into_boxed_str()])
|
||||
}
|
||||
|
||||
/// Add several arguments to be passed straight through to Clang.
|
||||
|
@ -1164,7 +1181,7 @@ options! {
|
|||
I::Item: AsRef<str>,
|
||||
{
|
||||
for arg in args {
|
||||
self.options.clang_args.push(arg.as_ref().to_owned());
|
||||
self.options.clang_args.push(arg.as_ref().to_owned().into_boxed_str());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
@ -1173,7 +1190,7 @@ options! {
|
|||
as_args: ignore,
|
||||
},
|
||||
/// Tuples of unsaved file contents of the form (name, contents).
|
||||
input_header_contents: Vec<(String, String)> {
|
||||
input_header_contents: Vec<(Box<str>, Box<str>)> {
|
||||
methods: {
|
||||
/// Add `contents` as an input C/C++ header named `name`.
|
||||
///
|
||||
|
@ -1187,7 +1204,7 @@ options! {
|
|||
.join(name)
|
||||
.to_str()
|
||||
.expect("Cannot convert current directory name to string")
|
||||
.to_owned();
|
||||
.into();
|
||||
self.options
|
||||
.input_header_contents
|
||||
.push((absolute_path, contents.into()));
|
||||
|
@ -1543,7 +1560,7 @@ options! {
|
|||
},
|
||||
as_args: |rust_target, args| {
|
||||
args.push("--rust-target".to_owned());
|
||||
args.push((*rust_target).into());
|
||||
args.push(rust_target.to_string());
|
||||
},
|
||||
},
|
||||
/// Features to be enabled. They are derived from `rust_target`.
|
||||
|
@ -1589,6 +1606,9 @@ options! {
|
|||
methods: {
|
||||
/// Set whether `size_t` should be translated to `usize`.
|
||||
///
|
||||
/// If `size_t` is translated to `usize`, type definitions for `size_t` will not be
|
||||
/// emitted.
|
||||
///
|
||||
/// `size_t` is translated to `usize` by default.
|
||||
pub fn size_t_is_usize(mut self, is: bool) -> Self {
|
||||
self.options.size_t_is_usize = is;
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::cell::Cell;
|
|||
/// A dynamic set of regular expressions.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct RegexSet {
|
||||
items: Vec<String>,
|
||||
items: Vec<Box<str>>,
|
||||
/// Whether any of the items in the set was ever matched. The length of this
|
||||
/// vector is exactly the length of `items`.
|
||||
matched: Vec<Cell<bool>>,
|
||||
|
@ -32,25 +32,25 @@ impl RegexSet {
|
|||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
self.items.push(string.as_ref().to_owned());
|
||||
self.items.push(string.as_ref().to_owned().into_boxed_str());
|
||||
self.matched.push(Cell::new(false));
|
||||
self.set = None;
|
||||
}
|
||||
|
||||
/// Returns slice of String from its field 'items'
|
||||
pub fn get_items(&self) -> &[String] {
|
||||
&self.items[..]
|
||||
pub fn get_items(&self) -> &[Box<str>] {
|
||||
&self.items
|
||||
}
|
||||
|
||||
/// Returns an iterator over regexes in the set which didn't match any
|
||||
/// strings yet.
|
||||
pub fn unmatched_items(&self) -> impl Iterator<Item = &String> {
|
||||
pub fn unmatched_items(&self) -> impl Iterator<Item = &str> {
|
||||
self.items.iter().enumerate().filter_map(move |(i, item)| {
|
||||
if !self.record_matches || self.matched[i].get() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(item)
|
||||
Some(item.as_ref())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ fn invalid_regex_warning(
|
|||
Level::Note,
|
||||
);
|
||||
|
||||
if set.items.iter().any(|item| item == "*") {
|
||||
if set.items.iter().any(|item| item.as_ref() == "*") {
|
||||
diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help);
|
||||
}
|
||||
diagnostic.display();
|
||||
|
|
|
@ -14,7 +14,7 @@ mozbuild = "0.1"
|
|||
|
||||
[build-dependencies]
|
||||
lazy_static = "1"
|
||||
bindgen = {version = "0.66", default-features = false}
|
||||
bindgen = {version = "0.68", default-features = false}
|
||||
mozbuild = "0.1"
|
||||
|
||||
[features]
|
||||
|
|
Загрузка…
Ссылка в новой задаче