From f9462a1633085920abe90670dbe9447e9d053cab Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Fri, 21 Nov 2025 00:58:44 -0800 Subject: [PATCH] Make GPU support optional to enable RISC-V builds without libdrm - Add 'gpu' feature flag (enabled by default) - Make gfxinfo dependency optional - Provide no-op GPU metrics when gpu feature disabled - Disable GPU support for RISC-V builds in CI (libdrm unavailable) - All other architectures (amd64, arm64, armhf) still get GPU support --- .github/workflows/build-deb.yml | 8 +++++++- socktop_agent/Cargo.toml | 5 +++-- socktop_agent/src/gpu.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index 8f357f4..a6205b7 100644 --- a/.github/workflows/build-deb.yml +++ b/.github/workflows/build-deb.yml @@ -115,10 +115,16 @@ jobs: run: | cargo deb --package socktop --target ${{ matrix.target }} --no-strip - - name: Build socktop_agent .deb package + - name: Build socktop_agent .deb package (with GPU support) + if: matrix.target != 'riscv64gc-unknown-linux-gnu' run: | cargo deb --package socktop_agent --target ${{ matrix.target }} --no-strip + - name: Build socktop_agent .deb package (without GPU support for RISC-V) + if: matrix.target == 'riscv64gc-unknown-linux-gnu' + run: | + cargo deb --package socktop_agent --target ${{ matrix.target }} --no-strip --no-default-features + - name: Copy packages to debs directory run: | mkdir -p debs diff --git a/socktop_agent/Cargo.toml b/socktop_agent/Cargo.toml index 8b78d18..6de4b95 100644 --- a/socktop_agent/Cargo.toml +++ b/socktop_agent/Cargo.toml @@ -23,7 +23,7 @@ flate2 = { version = "1", default-features = false, features = ["rust_backend"] futures-util = "0.3.31" tracing = { version = "0.1", optional = true } tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true } -gfxinfo = "0.1.2" +gfxinfo = { version = "0.1.2", optional = true } once_cell = "1.19" axum-server = { version = "0.7", features = ["tls-rustls"] } rustls = { version = "0.23", features = ["aws-lc-rs"] } @@ -35,7 +35,8 @@ prost = { workspace = true } time = { version = "0.3", default-features = false, features = ["formatting", "macros", "parsing" ] } [features] -default = [] +default = ["gpu"] +gpu = ["gfxinfo"] logging = ["tracing", "tracing-subscriber"] [build-dependencies] diff --git a/socktop_agent/src/gpu.rs b/socktop_agent/src/gpu.rs index 9082dcb..9e0eb08 100644 --- a/socktop_agent/src/gpu.rs +++ b/socktop_agent/src/gpu.rs @@ -1,4 +1,5 @@ // gpu.rs +#[cfg(feature = "gpu")] use gfxinfo::active_gpu; #[derive(Debug, Clone, serde::Serialize)] @@ -9,6 +10,7 @@ pub struct GpuMetrics { pub mem_total_bytes: u64, } +#[cfg(feature = "gpu")] pub fn collect_all_gpus() -> Result, Box> { let gpu = active_gpu()?; // Use ? to unwrap Result let info = gpu.info(); @@ -22,3 +24,9 @@ pub fn collect_all_gpus() -> Result, Box> Ok(vec![metrics]) } + +#[cfg(not(feature = "gpu"))] +pub fn collect_all_gpus() -> Result, Box> { + // GPU support not available on this platform + Ok(vec![]) +}