Skip to content

Commit 1a71713

Browse files
committed
Merge branch 'master' of github.com:rust-lang/rust-bindgen
2 parents 5b739af + 2cfc64e commit 1a71713

File tree

19 files changed

+350
-20
lines changed

19 files changed

+350
-20
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@
144144

145145
## Security
146146

147+
# 0.58.1
148+
149+
Released 2021/04/06
150+
151+
## Added
152+
153+
* Re-introduced unintentionally removed
154+
`bindgen::Builder::whitelist_recursively` (deprecated in favor of
155+
`bindgen::Builder::allowlist_recursively`). [#2022][]
156+
147157
# 0.58.0
148158

149159
Released 2021/04/03

Cargo.lock

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme = "README.md"
1515
repository = "https://github.com/adetaylor/rust-bindgen"
1616
documentation = "https://docs.rs/bindgen"
1717
homepage = "https://rust-lang.github.io/rust-bindgen/"
18-
version = "0.58.0"
18+
version = "0.58.1"
1919
edition = "2018"
2020
build = "build.rs"
2121

@@ -41,6 +41,7 @@ required-features = ["clap"]
4141
diff = "0.1"
4242
clap = "2"
4343
shlex = "1"
44+
tempfile = "3"
4445

4546
[dependencies]
4647
bitflags = "1.0.3"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ End-users should set these environment variables to modify `bindgen`'s behavior
6969
- Examples:
7070
- Specify alternate sysroot: `--sysroot=/path/to/sysroot`
7171
- Add include search path with spaces: `-I"/path/with spaces"`
72+
- `BINDGEN_EXTRA_CLANG_ARGS_<TARGET>`: similar to `BINDGEN_EXTRA_CLANG_ARGS`,
73+
but used to set per-target arguments to pass to clang. Useful to set system include
74+
directories in a target-specific way in cross-compilation environments with multiple targets.
75+
Has precedence over `BINDGEN_EXTRA_CLANG_ARGS`.
7276

7377
Additionally, `bindgen` uses `libclang` to parse C and C++ header files.
7478
To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env].

bindgen-integration/build.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,16 @@ fn main() {
140140
cc::Build::new()
141141
.cpp(true)
142142
.file("cpp/Test.cc")
143+
.include("include")
143144
.compile("libtest.a");
144145

145146
let macros = Arc::new(RwLock::new(HashSet::new()));
146147

148+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
149+
let out_rust_file = out_path.join("test.rs");
150+
let out_rust_file_relative = out_rust_file.strip_prefix(std::env::current_dir().unwrap()).unwrap();
151+
let out_dep_file = out_path.join("test.d");
152+
147153
let bindings = Builder::default()
148154
.rustfmt_bindings(false)
149155
.enable_cxx_namespaces()
@@ -154,7 +160,7 @@ fn main() {
154160
.raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }")
155161
.module_raw_line("root::testing", "pub type Bar = i32;")
156162
.header("cpp/Test.h")
157-
.clang_args(&["-x", "c++", "-std=c++11"])
163+
.clang_args(&["-x", "c++", "-std=c++11", "-I", "include"])
158164
.parse_callbacks(Box::new(MacroCallback {
159165
macros: macros.clone(),
160166
seen_hellos: Mutex::new(0),
@@ -163,13 +169,18 @@ fn main() {
163169
.blocklist_function("my_prefixed_function_to_remove")
164170
.constified_enum("my_prefixed_enum_to_be_constified")
165171
.opaque_type("my_prefixed_templated_foo<my_prefixed_baz>")
172+
.depfile(out_rust_file_relative.display().to_string(), &out_dep_file)
166173
.generate()
167174
.expect("Unable to generate bindings");
168175

169176
assert!(macros.read().unwrap().contains("TESTMACRO"));
170-
171-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
172-
bindings
173-
.write_to_file(out_path.join("test.rs"))
174-
.expect("Couldn't write bindings!");
177+
bindings.write_to_file(&out_rust_file).expect("Couldn't write bindings!");
178+
179+
let observed_deps = std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!");
180+
let expected_deps = format!("{}: cpp/Test.h include/stub.h", out_rust_file_relative.display());
181+
assert_eq!(
182+
observed_deps,
183+
expected_deps,
184+
"including stub via include dir must produce correct dep path",
185+
);
175186
}

bindgen-integration/cpp/Test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "stub.h" // this bad path is made valid by a `-I include` clang arg
2+
13
#pragma once
24

35
#define TESTMACRO

bindgen-integration/include/stub.h

Whitespace-only changes.

book/src/requirements.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ repos to get version 3.9. See http://apt.llvm.org/.
6363
# pacman -S clang
6464
```
6565

66+
#### Fedora
67+
68+
```bash
69+
# dnf install clang-devel
70+
```
71+
6672
#### OpenBSD
6773

6874
```bash

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@ fn main() {
7979
println!("cargo:rerun-if-env-changed=LIBCLANG_PATH");
8080
println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH");
8181
println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
82+
println!(
83+
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
84+
std::env::var("TARGET").unwrap()
85+
);
86+
println!(
87+
"cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}",
88+
std::env::var("TARGET").unwrap().replace("-", "_")
89+
);
8290
}

src/codegen/mod.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,18 @@ impl CodeGenerator for Var {
619619
return;
620620
}
621621

622+
let mut attrs = vec![];
623+
if let Some(comment) = item.comment(ctx) {
624+
attrs.push(attributes::doc(comment));
625+
}
626+
622627
let ty = self.ty().to_rust_ty_or_opaque(ctx, &()).ignore_annotations();
623628

624629
if let Some(val) = self.val() {
625630
match *val {
626631
VarType::Bool(val) => {
627632
result.push(quote! {
633+
#(#attrs)*
628634
pub const #canonical_ident : #ty = #val ;
629635
});
630636
}
@@ -644,6 +650,7 @@ impl CodeGenerator for Var {
644650
helpers::ast_ty::uint_expr(val as _)
645651
};
646652
result.push(quote! {
653+
#(#attrs)*
647654
pub const #canonical_ident : #ty = #val ;
648655
});
649656
}
@@ -661,12 +668,14 @@ impl CodeGenerator for Var {
661668
Ok(string) => {
662669
let cstr = helpers::ast_ty::cstr_expr(string);
663670
result.push(quote! {
671+
#(#attrs)*
664672
pub const #canonical_ident : &'static #ty = #cstr ;
665673
});
666674
}
667675
Err(..) => {
668676
let bytes = helpers::ast_ty::byte_array_expr(bytes);
669677
result.push(quote! {
678+
#(#attrs)*
670679
pub const #canonical_ident : #ty = #bytes ;
671680
});
672681
}
@@ -675,20 +684,20 @@ impl CodeGenerator for Var {
675684
VarType::Float(f) => {
676685
match helpers::ast_ty::float_expr(ctx, f) {
677686
Ok(expr) => result.push(quote! {
687+
#(#attrs)*
678688
pub const #canonical_ident : #ty = #expr ;
679689
}),
680690
Err(..) => return,
681691
}
682692
}
683693
VarType::Char(c) => {
684694
result.push(quote! {
695+
#(#attrs)*
685696
pub const #canonical_ident : #ty = #c ;
686697
});
687698
}
688699
}
689700
} else {
690-
let mut attrs = vec![];
691-
692701
// If necessary, apply a `#[link_name]` attribute
693702
let link_name = self.mangled_name().unwrap_or(self.name());
694703
if !utils::names_will_be_identical_after_mangling(
@@ -4277,6 +4286,16 @@ pub(crate) fn codegen(
42774286
}
42784287
}
42794288

4289+
if let Some(spec) = context.options().depfile.as_ref() {
4290+
match spec.write(context.deps()) {
4291+
Ok(()) => info!(
4292+
"Your depfile was generated successfully into: {}",
4293+
spec.depfile_path.display()
4294+
),
4295+
Err(e) => warn!("{}", e),
4296+
}
4297+
}
4298+
42804299
context.resolve_item(context.root_module()).codegen(
42814300
context,
42824301
&mut result,

src/deps.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// Generating build depfiles from parsed bindings.
2+
use std::{collections::BTreeSet, path::PathBuf};
3+
4+
#[derive(Debug)]
5+
pub(crate) struct DepfileSpec {
6+
pub output_module: String,
7+
pub depfile_path: PathBuf,
8+
}
9+
10+
impl DepfileSpec {
11+
pub fn write(&self, deps: &BTreeSet<String>) -> std::io::Result<()> {
12+
let mut buf = format!("{}:", self.output_module);
13+
14+
for file in deps {
15+
buf = format!("{} {}", buf, file);
16+
}
17+
18+
std::fs::write(&self.depfile_path, &buf)
19+
}
20+
}

0 commit comments

Comments
 (0)