Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
496 changes: 256 additions & 240 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ edition = "2021"

# All dependency version management is centralized here
[workspace.dependencies]
annotate-snippets = "0.11.4"
annotate-snippets = "0.12.16"
bindgen = { version = "0.72.0", path = "./bindgen", default-features = false }
bitflags = "2.2.1"
block = "0.1"
cc = "1.0"
cexpr = "0.6"
clang-sys = "1"
clap = "4"
clap_complete = "4"
env_logger = "0.10.0"
libloading = "0.8"
log = "0.4"
objc = "0.2"
owo-colors = "4.1.0"
prettyplease = "0.3"
proc-macro2 = "1.0.80"
quickcheck = "1.0"
quote = { version = "1", default-features = false }
regex = { version = "1.5.3", default-features = false }
rustc-hash = "2.1.0"
shlex = "2"
similar = "2.2.1"
syn = "3.0"
bitflags = "2.13.1"
block = "0.1.6"
cc = "1.4.2"
cexpr = "0.6.0"
clang-sys = "1.9.1"
clap = "4.6.6"
clap_complete = "4.6.9"
env_logger = "0.11.11"
libloading = "0.9.0"
log = "0.4.33"
objc = "0.2.7"
owo-colors = "4.3.0"
prettyplease = "0.3.0"
proc-macro2 = "1.0.107"
quickcheck = "1.1.0"
quote = { version = "1.0.47", default-features = false }
regex = { version = "1.13.1", default-features = false }
rustc-hash = "2.1.3"
shlex = "2.0.1"
similar = "3.1.2"
syn = "3.0.3"
tempfile = "3.27.0"

[workspace.lints.rust]
Expand Down
2 changes: 1 addition & 1 deletion bindgen-tests/tests/quickchecking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ pub fn test_bindgen(

QuickCheck::new()
.tests(tests)
.gen(Gen::new(generate_range))
.rng(Gen::new(generate_range))
.quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult);
}
12 changes: 6 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4981,18 +4981,18 @@ fn unsupported_abi_diagnostic(
"Skipping {}function `{fn_name}` because the {error}",
if variadic { "variadic " } else { "" },
),
Level::Warning,
Level::WARNING,
)
.add_annotation(
"No code will be generated for this function.",
Level::Warning,
Level::WARNING,
)
.add_annotation(
format!(
"The configured Rust version is {}.",
ctx.options().rust_target
),
Level::Note,
Level::NOTE,
);

if let Some(loc) = location {
Expand Down Expand Up @@ -5028,9 +5028,9 @@ fn variadic_fn_diagnostic(

let mut diag = Diagnostic::default();

diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::Warning)
.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);
diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::WARNING)
.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();
Expand Down
53 changes: 26 additions & 27 deletions bindgen/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ use std::fmt::Write;
use std::io::{self, BufRead, BufReader};
use std::{borrow::Cow, fs::File};

use annotate_snippets::{Renderer, Snippet};
use annotate_snippets::{Annotation, Group, Renderer, Snippet};

pub(crate) use annotate_snippets::Level;

/// A `bindgen` diagnostic.
#[derive(Default)]
pub(crate) struct Diagnostic<'a> {
title: Option<(Cow<'a, str>, Level)>,
title: Option<(Cow<'a, str>, Level<'a>)>,
slices: Vec<Slice<'a>>,
footer: Vec<(Cow<'a, str>, Level)>,
footer: Vec<(Cow<'a, str>, Level<'a>)>,
}

impl<'a> Diagnostic<'a> {
/// Add a title to the diagnostic and set its type.
pub(crate) fn with_title(
&mut self,
title: impl Into<Cow<'a, str>>,
level: Level,
level: Level<'a>,
) -> &mut Self {
self.title = Some((title.into(), level));
self
Expand All @@ -39,7 +39,7 @@ impl<'a> Diagnostic<'a> {
pub(crate) fn add_annotation(
&mut self,
msg: impl Into<Cow<'a, str>>,
level: Level,
level: Level<'a>,
) -> &mut Self {
self.footer.push((msg.into(), level));
self
Expand All @@ -54,45 +54,44 @@ impl<'a> Diagnostic<'a> {
static INVOKED_BY_BUILD_SCRIPT: bool = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some();
}

let mut footer = vec![];
let mut slices = vec![];
let snippet = if let Some((msg, level)) = &self.title {
(*level).title(msg)
} else {
let Some((msg, level)) = &self.title else {
return;
};

for (msg, level) in &self.footer {
footer.push((*level).title(msg));
}

// add additional info that this is generated by bindgen
// so as to not confuse with rustc warnings
footer.push(
Level::Info.title("This diagnostic was generated by bindgen."),
);
let mut group =
Group::with_title(level.clone().primary_title(msg.as_ref()));

for slice in &self.slices {
if let Some(source) = &slice.source {
let mut snippet = Snippet::source(source)
.line_start(slice.line.unwrap_or_default());
let mut snippet: Snippet<'_, Annotation<'_>> =
Snippet::source(source.as_ref())
.line_start(slice.line.unwrap_or_default())
.fold(false);
if let Some(origin) = &slice.filename {
snippet = snippet.origin(origin);
snippet = snippet.path(origin.as_str());
}
slices.push(snippet);
group = group.element(snippet);
}
}

for (msg, level) in &self.footer {
group = group.element(level.clone().message(msg.as_ref()));
}

// add additional info that this is generated by bindgen
// so as to not confuse with rustc warnings
group = group.element(
Level::INFO.message("This diagnostic was generated by bindgen."),
);

let renderer = Renderer::styled();
let dl = renderer.render(snippet.snippets(slices).footers(footer));
let dl = renderer.render(&[group]);

if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) {
// This is just a hack which hides the `warning:` added by cargo at the beginning of
// every line. This should be fine as our diagnostics already have a colorful title.
// FIXME (pvdrz): Could it be that this doesn't work in other languages?
let hide_warning = "\r \r";
let string = dl.to_string();
for line in string.lines() {
for line in dl.lines() {
println!("cargo:warning={hide_warning}{line}");
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3107,11 +3107,11 @@ fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) {
Diagnostic::default()
.with_title(
format!("Unused regular expression: `{item}`."),
Level::Warning,
Level::WARNING,
)
.add_annotation(
format!("This regular expression was passed to `{name}`."),
Level::Note,
Level::NOTE,
)
.display();
}
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ fn duplicated_macro_diagnostic(
slice.with_source(source);

Diagnostic::default()
.with_title("Duplicated macro definition.", Level::Warning)
.with_title("Duplicated macro definition.", Level::WARNING)
.add_slice(slice)
.add_annotation("This macro had a duplicate.", Level::Note)
.add_annotation("This macro had a duplicate.", Level::NOTE)
.display();
}
}
4 changes: 2 additions & 2 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,10 @@ fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) {
use crate::diagnostics::{Diagnostic, Level};

Diagnostic::default()
.with_title(msg, Level::Warning)
.with_title(msg, Level::WARNING)
.add_annotation(
"The bindings will be generated but not formatted.",
Level::Note,
Level::NOTE,
)
.display();
}
Expand Down
16 changes: 8 additions & 8 deletions bindgen/regex_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl RegexSet {
}

#[cfg(all(not(feature = "__cli"), feature = "experimental"))]
/// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the
/// 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
Expand Down Expand Up @@ -164,9 +164,9 @@ fn invalid_regex_warning(
let error = "error: ";
if line.starts_with(error) {
let (_, msg) = line.split_at(error.len());
diagnostic.add_annotation(msg.to_owned(), Level::Error);
diagnostic.add_annotation(msg.to_owned(), Level::ERROR);
} else {
diagnostic.add_annotation(line.to_owned(), Level::Info);
diagnostic.add_annotation(line.to_owned(), Level::INFO);
}
}
let mut slice = Slice::default();
Expand All @@ -175,25 +175,25 @@ fn invalid_regex_warning(

diagnostic.with_title(
"Error while parsing a regular expression.",
Level::Warning,
Level::WARNING,
);
} else {
diagnostic.with_title(string, Level::Warning);
diagnostic.with_title(string, Level::WARNING);
}
}
err => {
let err = err.to_string();
diagnostic.with_title(err, Level::Warning);
diagnostic.with_title(err, Level::WARNING);
}
}

diagnostic.add_annotation(
format!("This regular expression was passed via `{name}`."),
Level::Note,
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.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::HELP);
}
diagnostic.display();
}
Loading