Skip to content

Commit 90c6024

Browse files
committed
Hash the cargo metadata
Fixes #208.
1 parent e56dde5 commit 90c6024

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/build.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::hash::{DefaultHasher, Hash, Hasher};
23
use std::io::Read;
34
use std::path::{Path, PathBuf};
45
use std::sync::atomic::{AtomicBool, Ordering};
@@ -235,6 +236,7 @@ struct FingerPrint {
235236
build_targets: BuildTargets,
236237
install_paths: InstallPaths,
237238
static_libs: String,
239+
hasher: DefaultHasher,
238240
}
239241

240242
#[derive(serde::Serialize, serde::Deserialize)]
@@ -249,21 +251,24 @@ impl FingerPrint {
249251
root_output: &Path,
250252
build_targets: &BuildTargets,
251253
install_paths: &InstallPaths,
254+
capi_config: &CApiConfig,
252255
) -> Self {
256+
let mut hasher = DefaultHasher::new();
257+
258+
capi_config.hash(&mut hasher);
259+
253260
Self {
254261
id: id.to_owned(),
255262
root_output: root_output.to_owned(),
256263
build_targets: build_targets.clone(),
257264
install_paths: install_paths.clone(),
258265
static_libs: String::new(),
266+
hasher,
259267
}
260268
}
261269

262270
fn hash(&self) -> anyhow::Result<Option<String>> {
263-
use std::collections::hash_map::DefaultHasher;
264-
use std::hash::{Hash, Hasher};
265-
266-
let mut hasher = DefaultHasher::new();
271+
let mut hasher = self.hasher.clone();
267272
self.install_paths.hash(&mut hasher);
268273

269274
let mut paths: Vec<&PathBuf> = Vec::new();
@@ -324,23 +329,23 @@ impl FingerPrint {
324329
}
325330
}
326331

327-
#[derive(Debug)]
332+
#[derive(Debug, Hash)]
328333
pub struct CApiConfig {
329334
pub header: HeaderCApiConfig,
330335
pub pkg_config: PkgConfigCApiConfig,
331336
pub library: LibraryCApiConfig,
332337
pub install: InstallCApiConfig,
333338
}
334339

335-
#[derive(Debug)]
340+
#[derive(Debug, Hash)]
336341
pub struct HeaderCApiConfig {
337342
pub name: String,
338343
pub subdirectory: String,
339344
pub generation: bool,
340345
pub enabled: bool,
341346
}
342347

343-
#[derive(Debug)]
348+
#[derive(Debug, Hash)]
344349
pub struct PkgConfigCApiConfig {
345350
pub name: String,
346351
pub filename: String,
@@ -351,14 +356,14 @@ pub struct PkgConfigCApiConfig {
351356
pub strip_include_path_components: usize,
352357
}
353358

354-
#[derive(Debug)]
359+
#[derive(Debug, Hash)]
355360
pub enum VersionSuffix {
356361
Major,
357362
MajorMinor,
358363
MajorMinorPatch,
359364
}
360365

361-
#[derive(Debug)]
366+
#[derive(Debug, Hash)]
362367
pub struct LibraryCApiConfig {
363368
pub name: String,
364369
pub version: Version,
@@ -388,19 +393,19 @@ impl LibraryCApiConfig {
388393
}
389394
}
390395

391-
#[derive(Debug, Default)]
396+
#[derive(Debug, Default, Hash)]
392397
pub struct InstallCApiConfig {
393398
pub include: Vec<InstallTarget>,
394399
pub data: Vec<InstallTarget>,
395400
}
396401

397-
#[derive(Debug)]
402+
#[derive(Debug, Hash)]
398403
pub enum InstallTarget {
399404
Asset(InstallTargetPaths),
400405
Generated(InstallTargetPaths),
401406
}
402407

403-
#[derive(Clone, Debug)]
408+
#[derive(Clone, Debug, Hash)]
404409
pub struct InstallTargetPaths {
405410
/// pattern to feed to glob::glob()
406411
///
@@ -980,7 +985,13 @@ impl CPackage {
980985
args.get_flag("meson"),
981986
)?;
982987

983-
let finger_print = FingerPrint::new(&id, root_output, &build_targets, &install_paths);
988+
let finger_print = FingerPrint::new(
989+
&id,
990+
root_output,
991+
&build_targets,
992+
&install_paths,
993+
&capi_config,
994+
);
984995

985996
Ok(CPackage {
986997
version,

0 commit comments

Comments
 (0)