Work on custom binaries

This commit is contained in:
Michael Mikovsky
2026-01-30 14:05:07 -07:00
parent b2fe85a698
commit 82d8e1ba10
21 changed files with 217 additions and 278 deletions
+4 -1
View File
@@ -1,6 +1,9 @@
[package]
name = "unshell-server"
edition = "2024"
version.workspace = true
edition.workspace = true
authors.workspace = true
include.workspace = true
[features]
default = ["log_debug"]
-14
View File
@@ -1,14 +0,0 @@
use std::collections::HashMap;
use unshell::config::ConfigStructField;
// use crate::config::ConfigStructField;
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct Blob {
name: String,
parent_component: String,
// parent_runtime: String,
config: HashMap<String, ConfigStructField>,
}
-49
View File
@@ -1,49 +0,0 @@
use std::collections::HashMap;
use serde_json::Value;
use crate::config::ConfigStructField;
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub enum Interface {
Sub(HashMap<String, InterfaceWrapper>),
Struct {
fields: HashMap<String, ConfigStructField>,
value: HashMap<String, Value>,
},
}
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct InterfaceWrapper {
pub name: String,
pub interface: Interface,
}
impl InterfaceWrapper {
pub fn get_path(&self, elements: &Vec<&str>, depth: usize) -> Result<InterfaceWrapper, String> {
if depth == elements.len() {
return Ok(self.clone());
}
let element = elements[depth];
match &self.interface {
Interface::Sub(interface_wrappers) => {
if let Some(interface) = interface_wrappers.get(element) {
interface.get_path(elements, depth)
} else {
Err("Invalid Path".into())
}
}
_ => Err("Invalid Path".into()),
}
}
}
pub fn get_test_interface() -> InterfaceWrapper {
InterfaceWrapper {
name: "Root Interface".into(),
interface: Interface::Sub(HashMap::new()),
}
}
-91
View File
@@ -1,91 +0,0 @@
mod blob;
use std::{
collections::HashMap,
fs,
path::{Path, PathBuf},
};
use unshell::{ModuleError, Result, debug, info};
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
struct ComponentMetadata {
name: String,
description: Option<String>,
version: Option<String>,
authors: Option<Vec<String>>,
// Struct to contain build information
#[serde(default)]
build_config: BuildConfig,
// Other components that can be pointed to by this component
#[serde(default)]
child_components: Vec<PathBuf>,
}
#[derive(Default, Debug, Clone, serde::Deserialize, serde::Serialize)]
struct BuildConfig {
// Cargo feature list of a component
// (Name, Description)
#[serde(default)]
features: HashMap<String, String>,
}
#[derive(Clone, Debug)]
pub struct ComponentState {
metadata: ComponentMetadata,
path: PathBuf,
}
pub fn load_config(path: &PathBuf) -> Result<Vec<ComponentState>> {
let path_absolute =
fs::canonicalize(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?;
debug!("Loading data from path: `{:?}`", path_absolute);
// Read string as path
let config_str =
fs::read_to_string(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?;
// Load config from String
let config = toml::from_str::<ComponentMetadata>(&config_str)
.map_err(|e| ModuleError::Error(e.to_string()))?;
info!("Loaded component `{}`", config.name);
let parent_path = path_absolute.parent().expect("Path must have parent");
if config.child_components.is_empty() {
Ok(vec![ComponentState {
metadata: config,
path: PathBuf::from(parent_path),
}])
} else {
let mut config_vec = vec![];
// Load each child component
for component_path in &config.child_components {
let path = Path::join(parent_path, component_path);
let mut config = load_config(&path)?;
config_vec.append(&mut config);
}
config_vec.insert(
0,
ComponentState {
metadata: config,
path: PathBuf::from(parent_path),
},
);
Ok(config_vec)
}
}
// pub fn parse_toml() -> ComponentMetadata {
// let data = include_str!("../../test.toml");
// let config = toml::from_str(data).unwrap();
// config
// }
+1 -1
View File
@@ -1,6 +1,6 @@
mod api;
mod auth;
mod config;
// mod config;
pub mod logger;
mod server;