Skip to content

Commit 4d8dad7

Browse files
committed
chore: merged changes onto upstream
2 parents 03d49b6 + e48a074 commit 4d8dad7

File tree

20 files changed

+777
-221
lines changed

20 files changed

+777
-221
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clang-sys = "1"
3131
clap = "4"
3232
clap_complete = "4"
3333
env_logger = "0.10.0"
34-
itertools = { version = ">=0.10,<0.14", default-features = false }
34+
itertools = { version = ">=0.10,<0.15", default-features = false, features = ["use_alloc"]}
3535
libloading = "0.8"
3636
log = "0.4"
3737
objc = "0.2"

bindgen-integration/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ build = "build.rs"
1010
rust-version.workspace = true
1111
edition.workspace = true
1212

13+
[dependencies]
14+
syn = { workspace = true, features = ["full", "visit"] }
15+
1316
[build-dependencies]
1417
bindgen = { workspace = true, default-features = true, features = ["experimental"] }
1518
cc.workspace = true

bindgen-integration/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
extern crate bindgen;
22

33
use bindgen::callbacks::{
4-
DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks,
4+
AttributeItemKind, DeriveInfo, FunctionKind, IntKind, MacroParsingBehavior,
5+
ParseCallbacks,
56
};
67
use bindgen::{Builder, EnumVariation, Formatter};
78
use std::collections::HashSet;
@@ -140,7 +141,14 @@ impl ParseCallbacks for MacroCallback {
140141
info: &bindgen::callbacks::AttributeInfo<'_>,
141142
) -> Vec<String> {
142143
if info.name == "Test" {
144+
assert_eq!(info.kind, AttributeItemKind::Struct);
143145
vec!["#[cfg_attr(test, derive(PartialOrd))]".into()]
146+
} else if info.name == "coord" {
147+
assert_eq!(
148+
info.kind,
149+
AttributeItemKind::Function(FunctionKind::Function)
150+
);
151+
vec!["#[must_use]".into()]
144152
} else {
145153
vec![]
146154
}

bindgen-integration/src/lib.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,62 @@ fn test_custom_derive() {
297297
assert!(!(test1 > test2));
298298
}
299299

300+
#[test]
301+
fn test_custom_fn_attribute() {
302+
use std::env;
303+
use std::fs;
304+
use std::path::Path;
305+
use syn::visit::Visit;
306+
use syn::{parse_file, File, ForeignItem, Item, ItemForeignMod};
307+
308+
let out_dir =
309+
std::env::var("OUT_DIR").expect("OUT_DIR environment variable not set");
310+
let test_file_path = Path::new(&out_dir).join("test.rs");
311+
let file_content = fs::read_to_string(&test_file_path)
312+
.expect("Failed to read test.rs file");
313+
let syntax_tree: File =
314+
parse_file(&file_content).expect("Failed to parse test.rs");
315+
316+
struct FunctionVisitor {
317+
found_coord: bool,
318+
has_must_use: bool,
319+
}
320+
321+
impl<'ast> Visit<'ast> for FunctionVisitor {
322+
fn visit_item_foreign_mod(
323+
&mut self,
324+
foreign_mod: &'ast ItemForeignMod,
325+
) {
326+
for foreign_item in &foreign_mod.items {
327+
if let ForeignItem::Fn(item_fn) = foreign_item {
328+
if item_fn.sig.ident == "coord" {
329+
self.found_coord = true;
330+
self.has_must_use = item_fn
331+
.attrs
332+
.iter()
333+
.any(|attr| attr.path().is_ident("must_use"));
334+
}
335+
}
336+
}
337+
}
338+
}
339+
340+
let mut visitor = FunctionVisitor {
341+
found_coord: false,
342+
has_must_use: false,
343+
};
344+
visitor.visit_file(&syntax_tree);
345+
346+
assert!(
347+
visitor.found_coord,
348+
"The function 'coord' was not found in the source."
349+
);
350+
assert!(
351+
visitor.has_must_use,
352+
"The function 'coord' does not have the #[must_use] attribute."
353+
);
354+
}
355+
300356
#[test]
301357
fn test_custom_attributes() {
302358
// The `add_attributes` callback should have added `#[cfg_attr(test, derive(PartialOrd))])`

bindgen-tests/tests/expectations/tests/attribute-custom-cli.rs

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/expectations/tests/attribute-custom.rs

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/headers/attribute-custom-cli.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bindgen-flags: --default-enum-style rust --default-non-copy-union-style manually_drop --no-default=".*" --no-hash=".*" --no-partialeq=".*" --no-debug=".*" --no-copy=".*" --with-attribute-custom="foo_[^e].*=#[doc(hidden)]" --with-attribute-custom-struct="foo.*=#[derive(Default)]" --with-attribute-custom-enum="foo.*=#[cfg_attr(test, derive(PartialOrd, Copy))]" --with-attribute-custom-union="foo.*=#[derive(Clone)],#[derive(Copy)]"
1+
// bindgen-flags: --default-enum-style rust --default-non-copy-union-style manually_drop --no-default=".*" --no-hash=".*" --no-partialeq=".*" --no-debug=".*" --no-copy=".*" --with-attribute-custom="foo_[^e].*=#[doc(hidden)]" --with-attribute-custom-struct="foo.*=#[derive(Default)]" --with-attribute-custom-enum="foo.*=#[cfg_attr(test, derive(PartialOrd, Copy))]" --with-attribute-custom-union="foo.*=#[derive(Clone)],#[derive(Copy)]" --with-attribute-custom-function="foo.*=#[must_use],#[doc(hidden)]"
22
struct foo_struct {
33
int inner;
44
};
@@ -12,3 +12,4 @@ union foo_union {
1212
struct non_matching {
1313
int inner;
1414
};
15+
int foo_function() { return 1; }

bindgen-tests/tests/headers/attribute-custom.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ struct my_type2 {
2626
struct my_type3 {
2727
unsigned long a;
2828
};
29+
30+
/**
31+
* <div rustbindgen attribute="#[must_use]" attribute="#[doc(hidden)]"></div>
32+
*/
33+
int function_attributes() { return 1; }

bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ readme = "../README.md"
1616
repository = "https://github.com/rust-lang/rust-bindgen"
1717
documentation = "https://docs.rs/bindgen"
1818
homepage = "https://rust-lang.github.io/rust-bindgen/"
19-
version = "0.71.1"
19+
version = "0.69.5"
2020
build = "build.rs"
2121
rust-version.workspace = true
2222
edition.workspace = true

0 commit comments

Comments
 (0)