rust-bindgen相关依赖兼容性适配

Signed-off-by: a30054014 <aipeng3@huawei.com>
This commit is contained in:
a30054014
2025-04-19 16:17:39 +08:00
parent c1e7498e84
commit b54cf916fe
9 changed files with 0 additions and 246 deletions
-11
View File
@@ -444,7 +444,6 @@ struct BindgenCommand {
emit_diagnostics: bool,
/// Generates completions for the specified SHELL, sends them to `stdout` and exits.
#[arg(long, value_name = "SHELL")]
generate_shell_completions: Option<clap_complete::Shell>,
/// Enables experimental features.
#[arg(long)]
experimental: bool,
@@ -579,22 +578,12 @@ where
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!(
-1
View File
@@ -20,7 +20,6 @@ pub enum MacroParsingBehavior {
/// A trait to allow configuring different kinds of types in different
/// situations.
pub trait ParseCallbacks: fmt::Debug {
#[cfg(feature = "__cli")]
#[doc(hidden)]
fn cli_args(&self) -> Vec<String> {
vec![]
-102
View File
@@ -128,7 +128,6 @@ fn root_import(
}
bitflags! {
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct DerivableTraits: u16 {
const DEBUG = 1 << 0;
const DEFAULT = 1 << 1;
@@ -4340,15 +4339,6 @@ impl TryToRustTy for FunctionSig {
syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret },
),
Err(err) => {
if matches!(err, error::Error::UnsupportedAbi(_)) {
unsupported_abi_diagnostic(
self.name(),
self.is_variadic(),
item.location(),
ctx,
&err,
);
}
Err(err)
}
@@ -4391,7 +4381,6 @@ impl CodeGenerator for Function {
if signature.is_variadic() {
// We cannot generate wrappers for variadic static functions so we avoid
// generating any code for them.
variadic_fn_diagnostic(self.name(), item.location(), ctx);
return None;
}
}
@@ -4457,13 +4446,6 @@ impl CodeGenerator for Function {
let abi = match signature.abi(ctx, Some(name)) {
Err(err) => {
if matches!(err, error::Error::UnsupportedAbi(_)) {
unsupported_abi_diagnostic(
name,
signature.is_variadic(),
item.location(),
ctx,
&err,
);
}
return None;
@@ -4592,102 +4574,18 @@ impl CodeGenerator for Function {
}
}
#[cfg_attr(not(feature = "experimental"), allow(unused_variables))]
fn unsupported_abi_diagnostic(
fn_name: &str,
variadic: bool,
location: Option<&crate::clang::SourceLocation>,
ctx: &BindgenContext,
error: &error::Error,
) {
warn!(
"Skipping {}function `{}` because the {}",
if variadic { "variadic " } else { "" },
fn_name,
error
);
#[cfg(feature = "experimental")]
if ctx.options().emit_diagnostics {
use crate::diagnostics::{get_line, Diagnostic, Level, Slice};
let mut diag = Diagnostic::default();
diag.with_title(
format!(
"Skipping {}function `{}` because the {}",
if variadic { "variadic " } else { "" },
fn_name,
error
),
Level::Warn,
)
.add_annotation(
"No code will be generated for this function.",
Level::Warn,
)
.add_annotation(
format!(
"The configured Rust version is {}.",
ctx.options().rust_target
),
Level::Note,
);
if let Some(loc) = location {
let (file, line, col, _) = loc.location();
if let Some(filename) = file.name() {
if let Ok(Some(source)) = get_line(&filename, line) {
let mut slice = Slice::default();
slice
.with_source(source)
.with_location(filename, line, col);
diag.add_slice(slice);
}
}
}
diag.display()
}
}
fn variadic_fn_diagnostic(
fn_name: &str,
_location: Option<&crate::clang::SourceLocation>,
_ctx: &BindgenContext,
) {
warn!(
"Cannot generate wrapper for the static variadic function `{}`.",
fn_name,
);
#[cfg(feature = "experimental")]
if _ctx.options().emit_diagnostics {
use crate::diagnostics::{get_line, Diagnostic, Level, Slice};
let mut diag = Diagnostic::default();
diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn)
.add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note)
.add_annotation("No code will be generated for this function.", Level::Note);
if let Some(loc) = _location {
let (file, line, col, _) = loc.location();
if let Some(filename) = file.name() {
if let Ok(Some(source)) = get_line(&filename, line) {
let mut slice = Slice::default();
slice
.with_source(source)
.with_location(filename, line, col);
diag.add_slice(slice);
}
}
}
diag.display()
}
}
fn objc_method_codegen(
ctx: &BindgenContext,
-1
View File
@@ -56,7 +56,6 @@ macro_rules! define_rust_targets {
}
}
#[cfg(feature = "__cli")]
/// Strings of allowed `RustTarget` values
pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*];
-3
View File
@@ -1,6 +1,5 @@
//! Compound types (unions and structs) in our intermediate representation.
use itertools::Itertools;
use super::analysis::Sizedness;
use super::annotations::Annotations;
@@ -496,7 +495,6 @@ where
{
let non_bitfields = raw_fields
.by_ref()
.peeking_take_while(|f| f.bitfield_width().is_none())
.map(|f| Field::DataMember(f.0));
fields.extend(non_bitfields);
}
@@ -506,7 +504,6 @@ where
// the Itanium C++ ABI.
let mut bitfields = raw_fields
.by_ref()
.peeking_take_while(|f| f.bitfield_width().is_some())
.peekable();
if bitfields.peek().is_none() {
-14
View File
@@ -3137,19 +3137,5 @@ impl TemplateParameters for PartialType {
fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) {
warn!("unused option: {} {}", name, item);
#[cfg(feature = "experimental")]
if _ctx.options().emit_diagnostics {
use crate::diagnostics::{Diagnostic, Level};
Diagnostic::default()
.with_title(
format!("Unused regular expression: `{}`.", item),
Level::Warn,
)
.add_annotation(
format!("This regular expression was passed to `{}`.", name),
Level::Note,
)
.display();
}
}
-21
View File
@@ -486,7 +486,6 @@ fn duplicated_macro_diagnostic(
) {
warn!("Duplicated macro definition: {}", macro_name);
#[cfg(feature = "experimental")]
// FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually
// useful. We have to change the logic where this function is called to be able to emit this
// message only when the duplication is an actual issue.
@@ -499,28 +498,8 @@ fn duplicated_macro_diagnostic(
// ```
//
// Will trigger this message even though there's nothing wrong with it.
#[allow(clippy::overly_complex_bool_expr)]
if false && _ctx.options().emit_diagnostics {
use crate::diagnostics::{get_line, Diagnostic, Level, Slice};
use std::borrow::Cow;
let mut slice = Slice::default();
let mut source = Cow::from(macro_name);
let (file, line, col, _) = _location.location();
if let Some(filename) = file.name() {
if let Ok(Some(code)) = get_line(&filename, line) {
source = code.into();
}
slice.with_location(filename, line, col);
}
slice.with_source(source);
Diagnostic::default()
.with_title("Duplicated macro definition.", Level::Warn)
.add_slice(slice)
.add_annotation("This macro had a duplicate.", Level::Note)
.display();
}
}
-30
View File
@@ -41,7 +41,6 @@ pub mod callbacks;
mod clang;
#[cfg(feature = "experimental")]
mod diagnostics;
mod features;
mod ir;
mod parse;
@@ -50,7 +49,6 @@ mod regex_set;
pub use codegen::{
AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle,
};
#[cfg(feature = "__cli")]
pub use features::RUST_TARGET_STRINGS;
pub use features::{RustTarget, LATEST_STABLE_RUST};
pub use ir::annotations::FieldVisibilityKind;
@@ -110,7 +108,6 @@ fn args_are_cpp(clang_args: &[Box<str>]) -> bool {
bitflags! {
/// A type used to indicate which kind of items we have to generate.
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct CodegenConfig: u32 {
/// Whether to generate functions.
const FUNCTIONS = 1 << 0;
@@ -587,24 +584,8 @@ impl BindgenOptions {
}
fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) {
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 {
use crate::diagnostics::{Diagnostic, Level};
let mut diagnostic = Diagnostic::default();
diagnostic.with_title(
format!("The {} Rust target is deprecated.", target),
Level::Warn,
);
diagnostic.add_annotation(
"This Rust target was passed to `--rust-target`",
Level::Info,
);
diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help);
diagnostic.display();
}
}
#[cfg(feature = "runtime")]
@@ -1052,18 +1033,7 @@ impl Bindings {
fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) {
warn!("{}", msg);
#[cfg(feature = "experimental")]
if _options.emit_diagnostics {
use crate::diagnostics::{Diagnostic, Level};
Diagnostic::default()
.with_title(msg, Level::Warn)
.add_annotation(
"The bindings will be generated but not formatted.",
Level::Note,
)
.display();
}
}
impl std::fmt::Display for Bindings {
-63
View File
@@ -63,7 +63,6 @@ impl RegexSet {
self.build_inner(record_matches, None)
}
#[cfg(all(feature = "__cli", feature = "experimental"))]
/// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the
/// name of the regex set is passed to it.
///
@@ -78,20 +77,6 @@ impl RegexSet {
self.build_inner(record_matches, name)
}
#[cfg(all(not(feature = "__cli"), feature = "experimental"))]
/// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the
/// name of the regex set is passed to it.
///
/// Must be called before calling `matches()`, or it will always return
/// false.
#[inline]
pub(crate) fn build_with_diagnostics(
&mut self,
record_matches: bool,
name: Option<&'static str>,
) {
self.build_inner(record_matches, name)
}
fn build_inner(
&mut self,
@@ -146,59 +131,11 @@ fn invalid_regex_warning(
err: regex::Error,
name: &'static str,
) {
use crate::diagnostics::{Diagnostic, Level, Slice};
let mut diagnostic = Diagnostic::default();
match err {
regex::Error::Syntax(string) => {
if string.starts_with("regex parse error:\n") {
let mut source = String::new();
let mut parsing_source = true;
for line in string.lines().skip(1) {
if parsing_source {
if line.starts_with(' ') {
source.push_str(line);
source.push('\n');
continue;
}
parsing_source = false;
}
let error = "error: ";
if line.starts_with(error) {
let (_, msg) = line.split_at(error.len());
diagnostic.add_annotation(msg.to_owned(), Level::Error);
} else {
diagnostic.add_annotation(line.to_owned(), Level::Info);
}
}
let mut slice = Slice::default();
slice.with_source(source);
diagnostic.add_slice(slice);
diagnostic.with_title(
"Error while parsing a regular expression.",
Level::Warn,
);
} else {
diagnostic.with_title(string, Level::Warn);
}
}
err => {
let err = err.to_string();
diagnostic.with_title(err, Level::Warn);
}
}
diagnostic.add_annotation(
format!("This regular expression was passed via `{}`.", name),
Level::Note,
);
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();
}