Compare commits
3 commits
2ac4bcfb9a
...
0fc901f032
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fc901f032 | |||
| 695c2d92dd | |||
| f6a514f34d |
5 changed files with 36 additions and 24 deletions
|
|
@ -15,8 +15,8 @@ path = "src/lib.rs"
|
|||
[features]
|
||||
default = []
|
||||
store = ["nixide-sys/nix-store-c"]
|
||||
expr = ["store", "nixide-sys/nix-expr-c"]
|
||||
flake = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"]
|
||||
exprs = ["store", "nixide-sys/nix-expr-c"]
|
||||
flakes = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.183"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ use std::ptr::{self, NonNull};
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::EvalState;
|
||||
#[cfg(feature = "flakes")]
|
||||
use crate::FlakeSettings;
|
||||
use crate::Store;
|
||||
use crate::errors::{ErrorContext, NixideResult};
|
||||
use crate::sys;
|
||||
|
|
@ -65,11 +67,6 @@ impl EvalStateBuilder {
|
|||
///
|
||||
/// Returns an error if the evaluation state cannot be built.
|
||||
pub fn build(self) -> NixideResult<EvalState> {
|
||||
// Load configuration first
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_eval_state_builder_load(ctx.as_ptr(), self.as_ptr())
|
||||
})?;
|
||||
|
||||
// Build the state
|
||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_eval_state_build(ctx.as_ptr(), self.as_ptr())
|
||||
|
|
@ -79,19 +76,39 @@ impl EvalStateBuilder {
|
|||
}
|
||||
|
||||
// XXX: TODO
|
||||
// fn set_flake_settings(FlakeSettings) { }
|
||||
#[cfg(feature = "flakes")]
|
||||
fn set_flake_settings(self, settings: FlakeSettings) -> NixideResult<Self> {
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_flake_settings_add_to_eval_state_builder(
|
||||
ctx.as_ptr(),
|
||||
settings.as_ptr(),
|
||||
self.as_ptr(),
|
||||
);
|
||||
})?;
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn load_ambient_settings(self) -> NixideResult<Self> {
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_eval_state_builder_load(ctx.as_ptr(), self.as_ptr());
|
||||
})?;
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn set_lookup_path<P: AsRef<str>>(self, paths: Vec<P>) -> NixideResult<Self> {
|
||||
let paths_len = paths.len();
|
||||
let paths_capacity = paths.capacity();
|
||||
|
||||
// XXX: TODO: use the `AsCArray` trait instead
|
||||
let mut ptrs: Vec<*const c_char> = paths
|
||||
.into_iter()
|
||||
.map(|p| {
|
||||
CString::new(p.as_ref())
|
||||
.unwrap_or_else(|err| {
|
||||
panic_issue_call_failed!(
|
||||
"Given string {} contains a NUL byte ({})",
|
||||
"given string {} contains a NUL byte ({})",
|
||||
p.as_ref(),
|
||||
err
|
||||
)
|
||||
|
|
@ -111,6 +128,7 @@ impl EvalStateBuilder {
|
|||
})
|
||||
.map(|()| self);
|
||||
|
||||
// ensure all allocated memory is dropped
|
||||
unsafe {
|
||||
Vec::from_raw_parts(ptr, paths_len, paths_capacity)
|
||||
.into_iter()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ptr::NonNull;
|
||||
|
||||
use crate::errors::{new_nixide_error, ErrorContext};
|
||||
use crate::errors::{ErrorContext, new_nixide_error};
|
||||
use crate::sys;
|
||||
use crate::util::wrappers::AsInnerPtr;
|
||||
use crate::{EvalStateBuilder, NixideError};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
mod eval_state_builder_ext;
|
||||
mod fetchers_settings;
|
||||
mod flake_lock_flags;
|
||||
mod flake_reference;
|
||||
|
|
@ -6,10 +5,9 @@ mod flake_reference_parse_flags;
|
|||
mod flake_settings;
|
||||
mod locked_flake;
|
||||
|
||||
pub(self) use eval_state_builder_ext::EvalStateBuilderExt;
|
||||
pub(self) use fetchers_settings::FetchersSettings;
|
||||
pub(self) use flake_lock_flags::{FlakeLockFlags, FlakeLockMode};
|
||||
pub(self) use flake_reference::FlakeReference;
|
||||
pub(self) use flake_reference_parse_flags::FlakeReferenceParseFlags;
|
||||
pub(self) use flake_settings::FlakeSettings;
|
||||
pub(self) use locked_flake::LockedFlake;
|
||||
pub use flake_settings::FlakeSettings;
|
||||
pub use locked_flake::LockedFlake;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ pub(crate) mod util;
|
|||
mod verbosity;
|
||||
mod version;
|
||||
|
||||
#[cfg(feature = "expr")]
|
||||
#[cfg(feature = "exprs")]
|
||||
mod expr;
|
||||
#[cfg(feature = "flake")]
|
||||
#[cfg(feature = "flakes")]
|
||||
mod flake;
|
||||
#[cfg(feature = "store")]
|
||||
mod store;
|
||||
|
|
@ -23,8 +23,10 @@ pub use errors::{NixError, NixideError, NixideResult};
|
|||
pub use verbosity::{NixVerbosity, set_verbosity};
|
||||
pub use version::NixVersion;
|
||||
|
||||
#[cfg(feature = "expr")]
|
||||
#[cfg(feature = "exprs")]
|
||||
pub use expr::{EvalState, EvalStateBuilder, Value};
|
||||
#[cfg(feature = "flakes")]
|
||||
pub use flake::{FlakeSettings, LockedFlake};
|
||||
#[cfg(feature = "store")]
|
||||
pub use store::{Store, StorePath};
|
||||
|
||||
|
|
@ -34,7 +36,7 @@ use util::wrappers::AsInnerPtr as _;
|
|||
pub(crate) static mut INIT_LIBUTIL_STATUS: Option<NixideResult<()>> = None;
|
||||
#[cfg(feature = "store")]
|
||||
pub(crate) static mut INIT_LIBSTORE_STATUS: Option<NixideResult<()>> = None;
|
||||
#[cfg(feature = "expr")]
|
||||
#[cfg(feature = "exprs")]
|
||||
pub(crate) static mut INIT_LIBEXPR_STATUS: Option<NixideResult<()>> = None;
|
||||
|
||||
/// # Warning
|
||||
|
|
@ -53,9 +55,6 @@ fn init_libutil() {
|
|||
}
|
||||
}
|
||||
|
||||
/// # TODO
|
||||
/// **Only run this if the "store" feature flag was enabled**
|
||||
///
|
||||
/// # Warning
|
||||
///
|
||||
/// > Rust's philosophy is that nothing happens before or after main and [ctor](https://github.com/mmastrac/rust-ctor)
|
||||
|
|
@ -74,9 +73,6 @@ fn init_libstore() {
|
|||
}
|
||||
}
|
||||
|
||||
/// # TODO
|
||||
/// **Only run this if the "expr" feature flag was enabled**
|
||||
//
|
||||
/// # Warning
|
||||
///
|
||||
/// > Rust's philosophy is that nothing happens before or after main and [ctor](https://github.com/mmastrac/rust-ctor)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue