nix-super/nix-rust/src/c.rs

56 lines
1.3 KiB
Rust
Raw Normal View History

2019-09-18 01:31:51 +03:00
use super::{
error,
foreign::{self, CBox},
util,
};
2019-09-16 00:09:30 +03:00
#[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() {
2019-09-18 01:31:51 +03:00
use crate::store::{self, Store};
2019-09-16 00:09:30 +03:00
use std::path::Path;
2019-12-04 16:32:28 +02:00
use tokio::runtime::Runtime;
2019-09-16 00:09:30 +03:00
let fut = async move {
let store: Box<dyn Store> = Box::new(store::BinaryCacheStore::new(
2019-12-04 22:01:16 +02:00
"http://cache.nixos.org".to_string(),
2019-09-16 00:09:30 +03:00
));
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);
*/
2019-12-04 16:32:28 +02:00
let closure = store
.compute_path_closure(vec![path].into_iter().collect())
.await
.unwrap();
2019-09-16 00:09:30 +03:00
eprintln!("CLOSURE = {:?}", closure.len());
};
2019-12-04 16:32:28 +02:00
let rt = Runtime::new().unwrap();
2019-09-18 01:31:51 +03:00
2019-12-04 16:32:28 +02:00
rt.block_on(fut);
/*
2019-09-18 01:31:51 +03:00
let file = std::fs::File::open("test.nar").unwrap();
crate::nar::parse(&mut std::io::BufReader::new(file)).unwrap();
2019-12-04 16:32:28 +02:00
*/
2019-09-16 00:09:30 +03:00
}