From f2ecd8633c5a429be1b38bef4a8737a594d1a359 Mon Sep 17 00:00:00 2001 From: Adonis Carvajal Date: Sat, 5 Jul 2025 22:35:25 -0400 Subject: [PATCH 1/3] Updated to v1.0 of waycap --- .github/workflows/clippy.yml | 268 ++++++++++++++++++++++++----------- Cargo.lock | 4 +- Cargo.toml | 2 +- src/main.rs | 2 +- src/waycap.rs | 14 +- 5 files changed, 189 insertions(+), 101 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index aecf631..12ac25d 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -2,57 +2,143 @@ name: Clippy & Test Check on: pull_request: - branches: - - main + branches: [main] workflow_dispatch: +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + CUDA_VERSION: '12.5.0' + jobs: - setup: - name: Shared Setup (Caching) + setup-cuda: + name: Setup CUDA Toolkit runs-on: ubuntu-latest + timeout-minutes: 20 outputs: - cache-hit: ${{ steps.cache.outputs.cache-hit }} + cuda-cache-hit: ${{ steps.cuda-cache.outputs.cache-hit }} steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Cache cargo registry and target dir - id: cache - uses: actions/cache@v3 + - name: Cache CUDA installation + id: cuda-cache + uses: actions/cache@v4 with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + path: /usr/local/cuda-* + key: cuda-${{ env.CUDA_VERSION }}-${{ runner.os }}-${{ runner.arch }} restore-keys: | - ${{ runner.os }}-cargo- + cuda-${{ env.CUDA_VERSION }}-${{ runner.os }}- - clippy: - name: Run Clippy + - name: Install CUDA Toolkit + if: steps.cuda-cache.outputs.cache-hit != 'true' + id: install_cuda + uses: Jimver/cuda-toolkit@v0.2.24 + with: + cuda: ${{ env.CUDA_VERSION }} + method: 'local' + use-github-cache: false + + - name: Archive CUDA installation with progress + run: | + CUDA_VER_SHORT=$(echo "${CUDA_VERSION}" | cut -d '.' -f1,2) + CUDA_DIR="/usr/local/cuda-${CUDA_VER_SHORT}" + echo "Archiving CUDA from $CUDA_DIR" + + # Check if directory exists + if [ ! -d "$CUDA_DIR" ]; then + echo "CUDA directory not found at $CUDA_DIR" + ls -la /usr/local/cuda* + exit 1 + fi + + # Create tarball with progress and better compression + sudo tar -C /usr/local -czf /tmp/cuda.tar.gz "cuda-${CUDA_VER_SHORT}" \ + --checkpoint=1000 \ + --checkpoint-action=echo='Archived %u records' \ + --exclude='*.a' \ + --exclude='doc' \ + --exclude='samples' + + # Show tarball size + ls -lh /tmp/cuda.tar.gz + env: + CUDA_VERSION: ${{ env.CUDA_VERSION }} + + - name: Upload CUDA artifact + uses: actions/upload-artifact@v4 + with: + name: cuda-toolkit-${{ env.CUDA_VERSION }} + path: /tmp/cuda.tar.gz + retention-days: 7 + compression-level: 0 # Already compressed + + fmt: + name: Code Formatting runs-on: ubuntu-latest - needs: setup + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - run: cargo fmt --all -- --check + + clippy: + name: Clippy Linting + runs-on: ubuntu-latest + needs: [setup-cuda, fmt] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Cache cargo dependencies + uses: actions/cache@v4 with: path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }} restore-keys: | + ${{ runner.os }}-cargo-clippy- ${{ runner.os }}-cargo- - - name: Install Rust - uses: actions-rs/toolchain@v1 + - name: Download CUDA artifact + uses: actions/download-artifact@v4 with: - toolchain: stable - components: clippy - profile: minimal - override: true + name: cuda-toolkit-${{ env.CUDA_VERSION }} + path: /tmp + + - name: Extract CUDA with progress + run: | + echo "Extracting CUDA toolkit..." + sudo tar -xzf /tmp/cuda.tar.gz -C /usr/local \ + --checkpoint=1000 \ + --checkpoint-action=echo='Extracted %u records' + + # Verify extraction + CUDA_VER_SHORT=$(echo "${CUDA_VERSION}" | cut -d '.' -f1,2) + ls -la /usr/local/cuda-${CUDA_VER_SHORT}/bin/nvcc + env: + CUDA_VERSION: ${{ env.CUDA_VERSION }} + + - name: Setup CUDA environment variables + run: | + CUDA_VER_SHORT=$(echo "${CUDA_VERSION}" | cut -d '.' -f1,2) + CUDA_HOME="/usr/local/cuda-${CUDA_VER_SHORT}" + + echo "CUDA_HOME=${CUDA_HOME}" >> $GITHUB_ENV + echo "PATH=${CUDA_HOME}/bin:$PATH" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH" >> $GITHUB_ENV + + # Also add to current session for verification + export PATH="${CUDA_HOME}/bin:$PATH" + export LD_LIBRARY_PATH="${CUDA_HOME}/lib64:$LD_LIBRARY_PATH" + env: + CUDA_VERSION: ${{ env.CUDA_VERSION }} - name: Install system dependencies run: | @@ -66,35 +152,74 @@ jobs: libswscale-dev \ libavdevice-dev \ libavfilter-dev \ + libwayland-dev \ + libwayland-client0 \ + wayland-protocols \ pkg-config - - name: Run cargo clippy - run: cargo clippy --all-targets --all-features -- -D warnings + - name: Verify CUDA installation + run: | + nvcc --version + echo "CUDA_HOME: $CUDA_HOME" + echo "PATH: $PATH" + + - run: cargo clippy --all-targets --all-features -- -D warnings test: - name: Run Tests + name: Unit Tests runs-on: ubuntu-latest - needs: setup - + needs: [setup-cuda, fmt] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable - - uses: actions/cache@v3 + - name: Cache cargo dependencies + uses: actions/cache@v4 with: path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} restore-keys: | + ${{ runner.os }}-cargo-test- ${{ runner.os }}-cargo- - - name: Install Rust - uses: actions-rs/toolchain@v1 + - name: Download CUDA artifact + uses: actions/download-artifact@v4 with: - toolchain: stable - profile: minimal - override: true + name: cuda-toolkit-${{ env.CUDA_VERSION }} + path: /tmp + + - name: Extract CUDA with progress + run: | + echo "Extracting CUDA toolkit..." + sudo tar -xzf /tmp/cuda.tar.gz -C /usr/local \ + --checkpoint=1000 \ + --checkpoint-action=echo='Extracted %u records' + + # Verify extraction + CUDA_VER_SHORT=$(echo "${CUDA_VERSION}" | cut -d '.' -f1,2) + ls -la /usr/local/cuda-${CUDA_VER_SHORT}/bin/nvcc + env: + CUDA_VERSION: ${{ env.CUDA_VERSION }} + + - name: Setup CUDA environment variables + run: | + CUDA_VER_SHORT=$(echo "${CUDA_VERSION}" | cut -d '.' -f1,2) + CUDA_HOME="/usr/local/cuda-${CUDA_VER_SHORT}" + + echo "CUDA_HOME=${CUDA_HOME}" >> $GITHUB_ENV + echo "PATH=${CUDA_HOME}/bin:$PATH" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH" >> $GITHUB_ENV + + # Also add to current session for verification + export PATH="${CUDA_HOME}/bin:$PATH" + export LD_LIBRARY_PATH="${CUDA_HOME}/lib64:$LD_LIBRARY_PATH" + env: + CUDA_VERSION: ${{ env.CUDA_VERSION }} - name: Install system dependencies run: | @@ -108,44 +233,15 @@ jobs: libswscale-dev \ libavdevice-dev \ libavfilter-dev \ + libwayland-dev \ + libwayland-client0 \ + wayland-protocols \ pkg-config - - name: Run tests - run: cargo test - - rust-fmt: - name: Run rustfmt - runs-on: ubuntu-latest - needs: setup - - steps: - - uses: actions/checkout@v3 - - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - - name: Install rustfmt - run: rustup component add rustfmt - - - name: Run rustfmt - run: cargo fmt -- --check - - - name: Fail if rustfmt is not correct - if: failure() + - name: Verify CUDA installation run: | - echo "Code is not formatted. Please run 'cargo fmt' and commit the changes." - exit 1 + nvcc --version + echo "CUDA_HOME: $CUDA_HOME" + echo "PATH: $PATH" + + - run: cargo test diff --git a/Cargo.lock b/Cargo.lock index b9b5888..6518263 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2969,9 +2969,9 @@ dependencies = [ [[package]] name = "waycap-rs" -version = "0.3.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cbbc6aee0533ba332c42e317201f6acc4575e4d58063a33c51f0b5d641bc59f" +checksum = "0c5b54a664ce6e5b5ca430f8811eada98b456d288ac1f9f7ef2d719c3e4c89b0" dependencies = [ "bytemuck", "crossbeam", diff --git a/Cargo.toml b/Cargo.toml index 26720fe..ddd9ee1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ simple-logging = "2.0.2" tokio = { version = "1.43.0", features = ["full", "rt-multi-thread"] } toml = "0.8.20" zbus = { version = "5.3.1", features = ["tokio"] } -waycap-rs = "0.3.0" +waycap-rs = "1.0.0" crossbeam = "0.8.4" [profile.dev] diff --git a/src/main.rs b/src/main.rs index 8053d0c..f406042 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<(), Error> { pw::init(); ffmpeg::init()?; let config = load_or_create_config(); - log::debug!("Config: {:?}", config); + log::debug!("Config: {config:?}"); let mode = ShadowCapMode::new(config.max_seconds).await?; let mut app = WayCap::new(mode, config).await?; diff --git a/src/waycap.rs b/src/waycap.rs index 0cda5ef..f2e5af0 100644 --- a/src/waycap.rs +++ b/src/waycap.rs @@ -19,7 +19,7 @@ pub struct WayCap { } impl WayCap { - pub async fn new(mut mode: M, config: AppConfig) -> Result { + pub async fn new(mut mode: M, _config: AppConfig) -> Result { simple_logging::log_to_file("logs.txt", log::LevelFilter::Info)?; let saving = Arc::new(AtomicBool::new(false)); let stop = Arc::new(AtomicBool::new(false)); @@ -41,14 +41,6 @@ impl WayCap { .with_audio() .with_quality_preset(waycap_rs::types::config::QualityPreset::Medium) .with_cursor_shown() - .with_video_encoder(match config.encoder { - crate::application_config::EncoderToUse::H264Nvenc => { - waycap_rs::types::config::VideoEncoder::H264Nvenc - } - crate::application_config::EncoderToUse::H264Vaapi => { - waycap_rs::types::config::VideoEncoder::H264Vaapi - } - }) .with_audio_encoder(waycap_rs::types::config::AudioEncoder::Opus) .build()?; @@ -91,13 +83,13 @@ impl WayCap { if let Some(conn) = self.dbus_conn.take() { if let Err(e) = conn.close().await { - log::error!("Error closing dbus connection: {:?}", e); + log::error!("Error closing dbus connection: {e:?}"); } } for handle in self.context.join_handles.drain(..) { if let Err(e) = handle.join() { - log::error!("Error shutting down a worker handle: {:?}", e); + log::error!("Error shutting down a worker handle: {e:?}"); } } From 66449a7a5647eae3226f6408df8d9f1fd105b413 Mon Sep 17 00:00:00 2001 From: Adonis Carvajal Date: Sun, 6 Jul 2025 00:26:04 -0400 Subject: [PATCH 2/3] rebase --- .github/workflows/clippy.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 12ac25d..5b6e873 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -50,12 +50,13 @@ jobs: fi # Create tarball with progress and better compression - sudo tar -C /usr/local -czf /tmp/cuda.tar.gz "cuda-${CUDA_VER_SHORT}" \ - --checkpoint=1000 \ - --checkpoint-action=echo='Archived %u records' \ + sudo tar -C /usr/local \ --exclude='*.a' \ --exclude='doc' \ - --exclude='samples' + --exclude='samples' \ + --checkpoint=1000 \ + --checkpoint-action=echo='Archived %u records' \ + -czf /tmp/cuda.tar.gz "cuda-${CUDA_VER_SHORT}" # Show tarball size ls -lh /tmp/cuda.tar.gz From 7dab0d5609a802d0f6ec9b1632873524b221c3eb Mon Sep 17 00:00:00 2001 From: Adonis Carvajal Date: Sun, 6 Jul 2025 00:41:58 -0400 Subject: [PATCH 3/3] Clean up github action --- .github/workflows/clippy.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 5b6e873..f5f28f2 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -42,14 +42,12 @@ jobs: CUDA_DIR="/usr/local/cuda-${CUDA_VER_SHORT}" echo "Archiving CUDA from $CUDA_DIR" - # Check if directory exists if [ ! -d "$CUDA_DIR" ]; then echo "CUDA directory not found at $CUDA_DIR" ls -la /usr/local/cuda* exit 1 fi - # Create tarball with progress and better compression sudo tar -C /usr/local \ --exclude='*.a' \ --exclude='doc' \ @@ -69,7 +67,7 @@ jobs: name: cuda-toolkit-${{ env.CUDA_VERSION }} path: /tmp/cuda.tar.gz retention-days: 7 - compression-level: 0 # Already compressed + compression-level: 0 fmt: name: Code Formatting @@ -86,7 +84,7 @@ jobs: clippy: name: Clippy Linting runs-on: ubuntu-latest - needs: [setup-cuda, fmt] + needs: [setup-cuda] steps: - uses: actions/checkout@v4 @@ -145,6 +143,8 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ + nvidia-driver-535 \ + libnvidia-compute-535 \ libdbus-1-dev \ libpipewire-0.3-dev \ libavutil-dev \ @@ -161,15 +161,13 @@ jobs: - name: Verify CUDA installation run: | nvcc --version - echo "CUDA_HOME: $CUDA_HOME" - echo "PATH: $PATH" - run: cargo clippy --all-targets --all-features -- -D warnings test: name: Unit Tests runs-on: ubuntu-latest - needs: [setup-cuda, fmt] + needs: [setup-cuda] steps: - uses: actions/checkout@v4 @@ -226,6 +224,8 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ + nvidia-driver-535 \ + libnvidia-compute-535 \ libdbus-1-dev \ libpipewire-0.3-dev \ libavutil-dev \ @@ -242,7 +242,5 @@ jobs: - name: Verify CUDA installation run: | nvcc --version - echo "CUDA_HOME: $CUDA_HOME" - echo "PATH: $PATH" - run: cargo test