Skip to content

Commit ab03a80

Browse files
authored
Merge pull request #364 from AerynOS/feat/stone-ffi
Feat/stone ffi
2 parents 3d70f7a + 3d2df67 commit ab03a80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2787
-820
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["boulder", "moss", "crates/*"]
2+
members = ["boulder", "moss", "libstone", "crates/*"]
33
default-members = ["moss"]
44
resolver = "3"
55

@@ -95,6 +95,8 @@ zbus = { version = "5.1.1", default-features = false, features = ["tokio"] }
9595
infer = "0.19.0"
9696
tempfile = "3.20.0"
9797
kdl = "6.5.0"
98+
libc = "0.2.62"
99+
cbindgen = "0.29.2"
98100

99101
[workspace.lints.rust]
100102
rust_2018_idioms = { level = "warn", priority = -1 }

boulder/src/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::{io, num::NonZeroU64};
66

77
use fs_err as fs;
88
use itertools::Itertools;
9+
use stone::StoneDigestWriterHasher;
910
use thiserror::Error;
1011

11-
use stone::write::digest;
1212
use stone_recipe::{Package, script};
1313

1414
use crate::{Macros, Paths, Recipe, Timing, build, container, timing, util};
@@ -60,7 +60,7 @@ impl<'a> Packager<'a> {
6060

6161
pub fn package(&self, timing: &mut Timing) -> Result<(), Error> {
6262
// Hasher used for calculating file digests
63-
let mut hasher = digest::Hasher::new();
63+
let mut hasher = StoneDigestWriterHasher::new();
6464

6565
let timer = timing.begin(timing::Kind::Analyze);
6666

boulder/src/package/analysis.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
};
1010

1111
use moss::{Dependency, Provider};
12-
use stone::write::digest;
12+
use stone::StoneDigestWriterHasher;
1313
use tui::{ProgressBar, ProgressStyle, Styled};
1414

1515
use crate::{Paths, Recipe};
@@ -25,12 +25,17 @@ pub struct Chain<'a> {
2525
recipe: &'a Recipe,
2626
paths: &'a Paths,
2727
collector: &'a Collector,
28-
hasher: &'a mut digest::Hasher,
28+
hasher: &'a mut StoneDigestWriterHasher,
2929
pub buckets: BTreeMap<String, Bucket>,
3030
}
3131

3232
impl<'a> Chain<'a> {
33-
pub fn new(paths: &'a Paths, recipe: &'a Recipe, collector: &'a Collector, hasher: &'a mut digest::Hasher) -> Self {
33+
pub fn new(
34+
paths: &'a Paths,
35+
recipe: &'a Recipe,
36+
collector: &'a Collector,
37+
hasher: &'a mut StoneDigestWriterHasher,
38+
) -> Self {
3439
Self {
3540
handlers: vec![
3641
Box::new(handler::ignore_blocked),
@@ -157,7 +162,7 @@ impl Bucket {
157162
pub struct BucketMut<'a> {
158163
pub providers: &'a mut BTreeSet<Provider>,
159164
pub dependencies: &'a mut BTreeSet<Dependency>,
160-
pub hasher: &'a mut digest::Hasher,
165+
pub hasher: &'a mut StoneDigestWriterHasher,
161166
pub recipe: &'a Recipe,
162167
pub paths: &'a Paths,
163168
}

boulder/src/package/collect.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use astr::AStr;
1313
use fs_err as fs;
1414
use glob::Pattern;
1515
use nix::libc::{S_IFDIR, S_IRGRP, S_IROTH, S_IRWXU, S_IXGRP, S_IXOTH};
16-
use stone::payload::{Layout, layout};
17-
use stone::write::digest;
16+
use stone::{StoneDigestWriter, StoneDigestWriterHasher, StonePayloadLayoutFile, StonePayloadLayoutRecord};
1817
use thiserror::Error;
1918

2019
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -72,7 +71,7 @@ impl Collector {
7271
}
7372

7473
/// Produce a [`PathInfo`] from the provided [`Path`]
75-
pub fn path(&self, path: &Path, hasher: &mut digest::Hasher) -> Result<PathInfo, Error> {
74+
pub fn path(&self, path: &Path, hasher: &mut StoneDigestWriterHasher) -> Result<PathInfo, Error> {
7675
let metadata = fs::metadata(path)?;
7776
self.path_with_metadata(path.to_path_buf(), &metadata, hasher)
7877
}
@@ -81,7 +80,7 @@ impl Collector {
8180
&self,
8281
path: PathBuf,
8382
metadata: &Metadata,
84-
hasher: &mut digest::Hasher,
83+
hasher: &mut StoneDigestWriterHasher,
8584
) -> Result<PathInfo, Error> {
8685
let target_path = Path::new("/").join(path.strip_prefix(&self.root).expect("path is ancestor of root"));
8786

@@ -96,7 +95,7 @@ impl Collector {
9695
pub fn enumerate_paths(
9796
&self,
9897
subdir: Option<(PathBuf, Metadata)>,
99-
hasher: &mut digest::Hasher,
98+
hasher: &mut StoneDigestWriterHasher,
10099
) -> Result<Vec<PathInfo>, Error> {
101100
let mut paths = vec![];
102101

@@ -139,7 +138,7 @@ impl Collector {
139138
pub struct PathInfo {
140139
pub path: PathBuf,
141140
pub target_path: PathBuf,
142-
pub layout: Layout,
141+
pub layout: StonePayloadLayoutRecord,
143142
pub size: u64,
144143
pub package: String,
145144
}
@@ -149,7 +148,7 @@ impl PathInfo {
149148
path: PathBuf,
150149
target_path: PathBuf,
151150
metadata: &Metadata,
152-
hasher: &mut digest::Hasher,
151+
hasher: &mut StoneDigestWriterHasher,
153152
package: String,
154153
) -> Result<Self, Error> {
155154
let layout = layout_from_metadata(&path, &target_path, metadata, hasher)?;
@@ -163,19 +162,19 @@ impl PathInfo {
163162
})
164163
}
165164

166-
pub fn restat(&mut self, hasher: &mut digest::Hasher) -> Result<(), Error> {
165+
pub fn restat(&mut self, hasher: &mut StoneDigestWriterHasher) -> Result<(), Error> {
167166
let metadata = fs::metadata(&self.path)?;
168167
self.layout = layout_from_metadata(&self.path, &self.target_path, &metadata, hasher)?;
169168
self.size = metadata.size();
170169
Ok(())
171170
}
172171

173172
pub fn is_file(&self) -> bool {
174-
matches!(self.layout.entry, layout::Entry::Regular(_, _))
173+
matches!(self.layout.file, StonePayloadLayoutFile::Regular(_, _))
175174
}
176175

177176
pub fn file_hash(&self) -> Option<u128> {
178-
if let layout::Entry::Regular(hash, _) = &self.layout.entry {
177+
if let StonePayloadLayoutFile::Regular(hash, _) = &self.layout.file {
179178
Some(*hash)
180179
} else {
181180
None
@@ -200,8 +199,8 @@ fn layout_from_metadata(
200199
path: &Path,
201200
target_path: &Path,
202201
metadata: &Metadata,
203-
hasher: &mut digest::Hasher,
204-
) -> Result<Layout, Error> {
202+
hasher: &mut StoneDigestWriterHasher,
203+
) -> Result<StonePayloadLayoutRecord, Error> {
205204
// Strip /usr
206205
let target: AStr = target_path
207206
.strip_prefix("/usr")
@@ -211,29 +210,29 @@ fn layout_from_metadata(
211210

212211
let file_type = metadata.file_type();
213212

214-
Ok(Layout {
213+
Ok(StonePayloadLayoutRecord {
215214
uid: metadata.uid(),
216215
gid: metadata.gid(),
217216
mode: metadata.mode(),
218217
tag: 0,
219-
entry: if file_type.is_symlink() {
218+
file: if file_type.is_symlink() {
220219
let source = fs::read_link(path)?;
221220

222-
layout::Entry::Symlink(source.to_string_lossy().into(), target)
221+
StonePayloadLayoutFile::Symlink(source.to_string_lossy().into(), target)
223222
} else if file_type.is_dir() {
224-
layout::Entry::Directory(target)
223+
StonePayloadLayoutFile::Directory(target)
225224
} else if file_type.is_char_device() {
226-
layout::Entry::CharacterDevice(target)
225+
StonePayloadLayoutFile::CharacterDevice(target)
227226
} else if file_type.is_block_device() {
228-
layout::Entry::BlockDevice(target)
227+
StonePayloadLayoutFile::BlockDevice(target)
229228
} else if file_type.is_fifo() {
230-
layout::Entry::Fifo(target)
229+
StonePayloadLayoutFile::Fifo(target)
231230
} else if file_type.is_socket() {
232-
layout::Entry::Socket(target)
231+
StonePayloadLayoutFile::Socket(target)
233232
} else {
234233
hasher.reset();
235234

236-
let mut digest_writer = digest::Writer::new(io::sink(), hasher);
235+
let mut digest_writer = StoneDigestWriter::new(io::sink(), hasher);
237236
let mut file = fs::File::open(path)?;
238237

239238
// Copy bytes to null sink so we don't
@@ -242,7 +241,7 @@ fn layout_from_metadata(
242241

243242
let hash = hasher.digest128();
244243

245-
layout::Entry::Regular(hash, target)
244+
StonePayloadLayoutFile::Regular(hash, target)
246245
},
247246
})
248247
}

boulder/src/package/emit.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use fs_err::{self as fs, File};
1111
use itertools::Itertools;
1212
use moss::{Dependency, Provider, package::Meta};
1313
use regex::Regex;
14+
use stone::{StoneHeaderV1FileType, StoneWriteError, StoneWriter};
1415
use thiserror::Error;
1516
use tui::{ProgressBar, ProgressStyle, Styled};
1617

@@ -183,7 +184,7 @@ fn emit_package(paths: &Paths, package: &Package<'_>) -> Result<(), Error> {
183184
let mut out_file = File::create(out_path)?;
184185

185186
// Create stone binary writer
186-
let mut writer = stone::Writer::new(&mut out_file, stone::header::v1::FileType::Binary)?;
187+
let mut writer = StoneWriter::new(&mut out_file, StoneHeaderV1FileType::Binary)?;
187188

188189
// Add metadata
189190
{
@@ -244,7 +245,7 @@ fn emit_package(paths: &Paths, package: &Package<'_>) -> Result<(), Error> {
244245
#[derive(Debug, Error)]
245246
pub enum Error {
246247
#[error("stone binary writer")]
247-
StoneBinaryWriter(#[from] stone::write::Error),
248+
StoneBinaryWriter(#[from] StoneWriteError),
248249
#[error("manifest")]
249250
Manifest(#[from] manifest::Error),
250251
#[error("io")]

boulder/src/package/emit/manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use std::{collections::BTreeSet, io, path::PathBuf};
66

7+
use stone::StoneWriteError;
78
use thiserror::Error;
89

910
use crate::{Architecture, Paths, Recipe};
@@ -69,7 +70,7 @@ impl<'a> Manifest<'a> {
6970
#[derive(Debug, Error)]
7071
pub enum Error {
7172
#[error("stone binary writer")]
72-
StoneWriter(#[from] stone::write::Error),
73+
StoneWriter(#[from] StoneWriteError),
7374
#[error("encode json")]
7475
Json(#[from] serde_json::Error),
7576
#[error("io")]

boulder/src/package/emit/manifest/binary.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use std::{collections::BTreeSet, path::Path};
77
use fs_err::File;
88
use moss::Dependency;
99
use stone::{
10-
header::v1::FileType,
11-
payload::{self, meta},
10+
StoneHeaderV1FileType, StonePayloadMetaPrimitive, StonePayloadMetaRecord, StonePayloadMetaTag, StoneWriter,
1211
};
1312

1413
use super::Error;
@@ -17,7 +16,7 @@ use crate::package::emit::Package;
1716
pub fn write(path: &Path, packages: &BTreeSet<&Package<'_>>, build_deps: &BTreeSet<String>) -> Result<(), Error> {
1817
let mut output = File::create(path)?;
1918

20-
let mut writer = stone::Writer::new(&mut output, FileType::BuildManifest)?;
19+
let mut writer = StoneWriter::new(&mut output, StoneHeaderV1FileType::BuildManifest)?;
2120

2221
// Add each package
2322
for package in packages {
@@ -29,9 +28,9 @@ pub fn write(path: &Path, packages: &BTreeSet<&Package<'_>>, build_deps: &BTreeS
2928
// Add build deps
3029
for name in build_deps {
3130
if let Ok(dep) = Dependency::from_name(name) {
32-
payload.push(payload::Meta {
33-
tag: meta::Tag::BuildDepends,
34-
kind: meta::Kind::Dependency(dep.kind.into(), dep.name),
31+
payload.push(StonePayloadMetaRecord {
32+
tag: StonePayloadMetaTag::BuildDepends,
33+
primitive: StonePayloadMetaPrimitive::Dependency(dep.kind.into(), dep.name),
3534
});
3635
}
3736
}

boulder/src/package/emit/manifest/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn write(
5353
.analysis
5454
.paths
5555
.iter()
56-
.map(|p| format!("/usr/{}", p.layout.entry.target()))
56+
.map(|p| format!("/usr/{}", p.layout.file.target()))
5757
.sorted()
5858
.collect();
5959

crates/astr/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ version.workspace = true
44
edition.workspace = true
55
rust-version.workspace = true
66

7+
[features]
8+
default = []
9+
diesel = ["dep:diesel"]
10+
711
[dependencies]
8-
diesel.workspace = true
912
stable_deref_trait = "1.2.1"
1013
triomphe.workspace = true
1114

15+
diesel = { workspace = true, optional = true }
16+
1217
[lints]
1318
workspace = true

0 commit comments

Comments
 (0)