Moved victoriafalls to sys dir in rust.

This commit is contained in:
Drew Galbraith 2025-02-07 18:05:38 -08:00
parent 9452e6c705
commit c8f84ec352
10 changed files with 39 additions and 19 deletions

View file

@ -0,0 +1,15 @@
[package]
name = "victoriafalls"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
yunq = { path = "../../lib/yunq" }
[build-dependencies]
yunqc = { path = "../../../yunq/rust" }
[[bin]]
name = "victoriafalls"

View file

@ -0,0 +1,14 @@
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.");
}

View file

@ -0,0 +1,11 @@
#![no_std]
#![no_main]
use mammoth::{define_entry, zion::z_err_t};
define_entry!();
#[no_mangle]
extern "C" fn main() -> z_err_t {
0
}

View file

@ -0,0 +1,27 @@
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())
}

View file

@ -0,0 +1,30 @@
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
}
}

View file

@ -0,0 +1,29 @@
#![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) };
}