From 96329923f62c744419fe3f30521a3997932fd714 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Mon, 2 Dec 2024 17:01:21 -0500 Subject: [PATCH] move client and test minifb client code to seperate crates --- .gitignore | 3 +- README.md | 7 ++- build.rs | 18 ------- client/Cargo.lock | 69 +++++++++++++++++++++++++ Cargo.toml => client/Cargo.toml | 4 +- client/build.rs | 18 +++++++ src/hzclient.rs => client/src/client.rs | 0 client/src/lib.rs | 2 + {src => client/src}/rust_wrapper.cpp | 0 Cargo.lock => testclient/Cargo.lock | 28 ++++++---- testclient/Cargo.toml | 9 ++++ {src => testclient/src}/main.rs | 12 ++--- 12 files changed, 131 insertions(+), 39 deletions(-) delete mode 100644 build.rs create mode 100644 client/Cargo.lock rename Cargo.toml => client/Cargo.toml (62%) create mode 100644 client/build.rs rename src/hzclient.rs => client/src/client.rs (100%) create mode 100644 client/src/lib.rs rename {src => client/src}/rust_wrapper.cpp (100%) rename Cargo.lock => testclient/Cargo.lock (99%) create mode 100644 testclient/Cargo.toml rename {src => testclient/src}/main.rs (86%) diff --git a/.gitignore b/.gitignore index b0f943f..d630c66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/target +/client/target +/testclient/target # agent /agent/.cache diff --git a/README.md b/README.md index 74d86d4..eca83bb 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,13 @@ Currently NVIDIA-specific (since we use NvFBC); support for DXGI duplication (fo The agent runs on Windows 7 x64 onwards. Lower (or x86) is currently not supported as a target. -The agent uses IVSHMEM to provide frames to the client in a low-latency fashion. Later on virtio-serial may be considered for low-bandwidth additional functionality, like input. For now, however, the agent is display only. +The agent uses IVSHMEM to provide frames to the client in a low-latency fashion. + +Later on virtio-serial may be considered for low-bandwidth additional functionality, like input. For now, however, the agent is display only. This repository contains: - The agent. Written in C++20. - Shared headers and utility code, used between the agent and the client. Written in C++20, mostly so it can be shared between the agent and client. -- A simple client, written mostly in Rust (with some C++ glue since I don't feel like rewriting structures and the shared code in Rust), which displays the framebuffer (in a quick-and-dirty fashion.). Mostly test-only code. Some of it isn't though, and will be turned into a standalone client crate. +- A Rust crate for Hazelnut clients to use. Wraps the Shared code. +- A test client written in Rust which displays the framebuffer (in a quick-and-dirty fashion.). \ No newline at end of file diff --git a/build.rs b/build.rs deleted file mode 100644 index bda2fd2..0000000 --- a/build.rs +++ /dev/null @@ -1,18 +0,0 @@ -use cc; - -fn main() { - let mut build = cc::Build::new(); - - // HACK: cc sucks - println!("cargo:rerun-if-changed=src"); - println!("cargo:rerun-if-changed=shared/src"); - - build - .emit_rerun_if_env_changed(true) - .cpp(true) - .std("c++20") - .include("shared/src") - .file("shared/src/ivshmem.cpp") - .file("src/rust_wrapper.cpp") - .compile("rust_ivshmem_bare"); -} \ No newline at end of file diff --git a/client/Cargo.lock b/client/Cargo.lock new file mode 100644 index 0000000..6d34fe6 --- /dev/null +++ b/client/Cargo.lock @@ -0,0 +1,69 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cc" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "hazelnut_client" +version = "0.1.0" +dependencies = [ + "anyhow", + "cc", + "nix", +] + +[[package]] +name = "libc" +version = "0.2.167" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" diff --git a/Cargo.toml b/client/Cargo.toml similarity index 62% rename from Cargo.toml rename to client/Cargo.toml index a0e1f19..e7d5e03 100644 --- a/Cargo.toml +++ b/client/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "fbcserver" +name = "hazelnut_client" +description = "Low-level client for the Hazelnut IVSHMEM display protocol" version = "0.1.0" edition = "2021" [dependencies] anyhow = "1.0.93" -minifb = "0.27.0" nix = { version = "0.29.0", features = [ "fs" ] } [build-dependencies] diff --git a/client/build.rs b/client/build.rs new file mode 100644 index 0000000..90bb452 --- /dev/null +++ b/client/build.rs @@ -0,0 +1,18 @@ +use cc; + +fn main() { + let mut build = cc::Build::new(); + + // HACK: cc sucks + println!("cargo:rerun-if-changed=src/rust_wrapper.cpp"); + println!("cargo:rerun-if-changed=../shared/src"); + + build + .emit_rerun_if_env_changed(true) + .cpp(true) + .std("c++20") + .include("../shared/src") + .file("../shared/src/ivshmem.cpp") + .file("src/rust_wrapper.cpp") + .compile("hazelnut_client_cpp_native"); +} diff --git a/src/hzclient.rs b/client/src/client.rs similarity index 100% rename from src/hzclient.rs rename to client/src/client.rs diff --git a/client/src/lib.rs b/client/src/lib.rs new file mode 100644 index 0000000..9d088f5 --- /dev/null +++ b/client/src/lib.rs @@ -0,0 +1,2 @@ +pub mod client; +pub use client::*; \ No newline at end of file diff --git a/src/rust_wrapper.cpp b/client/src/rust_wrapper.cpp similarity index 100% rename from src/rust_wrapper.cpp rename to client/src/rust_wrapper.cpp diff --git a/Cargo.lock b/testclient/Cargo.lock similarity index 99% rename from Cargo.lock rename to testclient/Cargo.lock index 97ae774..4c87fd9 100644 --- a/Cargo.lock +++ b/testclient/Cargo.lock @@ -84,16 +84,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" -[[package]] -name = "fbcserver" -version = "0.1.0" -dependencies = [ - "anyhow", - "cc", - "minifb", - "nix 0.29.0", -] - [[package]] name = "futures" version = "0.3.31" @@ -183,6 +173,24 @@ dependencies = [ "slab", ] +[[package]] +name = "hazelnut_client" +version = "0.1.0" +dependencies = [ + "anyhow", + "cc", + "nix 0.29.0", +] + +[[package]] +name = "hazelnut_testclient" +version = "0.1.0" +dependencies = [ + "anyhow", + "hazelnut_client", + "minifb", +] + [[package]] name = "instant" version = "0.1.13" diff --git a/testclient/Cargo.toml b/testclient/Cargo.toml new file mode 100644 index 0000000..895dfe0 --- /dev/null +++ b/testclient/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hazelnut_testclient" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.93" +minifb = "0.27.0" +hazelnut_client = { path = "../client" } \ No newline at end of file diff --git a/src/main.rs b/testclient/src/main.rs similarity index 86% rename from src/main.rs rename to testclient/src/main.rs index 2f89764..c70ed24 100644 --- a/src/main.rs +++ b/testclient/src/main.rs @@ -1,13 +1,13 @@ use minifb::{Window, WindowOptions}; -mod hzclient; +use hazelnut_client::*; fn main() -> anyhow::Result<()> { let mut screen_width: u32 = 320; let mut screen_height: u32 = 200; let mut window: Option = None; - let mut client = hzclient::HazelnutClient::new(); + let mut client = HazelnutClient::new(); let socket_path: String = "/dev/shm/lg-win7".into(); @@ -26,8 +26,8 @@ fn main() -> anyhow::Result<()> { } match client.tick_one() { - hzclient::ResultCode::Fail => break, - hzclient::ResultCode::Changed => { + ResultCode::Fail => break, + ResultCode::Changed => { let dims = client.dimensions(); if screen_width != dims.0 && screen_height != dims.1 { @@ -58,11 +58,11 @@ fn main() -> anyhow::Result<()> { client.unlock(); }, - hzclient::sys::ResultCode::LockContended => { + ResultCode::LockContended => { // contended } - hzclient::ResultCode::Unchanged => match window.as_mut() { + ResultCode::Unchanged => match window.as_mut() { Some(window) => { client.unlock();