feat: Store.get_storedir()
(cherry picked from commit 6f4ba636f1e563167e6456d42c9fb6f65c9ca504)
This commit is contained in:
parent
3d3c77eced
commit
c9d54ccbc6
5 changed files with 63 additions and 4 deletions
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -156,11 +156,11 @@
|
||||||
"pre-commit-hooks": "pre-commit-hooks"
|
"pre-commit-hooks": "pre-commit-hooks"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1732892090,
|
"lastModified": 1734340930,
|
||||||
"narHash": "sha256-Ka/uNdaqpTAiVL++4MPHg8fG5o1tiJeY6G2t5UiKhd8=",
|
"narHash": "sha256-BeyD6r1rQWaL+K7vLRSiCcZG4czEfmBYEL3kvBS2nGw=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nix",
|
"repo": "nix",
|
||||||
"rev": "64000481168d1da9d2519f055dd1fdee22275c21",
|
"rev": "2f32cf6d90df599d620eea5c48b9469f1c251025",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
3
rust/Cargo.lock
generated
3
rust/Cargo.lock
generated
|
|
@ -1,6 +1,6 @@
|
||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "Inflector"
|
name = "Inflector"
|
||||||
|
|
@ -346,6 +346,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nix-c-raw",
|
"nix-c-raw",
|
||||||
"nix-util",
|
"nix-util",
|
||||||
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
name = "nix-store"
|
name = "nix-store"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
@ -11,3 +12,6 @@ anyhow = "1.0.79"
|
||||||
nix-util = { path = "../nix-util" }
|
nix-util = { path = "../nix-util" }
|
||||||
nix-c-raw = { path = "../nix-c-raw" }
|
nix-c-raw = { path = "../nix-c-raw" }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
pkg-config = "0.3.30"
|
||||||
|
|
|
||||||
39
rust/nix-store/build.rs
Normal file
39
rust/nix-store/build.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
fn main() {
|
||||||
|
// Get nix version
|
||||||
|
let nix_version = pkg_config::probe_library("nix-store-c").unwrap().version;
|
||||||
|
|
||||||
|
// Generate version flags
|
||||||
|
// Unfortunately, Rust doesn't give us a "greater than" operator in conditional
|
||||||
|
// compilation, so we pre-evaluate the version comparisons here, making use
|
||||||
|
// of the multi-valued nature of Rust cfgs.
|
||||||
|
let relevant_versions = vec!["2.26"];
|
||||||
|
let versions = relevant_versions
|
||||||
|
.iter()
|
||||||
|
.map(|v| format!("\"{}\"", v))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(",");
|
||||||
|
|
||||||
|
// Declare the known versions, so that Rust can warn about unknown versions
|
||||||
|
// that aren't part of `relevant_versions` yet - feel free to add entries.
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-check-cfg=cfg(nix_at_least,values({}))",
|
||||||
|
versions
|
||||||
|
);
|
||||||
|
|
||||||
|
let nix_version = nix_version.split('.').collect::<Vec<&str>>();
|
||||||
|
let nix_version = (
|
||||||
|
nix_version[0].parse::<u32>().unwrap(),
|
||||||
|
nix_version[1].parse::<u32>().unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
for version_str in relevant_versions {
|
||||||
|
let version = version_str.split('.').collect::<Vec<&str>>();
|
||||||
|
let version = (
|
||||||
|
version[0].parse::<u32>().unwrap(),
|
||||||
|
version[1].parse::<u32>().unwrap(),
|
||||||
|
);
|
||||||
|
if nix_version >= version {
|
||||||
|
println!("cargo:rustc-cfg=nix_at_least=\"{}\"", version_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -172,6 +172,21 @@ impl Store {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(nix_at_least = "2.26")]
|
||||||
|
#[doc(alias = "nix_store_get_storedir")]
|
||||||
|
pub fn get_storedir(&mut self) -> Result<String> {
|
||||||
|
let mut r = result_string_init!();
|
||||||
|
unsafe {
|
||||||
|
check_call!(raw::store_get_storedir(
|
||||||
|
&mut self.context,
|
||||||
|
self.inner.ptr(),
|
||||||
|
Some(callback_get_result_string),
|
||||||
|
callback_get_result_string_data(&mut r)
|
||||||
|
))
|
||||||
|
}?;
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
pub fn weak_ref(&self) -> StoreWeak {
|
pub fn weak_ref(&self) -> StoreWeak {
|
||||||
StoreWeak {
|
StoreWeak {
|
||||||
inner: Arc::downgrade(&self.inner),
|
inner: Arc::downgrade(&self.inner),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue