Skip to content

Commit 2cfc64e

Browse files
anpemilio
authored andcommitted
Integration test include directory paths for depfiles.
1 parent 1bb548b commit 2cfc64e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

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.

0 commit comments

Comments
 (0)