Skip to content

Commit 2f9d3cd

Browse files
boncheolgueqrion
authored andcommitted
Add Builder.with_lockfile
1 parent c2aae5b commit 2f9d3cd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/bindgen/builder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Builder {
1919
lib: Option<(path::PathBuf, Option<String>)>,
2020
lib_cargo: Option<Cargo>,
2121
std_types: bool,
22+
lockfile: Option<path::PathBuf>,
2223
}
2324

2425
impl Builder {
@@ -29,6 +30,7 @@ impl Builder {
2930
lib: None,
3031
lib_cargo: None,
3132
std_types: true,
33+
lockfile: None,
3234
}
3335
}
3436

@@ -248,6 +250,14 @@ impl Builder {
248250
self
249251
}
250252

253+
#[allow(unused)]
254+
pub fn with_lockfile<P: AsRef<path::Path>>(mut self, lockfile: P) -> Builder {
255+
debug_assert!(self.lockfile.is_none());
256+
debug_assert!(self.lib_cargo.is_none());
257+
self.lockfile = Some(path::PathBuf::from(lockfile.as_ref()));
258+
self
259+
}
260+
251261
pub fn generate(self) -> Result<Bindings, Error> {
252262
let mut result = Parse::new();
253263

@@ -260,18 +270,20 @@ impl Builder {
260270
}
261271

262272
if let Some((lib_dir, binding_lib_name)) = self.lib.clone() {
273+
let lockfile = self.lockfile.as_ref().and_then(|p| p.to_str());
274+
263275
let cargo = if let Some(binding_lib_name) = binding_lib_name {
264276
Cargo::load(
265277
&lib_dir,
266-
None,
278+
lockfile,
267279
Some(&binding_lib_name),
268280
self.config.parse.parse_deps,
269281
self.config.parse.clean,
270282
)?
271283
} else {
272284
Cargo::load(
273285
&lib_dir,
274-
None,
286+
lockfile,
275287
None,
276288
self.config.parse.parse_deps,
277289
self.config.parse.clean,

0 commit comments

Comments
 (0)