fix build

This commit is contained in:
cy 2025-04-16 12:42:44 -04:00
parent a771785352
commit 84bbe5dcb4
Signed by: cy
SSH key fingerprint: SHA256:o/geVWV4om1QhUSkKvDQeW/eAihwnjyXkqMwrVdbuts
10 changed files with 147 additions and 135 deletions

View file

@ -181,7 +181,7 @@ mod ffi {
}
unsafe extern "C++" {
include!("nix.hpp");
include!("nixcp/src/bindings/nix.hpp");
// =========
// CNixStore
@ -190,16 +190,6 @@ mod ffi {
/// Mid-level wrapper for the Unix Domain Socket Nix Store.
type CNixStore;
/// Returns the path of the Nix store itself.
fn store_dir(self: Pin<&mut CNixStore>) -> String;
/*
/// Verifies that a path is indeed in the Nix store, then return the base store path.
///
/// Use parse_store_path instead.
fn to_store_path(self: Pin<&mut CNixStore>, path: &str) -> Result<String>;
*/
/// Queries information about a valid path.
fn query_path_info(
self: Pin<&mut CNixStore>,
@ -218,30 +208,6 @@ mod ffi {
include_derivers: bool,
) -> Result<UniquePtr<CxxVector<CxxString>>>;
/// Computes the closure of a list of valid paths.
///
/// This is the multi-path variant of `compute_fs_closure`.
/// If `flip_directions` is true, the set of paths that can reach `store_path` is
/// returned.
///
/// It's easier and more efficient to just pass a vector of slices
/// instead of wrangling with concrete "extern rust" / "extern C++"
/// types.
fn compute_fs_closure_multi(
self: Pin<&mut CNixStore>,
base_names: &[&[u8]],
flip_direction: bool,
include_outputs: bool,
include_derivers: bool,
) -> Result<UniquePtr<CxxVector<CxxString>>>;
/// Creates a NAR dump from a path.
fn nar_from_path(
self: Pin<&mut CNixStore>,
base_name: Vec<u8>,
sender: Box<AsyncWriteSender>,
) -> Result<()>;
/// Obtains a handle to the Nix store.
fn open_nix_store() -> Result<UniquePtr<CNixStore>>;
@ -252,22 +218,10 @@ mod ffi {
/// Mid-level wrapper for the `nix::ValidPathInfo` struct.
type CPathInfo;
/// Returns the SHA-256 hash of the store path.
fn nar_sha256_hash(self: Pin<&mut CPathInfo>) -> &[u8];
/// Returns the size of the NAR.
fn nar_size(self: Pin<&mut CPathInfo>) -> u64;
/// Returns the references of the store path.
fn references(self: Pin<&mut CPathInfo>) -> UniquePtr<CxxVector<CxxString>>;
/// Returns the possibly invalid signatures attached to the store path.
fn sigs(self: Pin<&mut CPathInfo>) -> UniquePtr<CxxVector<CxxString>>;
/// Returns the CA field of the store path.
fn ca(self: Pin<&mut CPathInfo>) -> String;
/// Returns the derivation that built this path
fn deriver(self: Pin<&mut CPathInfo>) -> String;
}
}

View file

@ -24,7 +24,7 @@ limitations under the License.
// Rust types directly where possible, so that the interfaces are
// satisfying to use from the Rust side via cxx.rs.
#include "attic/src/nix_store/bindings/nix.hpp"
#include "nixcp/src/bindings/nix.hpp"
static std::mutex g_init_nix_mutex;
static bool g_init_nix_done = false;
@ -34,14 +34,6 @@ static nix::StorePath store_path_from_rust(RBasePathSlice base_name) {
return nix::StorePath(sv);
}
static bool hash_is_sha256(const nix::Hash &hash) {
#ifdef ATTIC_NIX_2_20
return hash.algo == nix::HashAlgorithm::SHA256;
#else
return hash.type == nix::htSHA256;
#endif
}
// ========
// RustSink
// ========
@ -65,20 +57,6 @@ void RustSink::eof() {
CPathInfo::CPathInfo(nix::ref<const nix::ValidPathInfo> pi) : pi(pi) {}
RHashSlice CPathInfo::nar_sha256_hash() {
auto &hash = this->pi->narHash;
if (!hash_is_sha256(hash)) {
throw nix::Error("Only SHA-256 hashes are supported at the moment");
}
return RHashSlice(hash.hash, hash.hashSize);
}
uint64_t CPathInfo::nar_size() {
return this->pi->narSize;
}
std::unique_ptr<std::vector<std::string>> CPathInfo::sigs() {
std::vector<std::string> result;
for (auto&& elem : this->pi->sigs) {
@ -95,22 +73,6 @@ std::unique_ptr<std::vector<std::string>> CPathInfo::references() {
return std::make_unique<std::vector<std::string>>(result);
}
RString CPathInfo::ca() {
if (this->pi->ca) {
return RString(nix::renderContentAddress(this->pi->ca));
} else {
return RString("");
}
}
RString CPathInfo::deriver() {
if (this->pi->deriver) {
return RString((this->pi->deriver).to_string());
} else {
return RString("");
}
}
// =========
// CNixStore
// =========
@ -127,10 +89,6 @@ CNixStore::CNixStore() {
this->store = nix::openStore(nix::settings.storeUri.get(), params);
}
RString CNixStore::store_dir() {
return RString(this->store->storeDir);
}
std::unique_ptr<CPathInfo> CNixStore::query_path_info(RBasePathSlice base_name) {
auto store_path = store_path_from_rust(base_name);
@ -150,32 +108,6 @@ std::unique_ptr<std::vector<std::string>> CNixStore::compute_fs_closure(RBasePat
return std::make_unique<std::vector<std::string>>(result);
}
std::unique_ptr<std::vector<std::string>> CNixStore::compute_fs_closure_multi(RSlice<const RBasePathSlice> base_names, bool flip_direction, bool include_outputs, bool include_derivers) {
std::set<nix::StorePath> path_set, out;
for (auto&& base_name : base_names) {
path_set.insert(store_path_from_rust(base_name));
}
this->store->computeFSClosure(path_set, out, flip_direction, include_outputs, include_derivers);
std::vector<std::string> result;
for (auto&& elem : out) {
result.push_back(std::string(elem.to_string()));
}
return std::make_unique<std::vector<std::string>>(result);
}
void CNixStore::nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender) {
RustSink sink(std::move(sender));
std::string_view sv((const char *)base_name.data(), base_name.size());
nix::StorePath store_path(sv);
// exceptions will be thrown into Rust
this->store->narFromPath(store_path, sink);
sink.eof();
}
std::unique_ptr<CNixStore> open_nix_store() {
return std::make_unique<CNixStore>();
}

View file

@ -63,11 +63,8 @@ class CPathInfo {
nix::ref<const nix::ValidPathInfo> pi;
public:
CPathInfo(nix::ref<const nix::ValidPathInfo> pi);
RHashSlice nar_sha256_hash();
uint64_t nar_size();
std::unique_ptr<std::vector<std::string>> sigs();
std::unique_ptr<std::vector<std::string>> references();
RString ca();
};
class CNixStore {
@ -82,15 +79,9 @@ public:
bool flip_direction,
bool include_outputs,
bool include_derivers);
std::unique_ptr<std::vector<std::string>> compute_fs_closure_multi(
RSlice<const RBasePathSlice> base_names,
bool flip_direction,
bool include_outputs,
bool include_derivers);
void nar_from_path(RVec<unsigned char> base_name, RBox<AsyncWriteSender> sender);
};
std::unique_ptr<CNixStore> open_nix_store();
// Relies on our definitions
#include "attic/src/nix_store/bindings/mod.rs.h"
#include "nixcp/src/bindings/mod.rs.h"

View file

@ -14,7 +14,6 @@ use crate::store::Store;
#[derive(Debug, Clone)]
pub struct PathInfo {
pub deriver: Option<StorePath<String>>,
pub path: StorePath<String>,
pub signatures: Vec<String>,
pub references: Vec<StorePath<String>>,

View file

@ -46,7 +46,6 @@ impl Store {
task::spawn_blocking(move || {
let mut c_path_info = inner.store().query_path_info(path.to_string().as_bytes())?;
let deriver = c_path_info.pin_mut().deriver();
let signatures = c_path_info
.pin_mut()
.sigs()
@ -65,11 +64,6 @@ impl Store {
Ok(PathInfo {
path,
deriver: if deriver.is_empty() {
None
} else {
Some(StorePath::from_bytes(deriver.as_bytes())?)
},
signatures,
references,
})

View file

@ -159,7 +159,7 @@ impl<'a> Uploader<'a> {
signatures: Vec::new(),
ca: None,
system: None,
deriver: self.path.deriver.as_ref().map(|x| x.as_ref()),
deriver: None,
compression: Some("zstd"),
file_hash: None,
file_size: None,