From 59efb1659a536c4efc6833b42002883b7db7a04f Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Fri, 7 Feb 2025 18:24:48 -0800 Subject: [PATCH] Move denali client to separate lib. --- rust/Cargo.lock | 13 +++++++++++-- rust/Cargo.toml | 1 + rust/lib/client/denali_client/Cargo.toml | 11 +++++++++++ rust/lib/client/denali_client/build.rs | 14 ++++++++++++++ rust/lib/client/denali_client/src/lib.rs | 5 +++++ rust/sys/denali/Cargo.toml | 12 +++--------- rust/sys/victoriafalls/src/bin/victoriafalls.rs | 4 ++++ rust/sys/yellowstone/Cargo.toml | 2 +- rust/sys/yellowstone/src/gpt.rs | 10 +++++----- rust/sys/yellowstone/src/server.rs | 2 +- 10 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 rust/lib/client/denali_client/Cargo.toml create mode 100644 rust/lib/client/denali_client/build.rs create mode 100644 rust/lib/client/denali_client/src/lib.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index e2a667e..c3a5f0e 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "autocfg" @@ -39,6 +39,15 @@ dependencies = [ "yunqc", ] +[[package]] +name = "denali_client" +version = "0.1.0" +dependencies = [ + "mammoth", + "yunq", + "yunqc", +] + [[package]] name = "linked_list_allocator" version = "0.10.5" @@ -174,7 +183,7 @@ dependencies = [ name = "yellowstone" version = "0.1.0" dependencies = [ - "denali", + "denali_client", "mammoth", "victoriafalls", "voyageurs", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0b2a592..0d4b7ca 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ + "lib/client/denali_client", "lib/mammoth", "lib/voyageurs", "lib/yellowstone", diff --git a/rust/lib/client/denali_client/Cargo.toml b/rust/lib/client/denali_client/Cargo.toml new file mode 100644 index 0000000..625a2d5 --- /dev/null +++ b/rust/lib/client/denali_client/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "denali_client" +version = "0.1.0" +edition = "2024" + +[dependencies] +mammoth = { path = "../../mammoth" } +yunq = { path = "../../yunq" } + +[build-dependencies] +yunqc = { path = "../../../../yunq/rust" } diff --git a/rust/lib/client/denali_client/build.rs b/rust/lib/client/denali_client/build.rs new file mode 100644 index 0000000..67e593c --- /dev/null +++ b/rust/lib/client/denali_client/build.rs @@ -0,0 +1,14 @@ +use std::fs; + +fn main() { + let input_file = "../../../../sys/denali/lib/denali/denali.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."); +} diff --git a/rust/lib/client/denali_client/src/lib.rs b/rust/lib/client/denali_client/src/lib.rs new file mode 100644 index 0000000..3cec9d6 --- /dev/null +++ b/rust/lib/client/denali_client/src/lib.rs @@ -0,0 +1,5 @@ +#![no_std] + +use core::include; + +include!(concat!(env!("OUT_DIR"), "/yunq.rs")); diff --git a/rust/sys/denali/Cargo.toml b/rust/sys/denali/Cargo.toml index d618354..dcb3cd0 100644 --- a/rust/sys/denali/Cargo.toml +++ b/rust/sys/denali/Cargo.toml @@ -6,17 +6,11 @@ edition = "2021" [dependencies] bitfield-struct = "0.8.0" mammoth = { path = "../../lib/mammoth" } -yunq = {path = "../../lib/yunq"} - -yellowstone-yunq = { path = "../../lib/yellowstone", optional = true } +yunq = { path = "../../lib/yunq" } +yellowstone-yunq = { path = "../../lib/yellowstone" } [[bin]] name = "denali" -required-features = ["binary"] [build-dependencies] -yunqc = {path = "../../../yunq/rust"} - -[features] -default = ["binary"] -binary = ["dep:yellowstone-yunq"] +yunqc = { path = "../../../yunq/rust" } diff --git a/rust/sys/victoriafalls/src/bin/victoriafalls.rs b/rust/sys/victoriafalls/src/bin/victoriafalls.rs index 7c9c8e8..4d19ddd 100644 --- a/rust/sys/victoriafalls/src/bin/victoriafalls.rs +++ b/rust/sys/victoriafalls/src/bin/victoriafalls.rs @@ -7,5 +7,9 @@ define_entry!(); #[no_mangle] extern "C" fn main() -> z_err_t { + let yellowstone = yellowstone_yunq::from_init_endpoint(); + + let denali = yellowstone.get_denali().unwrap(); + 0 } diff --git a/rust/sys/yellowstone/Cargo.toml b/rust/sys/yellowstone/Cargo.toml index f321b62..6a89d4d 100644 --- a/rust/sys/yellowstone/Cargo.toml +++ b/rust/sys/yellowstone/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] mammoth = { path = "../../lib/mammoth" } -denali = { path = "../denali", default-features = false } +denali_client = { path = "../../lib/client/denali_client" } victoriafalls = { path = "../victoriafalls" } voyageurs = { path = "../../lib/voyageurs" } yellowstone-yunq = { path = "../../lib/yellowstone" } diff --git a/rust/sys/yellowstone/src/gpt.rs b/rust/sys/yellowstone/src/gpt.rs index 950baf9..87bf3ce 100644 --- a/rust/sys/yellowstone/src/gpt.rs +++ b/rust/sys/yellowstone/src/gpt.rs @@ -1,4 +1,4 @@ -use denali::DenaliClient; +use denali_client::DenaliClient; use mammoth::{cap::Capability, zion::ZError}; const MBR_SIG: u16 = 0xAA55; @@ -47,9 +47,9 @@ struct PartitionEntry { } pub fn read_gpt(mut denali: DenaliClient) -> Result { - let resp = denali.read(&denali::ReadRequest { + let resp = denali.read(&denali_client::ReadRequest { device_id: 0, - block: denali::DiskBlock { lba: 0, size: 2 }, + block: denali_client::DiskBlock { lba: 0, size: 2 }, })?; let first_lbas = mammoth::mem::MemoryRegion::from_cap(Capability::take(resp.memory))?; @@ -99,9 +99,9 @@ pub fn read_gpt(mut denali: DenaliClient) -> Result { num_blocks ); - let resp = denali.read(&denali::ReadRequest { + let resp = denali.read(&denali_client::ReadRequest { device_id: 0, - block: denali::DiskBlock { + block: denali_client::DiskBlock { lba: lba_partition_entries, size: num_blocks, }, diff --git a/rust/sys/yellowstone/src/server.rs b/rust/sys/yellowstone/src/server.rs index 8ec36b8..8cc4a4b 100644 --- a/rust/sys/yellowstone/src/server.rs +++ b/rust/sys/yellowstone/src/server.rs @@ -122,7 +122,7 @@ impl YellowstoneServerHandler for YellowstoneServerImpl { fn get_denali(&mut self) -> Result { match self.context.service_map.lock().get("denali") { - Some(ep_cap) => crate::gpt::read_gpt(denali::DenaliClient::new( + Some(ep_cap) => crate::gpt::read_gpt(denali_client::DenaliClient::new( ep_cap.duplicate(Capability::PERMS_ALL).unwrap(), )) .map(|lba| DenaliInfo {