Skip to content

Commit

Permalink
drop all ffi functions not used by harmonia
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 authored and mergify[bot] committed Mar 21, 2024
1 parent 96145da commit aa248fd
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 204 deletions.
7 changes: 0 additions & 7 deletions libnixstore/include/nix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ namespace libnixstore {
void init();
bool is_valid_path(rust::Str path);
rust::String query_path_hash(rust::Str path);
rust::String query_deriver(rust::Str path);
InternalPathInfo query_path_info(rust::Str path, bool base32);
rust::String query_raw_realisation(rust::Str output_id);
rust::String query_path_from_hash_part(rust::Str hash_part);
rust::Vec<rust::String> compute_fs_closure(bool flip_direction,
bool include_outputs,
rust::Vec<rust::Str> paths);
rust::Vec<rust::String> topo_sort_paths(rust::Vec<rust::Str> paths);
rust::String follow_links_to_store_path(rust::Str path);
void export_paths(int32_t fd, rust::Vec<rust::Str> paths);
void import_paths(int32_t fd, bool dont_check_signs);
rust::String hash_file(rust::Str algo, bool base32, rust::Str path);
Expand Down
107 changes: 0 additions & 107 deletions libnixstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,16 @@ mod ffi {
unsafe extern "C++" {
include!("libnixstore/include/nix.h");

// bindings that are also available in the perl bindings
fn init();
fn is_valid_path(path: &str) -> Result<bool>;
fn query_path_hash(path: &str) -> Result<String>;
fn query_deriver(path: &str) -> Result<String>;
fn query_path_info(path: &str, base32: bool) -> Result<InternalPathInfo>;
fn query_raw_realisation(output_id: &str) -> Result<String>;
fn query_path_from_hash_part(hash_part: &str) -> Result<String>;
fn compute_fs_closure(
flip_direction: bool,
include_outputs: bool,
paths: Vec<&str>,
) -> Result<Vec<String>>;
fn topo_sort_paths(paths: Vec<&str>) -> Result<Vec<String>>;
fn follow_links_to_store_path(path: &str) -> Result<String>;
fn export_paths(fd: i32, paths: Vec<&str>) -> Result<()>;
fn import_paths(fd: i32, dont_check_signs: bool) -> Result<()>;
fn hash_file(algo: &str, base32: bool, path: &str) -> Result<String>;
fn hash_string(algo: &str, base32: bool, s: &str) -> Result<String>;
fn convert_hash(algo: &str, s: &str, to_base_32: bool) -> Result<String>;
fn sign_string(secret_key: &str, msg: &str) -> Result<String>;
fn check_signature(public_key: &str, sig: &str, msg: &str) -> Result<bool>;
fn derivation_from_path(drv_path: &str) -> Result<InternalDrv>;
fn add_temp_root(store_path: &str) -> Result<()>;
fn get_bin_dir() -> String;
fn get_store_dir() -> String;

// additional but useful for harmonia
fn get_build_log(derivation_path: &str) -> Result<String>;
fn get_nar_list(store_path: &str) -> Result<String>;
}
Expand Down Expand Up @@ -157,16 +139,6 @@ pub fn query_path_hash(path: &str) -> Result<String, cxx::Exception> {
ffi::query_path_hash(path)
}

#[inline]
#[must_use]
/// Return deriver of a valid path. It is permitted to omit the name part of the store path.
pub fn query_deriver(path: &str) -> Option<String> {
match ffi::query_deriver(path) {
Ok(v) => string_to_opt(v),
Err(_) => None,
}
}

#[inline]
/// Query information about a valid path. It is permitted to omit the name part of the store path.
/// The `radix` field affects only the `narHash` field of the result.
Expand All @@ -183,16 +155,6 @@ pub fn query_path_info(path: &str, radix: Radix) -> Result<PathInfo, cxx::Except
})
}

#[inline]
#[must_use]
/// Query the information about a realisation
pub fn query_raw_realisation(output_id: &str) -> Option<String> {
match ffi::query_raw_realisation(output_id) {
Ok(v) => string_to_opt(v),
Err(_) => None,
}
}

#[inline]
#[must_use]
/// Query the full store path given the hash part of a valid store path, or empty if the path
Expand All @@ -204,61 +166,6 @@ pub fn query_path_from_hash_part(hash_part: &str) -> Option<String> {
}
}

#[inline]
/// Returns all store paths in the file system closure of `storePath`
///
/// That is, all paths than can be directly or indirectly reached from it. If `flip_direction` is
/// true, the set of paths that can reach `storePath` is returned; that is, the closures under the
/// `referrers` relation instead of the `references` relation is returned. If `include_outputs` is
/// `true` then closure will additionally include all outputs of every derivation in the closure.
pub fn compute_fs_closure(
flip_direction: bool,
include_outputs: bool,
paths: Vec<&str>,
) -> Result<Vec<String>, cxx::Exception> {
ffi::compute_fs_closure(flip_direction, include_outputs, paths)
}

#[inline]
/// Sort a set of paths topologically under the references relation. If `p` refers to `q`, then `p`
/// precedes `q` in this list.
pub fn topo_sort_paths(paths: Vec<&str>) -> Result<Vec<String>, cxx::Exception> {
ffi::topo_sort_paths(paths)
}

#[inline]
/// Follow symlinks until we end up with a path in the Nix store. Will transform the results to
/// store paths.
pub fn follow_links_to_store_path(path: &str) -> Result<String, cxx::Exception> {
ffi::follow_links_to_store_path(path)
}

#[inline]
/// Export multiple paths in the format expected by `nix-store --import`.
pub fn export_paths(fd: i32, paths: Vec<&str>) -> Result<(), cxx::Exception> {
ffi::export_paths(fd, paths)
}

#[inline]
/// Import a sequence of NAR dumps created by `export_paths()` into the Nix store. Optionally, the
/// contents of the NARs are preloaded into the specified FS accessor to speed up subsequent
/// access.
pub fn import_paths(fd: i32, dont_check_signs: bool) -> Result<(), cxx::Exception> {
ffi::import_paths(fd, dont_check_signs)
}

#[inline]
/// Compute the hash of the given file.
pub fn hash_file(algo: &str, radix: Radix, path: &str) -> Result<String, cxx::Exception> {
ffi::hash_file(algo, matches!(radix, Radix::Base32), path)
}

#[inline]
/// Compute the hash of the given string.
pub fn hash_string(algo: &str, radix: Radix, s: &str) -> Result<String, cxx::Exception> {
ffi::hash_string(algo, matches!(radix, Radix::Base32), s)
}

#[inline]
/// Parse the hash from a string representation in the format `[<type>:]<base16|base32|base64>` or
/// `<type>-<base64>` to a string representation of the hash, in `base-16`, `base-32`. The result
Expand Down Expand Up @@ -304,20 +211,6 @@ pub fn derivation_from_path(drv_path: &str) -> Result<Drv, cxx::Exception> {
})
}

#[inline]
/// Add a store path as a temporary root of the garbage collector. The root disappears as soon as
/// we exit.
pub fn add_temp_root(store_path: &str) -> Result<(), cxx::Exception> {
ffi::add_temp_root(store_path)
}

#[inline]
#[must_use]
/// Return the path to the directory where the main programs are stored.
pub fn get_bin_dir() -> String {
ffi::get_bin_dir()
}

#[inline]
#[must_use]
/// Returns the path to the directory where nix store sources and derived files.
Expand Down
90 changes: 0 additions & 90 deletions libnixstore/src/nix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ rust::String query_path_hash(rust::Str path) {
->narHash.to_string(nix::HashFormat::Nix32, true);
}

rust::String query_deriver(rust::Str path) {
auto store = get_store();
nix::ref<const nix::ValidPathInfo> info =
store->queryPathInfo(store->parseStorePath(STRING_VIEW(path)));
return extract_opt_path(info->deriver);
}

InternalPathInfo query_path_info(rust::Str path, bool base32) {
auto store = get_store();
nix::ref<const nix::ValidPathInfo> info =
Expand Down Expand Up @@ -128,85 +121,11 @@ InternalPathInfo query_path_info(rust::Str path, bool base32) {
};
}

rust::String query_raw_realisation(rust::Str output_id) {
std::shared_ptr<const nix::Realisation> realisation =
get_store()->queryRealisation(
nix::DrvOutput::parse(STRING_VIEW(output_id)));
if (!realisation) {
// TODO(conni2461): Replace with option
return "";
}
return realisation->toJSON().dump();
}

rust::String query_path_from_hash_part(rust::Str hash_part) {
return extract_opt_path(
get_store()->queryPathFromHashPart(STRING_VIEW(hash_part)));
}

rust::Vec<rust::String> compute_fs_closure(bool flip_direction,
bool include_outputs,
rust::Vec<rust::Str> paths) {
auto store = get_store();
nix::StorePathSet path_set;
for (auto &path : paths) {
store->computeFSClosure(store->parseStorePath(STRING_VIEW(path)), path_set,
flip_direction, include_outputs);
}
return extract_path_set(path_set);
}

rust::Vec<rust::String> topo_sort_paths(rust::Vec<rust::Str> paths) {
auto store = get_store();
nix::StorePathSet path_set;
for (auto &path : paths) {
path_set.insert(store->parseStorePath(STRING_VIEW(path)));
}
nix::StorePaths sorted = store->topoSortPaths(path_set);
rust::Vec<rust::String> res;
res.reserve(sorted.size());
for (auto &path : sorted) {
res.push_back(store->printStorePath(path));
}
return res;
}

rust::String follow_links_to_store_path(rust::Str path) {
auto store = get_store();
return store->printStorePath(
store->followLinksToStorePath(STRING_VIEW(path)));
}

void export_paths(int32_t fd, rust::Vec<rust::Str> paths) {
auto store = get_store();
nix::StorePathSet path_set;
for (auto &path : paths) {
path_set.insert(store->parseStorePath(STRING_VIEW(path)));
}
nix::FdSink sink(fd);
store->exportPaths(path_set, sink);
}

void import_paths(int32_t fd, bool dont_check_signs) {
nix::FdSource source(fd);
get_store()->importPaths(source, dont_check_signs ? nix::NoCheckSigs
: nix::CheckSigs);
}

rust::String hash_file(rust::Str algo, bool base32, rust::Str path) {
nix::Hash h =
nix::hashFile(nix::parseHashAlgo(STRING_VIEW(algo)), STRING_VIEW(path));
return h.to_string(base32 ? nix::HashFormat::Nix32 : nix::HashFormat::Base16,
false);
}

rust::String hash_string(rust::Str algo, bool base32, rust::Str s) {
nix::Hash h =
nix::hashString(nix::parseHashAlgo(STRING_VIEW(algo)), STRING_VIEW(s));
return h.to_string(base32 ? nix::HashFormat::Nix32 : nix::HashFormat::Base16,
false);
}

rust::String convert_hash(rust::Str algo, rust::Str s, bool to_base_32) {
nix::Hash h = nix::Hash::parseAny(STRING_VIEW(s),
nix::parseHashAlgo(STRING_VIEW(algo)));
Expand Down Expand Up @@ -269,15 +188,6 @@ InternalDrv derivation_from_path(rust::Str drv_path) {
};
}

void add_temp_root(rust::Str store_path) {
auto store = get_store();
store->addTempRoot(store->parseStorePath(STRING_VIEW(store_path)));
}

rust::String get_bin_dir() {
return nix::settings.nixBinDir;
}

rust::String get_store_dir() {
return nix::settings.nixStore;
}
Expand Down

0 comments on commit aa248fd

Please sign in to comment.