mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
Move stuff around
This commit is contained in:
parent
ce3c41aef0
commit
a1ff43045b
10 changed files with 74 additions and 67 deletions
|
@ -18,7 +18,7 @@ libnixrust_LDFLAGS_USE += -Wl,-rpath,$(abspath $(d)/target/$(RUST_DIR))
|
||||||
libnixrust_LDFLAGS_USE_INSTALLED += -Wl,-rpath,$(libdir)
|
libnixrust_LDFLAGS_USE_INSTALLED += -Wl,-rpath,$(libdir)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(libnixrust_PATH): $(wildcard $(d)/src/*.rs) $(d)/Cargo.toml
|
$(libnixrust_PATH): $(call rwildcard, $(d)/src, *.rs) $(d)/Cargo.toml
|
||||||
$(trace-gen) cd nix-rust && CARGO_HOME=$$(if [[ -d vendor ]]; then echo vendor; fi) \
|
$(trace-gen) cd nix-rust && CARGO_HOME=$$(if [[ -d vendor ]]; then echo vendor; fi) \
|
||||||
$(libnixrust_BUILD_FLAGS) \
|
$(libnixrust_BUILD_FLAGS) \
|
||||||
RUSTC_BOOTSTRAP=1 cargo build $(RUST_MODE) $$(if [[ -d vendor ]]; then echo --offline; fi) \
|
RUSTC_BOOTSTRAP=1 cargo build $(RUST_MODE) $$(if [[ -d vendor ]]; then echo --offline; fi) \
|
||||||
|
|
42
nix-rust/src/c.rs
Normal file
42
nix-rust/src/c.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
use super::{foreign::{self, CBox}, error, util, store};
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn unpack_tarfile(
|
||||||
|
source: foreign::Source,
|
||||||
|
dest_dir: &str,
|
||||||
|
) -> CBox<Result<(), error::CppException>> {
|
||||||
|
CBox::new(util::tarfile::unpack_tarfile(source, dest_dir).map_err(|err| err.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_test() {
|
||||||
|
use crate::store::Store;
|
||||||
|
use futures::future::{FutureExt, TryFutureExt};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
let fut = async move {
|
||||||
|
let store: Box<dyn Store> = Box::new(store::BinaryCacheStore::new(
|
||||||
|
"https://cache.nixos.org".to_string(),
|
||||||
|
));
|
||||||
|
|
||||||
|
let path = store
|
||||||
|
.parse_store_path(&Path::new(
|
||||||
|
"/nix/store/7h7qgvs4kgzsn8a6rb273saxyqh4jxlz-konsole-18.12.3",
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
/*
|
||||||
|
let info = store.query_path_info(&path).await.unwrap();
|
||||||
|
|
||||||
|
eprintln!("INFO = {:?}", info);
|
||||||
|
*/
|
||||||
|
|
||||||
|
let closure = store.compute_path_closure(vec![path].into_iter().collect()).await.unwrap();
|
||||||
|
|
||||||
|
eprintln!("CLOSURE = {:?}", closure.len());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
tokio::run(fut.boxed().compat());
|
||||||
|
}
|
|
@ -12,3 +12,22 @@ impl std::io::Read for Source {
|
||||||
Ok(n)
|
Ok(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CBox<T> {
|
||||||
|
pub ptr: *mut libc::c_void,
|
||||||
|
phantom: std::marker::PhantomData<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> CBox<T> {
|
||||||
|
pub fn new(t: T) -> Self {
|
||||||
|
unsafe {
|
||||||
|
let size = std::mem::size_of::<T>();
|
||||||
|
let ptr = libc::malloc(size);
|
||||||
|
*(ptr as *mut T) = t; // FIXME: probably UB
|
||||||
|
Self {
|
||||||
|
ptr,
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,70 +1,9 @@
|
||||||
#![feature(await_macro, async_await)]
|
#![feature(await_macro, async_await)]
|
||||||
|
|
||||||
mod binary_cache_store;
|
mod c;
|
||||||
mod error;
|
mod error;
|
||||||
mod foreign;
|
mod foreign;
|
||||||
mod store;
|
mod store;
|
||||||
mod tarfile;
|
mod util;
|
||||||
mod path_info;
|
|
||||||
|
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|
||||||
pub struct CBox<T> {
|
|
||||||
pub ptr: *mut libc::c_void,
|
|
||||||
phantom: std::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> CBox<T> {
|
|
||||||
fn new(t: T) -> Self {
|
|
||||||
unsafe {
|
|
||||||
let size = std::mem::size_of::<T>();
|
|
||||||
let ptr = libc::malloc(size);
|
|
||||||
*(ptr as *mut T) = t; // FIXME: probably UB
|
|
||||||
Self {
|
|
||||||
ptr,
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn unpack_tarfile(
|
|
||||||
source: foreign::Source,
|
|
||||||
dest_dir: &str,
|
|
||||||
) -> CBox<Result<(), error::CppException>> {
|
|
||||||
CBox::new(tarfile::unpack_tarfile(source, dest_dir).map_err(|err| err.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn rust_test() {
|
|
||||||
use crate::store::Store;
|
|
||||||
use futures::future::{FutureExt, TryFutureExt};
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
let fut = async move {
|
|
||||||
let store: Box<dyn Store> = Box::new(binary_cache_store::BinaryCacheStore::new(
|
|
||||||
"https://cache.nixos.org".to_string(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let path = store
|
|
||||||
.parse_store_path(&Path::new(
|
|
||||||
"/nix/store/7h7qgvs4kgzsn8a6rb273saxyqh4jxlz-konsole-18.12.3",
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
/*
|
|
||||||
let info = store.query_path_info(&path).await.unwrap();
|
|
||||||
|
|
||||||
eprintln!("INFO = {:?}", info);
|
|
||||||
*/
|
|
||||||
|
|
||||||
let closure = store.compute_path_closure(vec![path].into_iter().collect()).await.unwrap();
|
|
||||||
|
|
||||||
eprintln!("CLOSURE = {:?}", closure.len());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
|
|
||||||
tokio::run(fut.boxed().compat());
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::store::{Store, StorePath};
|
use super::{Store, StorePath, PathInfo};
|
||||||
use crate::path_info::PathInfo;
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use futures::compat::Future01CompatExt;
|
use futures::compat::Future01CompatExt;
|
||||||
|
|
7
nix-rust/src/store/mod.rs
Normal file
7
nix-rust/src/store/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
mod binary_cache_store;
|
||||||
|
mod path_info;
|
||||||
|
mod store;
|
||||||
|
|
||||||
|
pub use binary_cache_store::BinaryCacheStore;
|
||||||
|
pub use path_info::PathInfo;
|
||||||
|
pub use store::{Store, StorePath};
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::path_info::PathInfo;
|
use super::PathInfo;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
1
nix-rust/src/util/mod.rs
Normal file
1
nix-rust/src/util/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod tarfile;
|
Loading…
Reference in a new issue