Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 181 additions & 86 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
14 changes: 3 additions & 11 deletions src/waycap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct WayCap<M: AppMode> {
}

impl<M: AppMode> WayCap<M> {
pub async fn new(mut mode: M, config: AppConfig) -> Result<Self> {
pub async fn new(mut mode: M, _config: AppConfig) -> Result<Self> {
simple_logging::log_to_file("logs.txt", log::LevelFilter::Info)?;
let saving = Arc::new(AtomicBool::new(false));
let stop = Arc::new(AtomicBool::new(false));
Expand All @@ -41,14 +41,6 @@ impl<M: AppMode> WayCap<M> {
.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()?;

Expand Down Expand Up @@ -91,13 +83,13 @@ impl<M: AppMode> WayCap<M> {

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:?}");
}
}

Expand Down
Loading