Moved victoriafalls to sys dir in rust.
This commit is contained in:
parent
9452e6c705
commit
c8f84ec352
10 changed files with 39 additions and 19 deletions
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "victoriafalls"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
mammoth = { path = "../mammoth" }
|
||||
yellowstone-yunq = { path = "../yellowstone" }
|
||||
yunq = {path = "../yunq"}
|
||||
|
||||
[build-dependencies]
|
||||
yunqc = {path = "../../../yunq/rust"}
|
||||
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let input_file = "../../../sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq";
|
||||
|
||||
println!("cargo::rerun-if-changed={input_file}");
|
||||
|
||||
let input = fs::read_to_string(input_file).expect("Failed to read input file");
|
||||
|
||||
let code = yunqc::codegen(&input).expect("Failed to generate yunq code.");
|
||||
|
||||
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
|
||||
fs::write(out, code).expect("Failed to write generated code.");
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
use alloc::{
|
||||
string::{String, ToString as _},
|
||||
vec::Vec,
|
||||
};
|
||||
use mammoth::zion::ZError;
|
||||
|
||||
pub fn exists(path: &str) -> Result<bool, ZError> {
|
||||
let vfs = crate::get_client();
|
||||
let result = vfs.get_directory(&crate::GetDirectoryRequest {
|
||||
path: path.to_string(),
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(_) => Ok(true),
|
||||
Err(ZError::NOT_FOUND) => Ok(false),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ls(path: &str) -> Result<Vec<String>, ZError> {
|
||||
let vfs = crate::get_client();
|
||||
let result = vfs.get_directory(&crate::GetDirectoryRequest {
|
||||
path: path.to_string(),
|
||||
})?;
|
||||
|
||||
Ok(result.filenames.split(',').map(|s| s.to_string()).collect())
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
use crate::OpenFileRequest;
|
||||
use alloc::string::ToString;
|
||||
use mammoth::{cap::Capability, mem::MemoryRegion, zion::ZError};
|
||||
|
||||
pub struct File {
|
||||
memory: MemoryRegion,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub fn open(path: &str) -> Result<Self, ZError> {
|
||||
let vfs = crate::get_client();
|
||||
let resp = vfs.open_file(&OpenFileRequest {
|
||||
path: path.to_string(),
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
memory: mammoth::mem::MemoryRegion::from_cap(Capability::take(resp.memory))?,
|
||||
len: resp.size as usize,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn slice(&self) -> &[u8] {
|
||||
&self.memory.slice()[..self.len]
|
||||
}
|
||||
|
||||
pub fn memory(&self) -> &MemoryRegion {
|
||||
&self.memory
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#![no_std]
|
||||
|
||||
use core::include;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
|
||||
|
||||
pub mod dir;
|
||||
pub mod file;
|
||||
|
||||
static mut VFS_CLIENT: Option<VFSClient> = None;
|
||||
|
||||
fn get_client() -> &'static mut VFSClient {
|
||||
unsafe {
|
||||
if let None = VFS_CLIENT {
|
||||
let endpoint_cap = yellowstone_yunq::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone_yunq::GetEndpointRequest {
|
||||
endpoint_name: "victoriafalls".to_string(),
|
||||
})
|
||||
.expect("Failed to get VFS endpoint");
|
||||
|
||||
VFS_CLIENT = Some(VFSClient::new(Capability::take(endpoint_cap.endpoint)));
|
||||
}
|
||||
VFS_CLIENT.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_client(client: VFSClient) {
|
||||
unsafe { VFS_CLIENT = Some(client) };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue