Skip to content

Commit 3c1ed05

Browse files
committed
Add patch.
1 parent f9dca62 commit 3c1ed05

File tree

9 files changed

+413
-144
lines changed

9 files changed

+413
-144
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ include = [
3232
[badges]
3333
travis-ci = { repository = "rust-lang/rust-bindgen" }
3434

35+
[workspace]
36+
members = [
37+
"bindgen-integration",
38+
"tests/expectations",
39+
"tests/quickchecking",
40+
]
41+
3542
[lib]
3643
path = "src/lib.rs"
3744

@@ -86,3 +93,7 @@ testing_only_docs = []
8693
testing_only_extra_assertions = []
8794
testing_only_libclang_9 = []
8895
testing_only_libclang_5 = []
96+
97+
[patch.crates-io]
98+
cexpr = { git = "https://github.com/reitermarkus/rust-cexpr", branch = "cast-expr" }
99+
# cexpr = { path = "./rust-cexpr" }

bindgen-integration/build.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,9 @@ impl ParseCallbacks for MacroCallback {
123123
// Test the "custom derives" capability by adding `PartialEq` to the `Test` struct.
124124
fn add_derives(&self, name: &str) -> Vec<String> {
125125
if name == "Test" {
126-
vec![
127-
"PartialEq".into(),
128-
]
126+
vec!["PartialEq".into()]
129127
} else if name == "MyOrderedEnum" {
130-
vec![
131-
"std::cmp::PartialOrd".into(),
132-
]
128+
vec!["std::cmp::PartialOrd".into()]
133129
} else {
134130
vec![]
135131
}
@@ -162,7 +158,9 @@ fn main() {
162158

163159
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
164160
let out_rust_file = out_path.join("test.rs");
165-
let out_rust_file_relative = out_rust_file.strip_prefix(std::env::current_dir().unwrap()).unwrap();
161+
let out_rust_file_relative = out_rust_file
162+
.strip_prefix(env::var("CARGO_MANIFEST_DIR").unwrap())
163+
.unwrap();
166164
let out_dep_file = out_path.join("test.d");
167165

168166
let bindings = Builder::default()
@@ -189,13 +187,18 @@ fn main() {
189187
.expect("Unable to generate bindings");
190188

191189
assert!(macros.read().unwrap().contains("TESTMACRO"));
192-
bindings.write_to_file(&out_rust_file).expect("Couldn't write bindings!");
193-
194-
let observed_deps = std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!");
195-
let expected_deps = format!("{}: cpp/Test.h include/stub.h", out_rust_file_relative.display());
190+
bindings
191+
.write_to_file(&out_rust_file)
192+
.expect("Couldn't write bindings!");
193+
194+
let observed_deps =
195+
std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!");
196+
let expected_deps = format!(
197+
"{}: cpp/Test.h include/stub.h",
198+
out_rust_file_relative.display()
199+
);
196200
assert_eq!(
197-
observed_deps,
198-
expected_deps,
201+
observed_deps, expected_deps,
199202
"including stub via include dir must produce correct dep path",
200203
);
201204
}

tests/expectations/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use std::fs;
88
use std::io::Write;
99
use std::path::Path;
1010

11-
const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[
12-
"libclang-5",
13-
"libclang-9",
14-
];
11+
const LIBCLANG_VERSION_DIRS: &'static [&'static str] =
12+
&["libclang-5", "libclang-9"];
1513

1614
fn main() {
1715
println!("cargo:rerun-if-changed=build.rs");

tests/expectations/tests/dynamic_loading_attributes.rs

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

tests/quickchecking/src/bin.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ fn main() {
103103
.get_matches();
104104

105105
let output_path: Option<&str> = matches.value_of("path");
106-
let generate_range: usize = matches.value_of("range").unwrap().parse::<usize>().unwrap();
107-
let tests: usize = matches.value_of("count").unwrap().parse::<usize>().unwrap();
106+
let generate_range: usize =
107+
matches.value_of("range").unwrap().parse::<usize>().unwrap();
108+
let tests: usize =
109+
matches.value_of("count").unwrap().parse::<usize>().unwrap();
108110

109111
quickchecking::test_bindgen(generate_range, tests, output_path)
110112
}

tests/quickchecking/src/fuzzers.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use quickcheck::{Arbitrary, Gen, StdGen};
2-
use std::fmt;
32
use rand::thread_rng;
3+
use std::fmt;
44

55
/// BaseTypeC is used in generation of C headers to represent the C language's
66
/// primitive types as well as `void*`.
@@ -185,10 +185,14 @@ impl Arbitrary for DeclarationC {
185185
fn arbitrary<G: Gen>(g: &mut G) -> DeclarationC {
186186
match g.gen_range(0, 5) {
187187
0 => DeclarationC::FunctionDecl(FunctionPrototypeC::arbitrary(g)),
188-
1 => DeclarationC::FunctionPtrDecl(FunctionPointerDeclarationC::arbitrary(g)),
188+
1 => DeclarationC::FunctionPtrDecl(
189+
FunctionPointerDeclarationC::arbitrary(g),
190+
),
189191
2 => DeclarationC::StructDecl(StructDeclarationC::arbitrary(g)),
190192
3 => DeclarationC::UnionDecl(UnionDeclarationC::arbitrary(g)),
191-
4 => DeclarationC::VariableDecl(BasicTypeDeclarationC::arbitrary(g)),
193+
4 => {
194+
DeclarationC::VariableDecl(BasicTypeDeclarationC::arbitrary(g))
195+
}
192196
_ => unreachable!(),
193197
}
194198
}
@@ -425,9 +429,7 @@ impl fmt::Display for StructDeclarationC {
425429
write!(
426430
f,
427431
"struct {{ {} }} struct_{}{};",
428-
self.fields,
429-
self.ident_id,
430-
self.array_dimension
432+
self.fields, self.ident_id, self.array_dimension
431433
)
432434
}
433435
}
@@ -475,9 +477,7 @@ impl fmt::Display for UnionDeclarationC {
475477
write!(
476478
f,
477479
"union {{ {} }} union_{}{};",
478-
self.fields,
479-
self.ident_id,
480-
self.array_dimension
480+
self.fields, self.ident_id, self.array_dimension
481481
)
482482
}
483483
}
@@ -574,9 +574,7 @@ impl fmt::Display for ParameterC {
574574
write!(
575575
f,
576576
"{} {} {}",
577-
self.type_qualifier,
578-
self.type_name,
579-
self.pointer_level
577+
self.type_qualifier, self.type_name, self.pointer_level
580578
)
581579
}
582580
}

tests/quickchecking/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ extern crate quickcheck;
2626
extern crate rand;
2727
extern crate tempdir;
2828

29-
use std::sync::Mutex;
3029
use quickcheck::{QuickCheck, StdGen, TestResult};
30+
use rand::thread_rng;
31+
use std::error::Error;
3132
use std::fs::File;
3233
use std::io::Write;
33-
use tempdir::TempDir;
34-
use std::process::{Command, Output};
3534
use std::path::PathBuf;
36-
use std::error::Error;
37-
use rand::thread_rng;
35+
use std::process::{Command, Output};
36+
use std::sync::Mutex;
37+
use tempdir::TempDir;
3838

3939
/// Contains definitions of and impls for types used to fuzz C declarations.
4040
pub mod fuzzers;
@@ -47,12 +47,15 @@ struct Context {
4747

4848
// Initialize global context.
4949
lazy_static! {
50-
static ref CONTEXT: Mutex<Context> = Mutex::new(Context { output_path: None });
50+
static ref CONTEXT: Mutex<Context> =
51+
Mutex::new(Context { output_path: None });
5152
}
5253

5354
// Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns
5455
// output of the associated command.
55-
fn run_predicate_script(header: fuzzers::HeaderC) -> Result<Output, Box<Error>> {
56+
fn run_predicate_script(
57+
header: fuzzers::HeaderC,
58+
) -> Result<Output, Box<Error>> {
5659
let dir = TempDir::new("bindgen_prop")?;
5760
let header_path = dir.path().join("prop_test.h");
5861

@@ -110,7 +113,11 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
110113
/// fuzzed C headers generated with types defined in the `fuzzers` module.
111114
/// Success/Failure is dictated by the result of passing the fuzzed headers
112115
/// to the `csmith-fuzzing/predicate.py` script.
113-
pub fn test_bindgen(generate_range: usize, tests: usize, output_path: Option<&str>) {
116+
pub fn test_bindgen(
117+
generate_range: usize,
118+
tests: usize,
119+
output_path: Option<&str>,
120+
) {
114121
match output_path {
115122
Some(path) => {
116123
CONTEXT.lock().unwrap().output_path =

tests/quickchecking/tests/fuzzed-c-headers.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
21
extern crate quickcheck;
32
extern crate quickchecking;
43
extern crate rand;
54

6-
use quickchecking::fuzzers::{ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC,
7-
DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC,
8-
HeaderC, ParameterC, ParameterListC, PointerLevelC,
9-
StructDeclarationC, TypeQualifierC, UnionDeclarationC};
105
use quickcheck::{Arbitrary, StdGen};
6+
use quickchecking::fuzzers::{
7+
ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC,
8+
DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, HeaderC,
9+
ParameterC, ParameterListC, PointerLevelC, StructDeclarationC,
10+
TypeQualifierC, UnionDeclarationC,
11+
};
1112
use rand::thread_rng;
1213

1314
#[test]

0 commit comments

Comments
 (0)