diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index aecf631..f5f28f2 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -2,62 +2,149 @@ 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" + + if [ ! -d "$CUDA_DIR" ]; then + echo "CUDA directory not found at $CUDA_DIR" + ls -la /usr/local/cuda* + exit 1 + fi + + sudo tar -C /usr/local \ + --exclude='*.a' \ + --exclude='doc' \ + --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 + 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 + + 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] 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: | sudo apt-get update sudo apt-get install -y \ + nvidia-driver-535 \ + libnvidia-compute-535 \ libdbus-1-dev \ libpipewire-0.3-dev \ libavutil-dev \ @@ -66,40 +153,79 @@ 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 + + - 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] 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: | sudo apt-get update sudo apt-get install -y \ + nvidia-driver-535 \ + libnvidia-compute-535 \ libdbus-1-dev \ libpipewire-0.3-dev \ libavutil-dev \ @@ -108,44 +234,13 @@ 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 + + - 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:?}"); } }