~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


40598944 Peter John

3 years ago
Merge pull request #188 from madmo/master
Files changed (1) hide show
  1. utils/src/lib.rs +9 -1
utils/src/lib.rs CHANGED
@@ -115,6 +115,11 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
115
115
  hasher.update(&data);
116
116
  let hash: [u8; 32] = hasher.finalize().into();
117
117
 
118
+ let source_date_epoch = match std::env::var("SOURCE_DATE_EPOCH") {
119
+ Ok(value) => value.parse::<u64>().map_or(None, |v| Some(v)),
120
+ Err(_) => None,
121
+ };
122
+
118
123
  let last_modified = fs::metadata(file_path)?.modified().ok().map(|last_modified| {
119
124
  last_modified
120
125
  .duration_since(SystemTime::UNIX_EPOCH)
@@ -124,7 +129,10 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
124
129
 
125
130
  Ok(EmbeddedFile {
126
131
  data,
132
+ metadata: Metadata {
133
+ hash,
127
- metadata: Metadata { hash, last_modified },
134
+ last_modified: source_date_epoch.or(last_modified),
135
+ },
128
136
  })
129
137
  }
130
138