Compare commits
No commits in common. "0fc901f0322c634d1c9a4414759f2d638b65e5a2" and "2ac4bcfb9a95ba9ebb6b853e3fdabada0e2bfbf1" have entirely different histories.
0fc901f032
...
2ac4bcfb9a
5 changed files with 24 additions and 36 deletions
|
|
@ -15,8 +15,8 @@ path = "src/lib.rs"
|
|||
[features]
|
||||
default = []
|
||||
store = ["nixide-sys/nix-store-c"]
|
||||
exprs = ["store", "nixide-sys/nix-expr-c"]
|
||||
flakes = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"]
|
||||
expr = ["store", "nixide-sys/nix-expr-c"]
|
||||
flake = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.183"
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ 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;
|
||||
|
|
@ -67,6 +65,11 @@ 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())
|
||||
|
|
@ -76,39 +79,19 @@ impl EvalStateBuilder {
|
|||
}
|
||||
|
||||
// XXX: TODO
|
||||
#[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_flake_settings(FlakeSettings) { }
|
||||
|
||||
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
|
||||
)
|
||||
|
|
@ -128,7 +111,6 @@ 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::{ErrorContext, new_nixide_error};
|
||||
use crate::errors::{new_nixide_error, ErrorContext};
|
||||
use crate::sys;
|
||||
use crate::util::wrappers::AsInnerPtr;
|
||||
use crate::{EvalStateBuilder, NixideError};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
mod eval_state_builder_ext;
|
||||
mod fetchers_settings;
|
||||
mod flake_lock_flags;
|
||||
mod flake_reference;
|
||||
|
|
@ -5,9 +6,10 @@ 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 use flake_settings::FlakeSettings;
|
||||
pub use locked_flake::LockedFlake;
|
||||
pub(self) use flake_settings::FlakeSettings;
|
||||
pub(self) use locked_flake::LockedFlake;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ pub(crate) mod util;
|
|||
mod verbosity;
|
||||
mod version;
|
||||
|
||||
#[cfg(feature = "exprs")]
|
||||
#[cfg(feature = "expr")]
|
||||
mod expr;
|
||||
#[cfg(feature = "flakes")]
|
||||
#[cfg(feature = "flake")]
|
||||
mod flake;
|
||||
#[cfg(feature = "store")]
|
||||
mod store;
|
||||
|
|
@ -23,10 +23,8 @@ pub use errors::{NixError, NixideError, NixideResult};
|
|||
pub use verbosity::{NixVerbosity, set_verbosity};
|
||||
pub use version::NixVersion;
|
||||
|
||||
#[cfg(feature = "exprs")]
|
||||
#[cfg(feature = "expr")]
|
||||
pub use expr::{EvalState, EvalStateBuilder, Value};
|
||||
#[cfg(feature = "flakes")]
|
||||
pub use flake::{FlakeSettings, LockedFlake};
|
||||
#[cfg(feature = "store")]
|
||||
pub use store::{Store, StorePath};
|
||||
|
||||
|
|
@ -36,7 +34,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 = "exprs")]
|
||||
#[cfg(feature = "expr")]
|
||||
pub(crate) static mut INIT_LIBEXPR_STATUS: Option<NixideResult<()>> = None;
|
||||
|
||||
/// # Warning
|
||||
|
|
@ -55,6 +53,9 @@ 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)
|
||||
|
|
@ -73,6 +74,9 @@ 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