[Teton] Move console/shell to rust. WIP
This commit is contained in:
parent
76f8795a46
commit
18e512cf1f
17 changed files with 409 additions and 5 deletions
15
rust/lib/victoriafalls/Cargo.toml
Normal file
15
rust/lib/victoriafalls/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "victoriafalls"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
mammoth = { path = "../mammoth" }
|
||||
yellowstone = { path = "../yellowstone" }
|
||||
yunq = {path = "../yunq"}
|
||||
yunq-derive = {path = "../yunq-derive"}
|
||||
|
||||
[build-dependencies]
|
||||
yunqc = {path = "../../../yunq/rust"}
|
||||
|
||||
|
||||
14
rust/lib/victoriafalls/build.rs
Normal file
14
rust/lib/victoriafalls/build.rs
Normal 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.");
|
||||
}
|
||||
42
rust/lib/victoriafalls/src/file.rs
Normal file
42
rust/lib/victoriafalls/src/file.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::OpenFileRequest;
|
||||
use crate::VFSClient;
|
||||
use alloc::string::ToString;
|
||||
use mammoth::zion::ZError;
|
||||
|
||||
static mut VFS_CLIENT: Option<VFSClient> = None;
|
||||
|
||||
fn get_client() -> &'static mut VFSClient {
|
||||
unsafe {
|
||||
if let None = VFS_CLIENT {
|
||||
let endpoint_cap = yellowstone::from_init_endpoint()
|
||||
.get_endpoint(&yellowstone::GetEndpointRequest {
|
||||
endpoint_name: "victoriafalls".to_string(),
|
||||
})
|
||||
.expect("Failed to get VFS endpoint");
|
||||
|
||||
VFS_CLIENT = Some(VFSClient::new(endpoint_cap.endpoint));
|
||||
}
|
||||
VFS_CLIENT.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
memory: mammoth::mem::MemoryRegion,
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub fn open(path: &str) -> Result<Self, ZError> {
|
||||
let vfs = get_client();
|
||||
let resp = vfs.open_file(&OpenFileRequest {
|
||||
path: path.to_string(),
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
memory: mammoth::mem::MemoryRegion::from_cap(resp.memory)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn slice(&self, offset: usize, len: usize) -> &[u8] {
|
||||
&self.memory.slice()[offset..offset + len]
|
||||
}
|
||||
}
|
||||
7
rust/lib/victoriafalls/src/lib.rs
Normal file
7
rust/lib/victoriafalls/src/lib.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#![no_std]
|
||||
|
||||
use core::include;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));
|
||||
|
||||
pub mod file;
|
||||
Loading…
Add table
Add a link
Reference in a new issue