From c1621e5fb7909f2fa8a83af329b0e4d2f27888df Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Wed, 1 Apr 2026 00:13:47 +0200 Subject: [PATCH 1/3] Enable all non-hardware features in CI and fix clippy warnings --- .github/workflows/ci.yml | 6 +++--- Makefile | 11 ++++++----- llama-cpp-bindings/src/llguidance_sampler.rs | 6 +++++- llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs | 1 + llama-cpp-bindings/src/mtmd/mtmd_context.rs | 4 ++-- llama-cpp-bindings/src/mtmd/mtmd_error.rs | 2 +- llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs | 4 ++-- llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs | 6 +++--- llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs | 4 ++-- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60a30c62..c0db0a71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: toolchain: "1.92.0" components: rustfmt - - run: cargo fmt --all -- --check + - run: make fmt clippy: name: Clippy @@ -41,7 +41,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --workspace -- -D warnings + - run: make clippy test: name: Tests @@ -60,4 +60,4 @@ jobs: - uses: Swatinem/rust-cache@v2 - - run: cargo test --workspace + - run: make test.unit diff --git a/Makefile b/Makefile index 378b6535..d4e9ac9f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ -CARGO_TEST_LLM_FLAGS = --lib -p llama-cpp-bindings --features tests_that_use_llms,mtmd -- --test-threads=1 -CARGO_COV_LLM_FLAGS = --lib --features tests_that_use_llms,mtmd -p llama-cpp-bindings +FEATURES = mtmd,sampler,llguidance +CARGO_TEST_LLM_FLAGS = --lib -p llama-cpp-bindings --features tests_that_use_llms,$(FEATURES) -- --test-threads=1 +CARGO_COV_LLM_FLAGS = --lib --features tests_that_use_llms,$(FEATURES) -p llama-cpp-bindings QWEN3_5_0_8B_ENV = \ LLAMA_TEST_HF_REPO=unsloth/Qwen3.5-0.8B-GGUF \ @@ -12,7 +13,7 @@ QWEN3_5_0_8B_ENV = \ .PHONY: test.unit test.unit: clippy - cargo test --lib -p llama-cpp-bindings + cargo test --lib -p llama-cpp-bindings --features $(FEATURES) .PHONY: test.qwen3.5_0.8B test.qwen3.5_0.8B: clippy @@ -42,8 +43,8 @@ test: test.unit test.llms .PHONY: fmt fmt: - cargo fmt --check + cargo fmt --all --check .PHONY: clippy clippy: - cargo clippy --all-targets -p llama-cpp-bindings + cargo clippy --all-targets -p llama-cpp-bindings --features $(FEATURES) -- -D warnings diff --git a/llama-cpp-bindings/src/llguidance_sampler.rs b/llama-cpp-bindings/src/llguidance_sampler.rs index a6a45e8f..0db8dd16 100644 --- a/llama-cpp-bindings/src/llguidance_sampler.rs +++ b/llama-cpp-bindings/src/llguidance_sampler.rs @@ -69,7 +69,7 @@ fn build_tok_env(model: &LlamaModel) -> Arc { // --- extern "C" vtable callbacks --- -unsafe extern "C" fn llg_name( +const unsafe extern "C" fn llg_name( _smpl: *const llama_cpp_bindings_sys::llama_sampler, ) -> *const std::os::raw::c_char { c"llguidance".as_ptr() @@ -168,6 +168,10 @@ static mut LLG_SAMPLER_I: llama_cpp_bindings_sys::llama_sampler_i = }; /// Create an llguidance-based constrained decoding sampler. +/// +/// # Errors +/// +/// Returns `GrammarError` if the parser factory, grammar, or parser cannot be created. pub fn create_llg_sampler( model: &LlamaModel, grammar_kind: &str, diff --git a/llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs b/llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs index e59992f3..3d2b0bd4 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs @@ -283,6 +283,7 @@ mod tests { #[test] fn from_audio_data_creates_valid_bitmap() { + #[allow(clippy::cast_precision_loss)] let audio_samples: Vec = (0..100).map(|index| (index as f32 * 0.1).sin()).collect(); let bitmap = MtmdBitmap::from_audio_data(&audio_samples).unwrap(); diff --git a/llama-cpp-bindings/src/mtmd/mtmd_context.rs b/llama-cpp-bindings/src/mtmd/mtmd_context.rs index 9379c9c3..5a2e3f44 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_context.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_context.rs @@ -10,7 +10,7 @@ use super::mtmd_input_chunk::MtmdInputChunk; use super::mtmd_input_chunks::MtmdInputChunks; use super::mtmd_input_text::MtmdInputText; -fn tokenize_result_to_error(result: i32) -> MtmdTokenizeError { +const fn tokenize_result_to_error(result: i32) -> MtmdTokenizeError { match result { 1 => MtmdTokenizeError::BitmapCountMismatch, 2 => MtmdTokenizeError::ImagePreprocessingError, @@ -18,7 +18,7 @@ fn tokenize_result_to_error(result: i32) -> MtmdTokenizeError { } } -fn check_encode_result(result: i32) -> Result<(), MtmdEncodeError> { +const fn check_encode_result(result: i32) -> Result<(), MtmdEncodeError> { if result == 0 { Ok(()) } else { diff --git a/llama-cpp-bindings/src/mtmd/mtmd_error.rs b/llama-cpp-bindings/src/mtmd/mtmd_error.rs index 4e91a907..9515fd06 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_error.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_error.rs @@ -73,7 +73,7 @@ pub enum MtmdEvalError { /// Requested batch size exceeds the context's maximum batch size #[error("batch size {requested} exceeds context batch size {context_max}")] BatchSizeExceedsContextLimit { - /// The batch size requested in eval_chunks + /// The batch size requested in `eval_chunks` requested: i32, /// The maximum batch size configured on the context context_max: u32, diff --git a/llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs b/llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs index 9ca40514..e300dccd 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs @@ -11,7 +11,7 @@ use super::mtmd_input_chunk_type::{MtmdInputChunkType, MtmdInputChunkTypeError}; /// /// `tokens_ptr` must point to at least `n_tokens` valid `llama_token` values /// that remain valid for the lifetime `'chunk`. -unsafe fn tokens_from_raw_ptr<'chunk>( +const unsafe fn tokens_from_raw_ptr<'chunk>( tokens_ptr: *const llama_cpp_bindings_sys::llama_token, n_tokens: usize, ) -> Option<&'chunk [LlamaToken]> { @@ -131,7 +131,7 @@ mod unit_tests { #[test] fn tokens_from_raw_ptr_returns_none_for_zero_count() { let token: llama_cpp_bindings_sys::llama_token = 42; - assert!(unsafe { tokens_from_raw_ptr(&token, 0) }.is_none()); + assert!(unsafe { tokens_from_raw_ptr(&raw const token, 0) }.is_none()); } #[test] diff --git a/llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs b/llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs index e9908e20..a779363a 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_input_chunk_type.rs @@ -37,9 +37,9 @@ impl TryFrom for MtmdInputChunkTy chunk_type: llama_cpp_bindings_sys::mtmd_input_chunk_type, ) -> Result { match chunk_type { - llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_TEXT => Ok(MtmdInputChunkType::Text), - llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_IMAGE => Ok(MtmdInputChunkType::Image), - llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_AUDIO => Ok(MtmdInputChunkType::Audio), + llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_TEXT => Ok(Self::Text), + llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_IMAGE => Ok(Self::Image), + llama_cpp_bindings_sys::MTMD_INPUT_CHUNK_TYPE_AUDIO => Ok(Self::Audio), unknown => Err(MtmdInputChunkTypeError(unknown)), } } diff --git a/llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs b/llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs index 251448b8..0b8aacd1 100644 --- a/llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs +++ b/llama-cpp-bindings/src/mtmd/mtmd_input_chunks.rs @@ -6,7 +6,7 @@ use super::mtmd_context::MtmdContext; use super::mtmd_error::MtmdEvalError; use super::mtmd_input_chunk::MtmdInputChunk; -fn check_eval_result(result: i32) -> Result<(), MtmdEvalError> { +const fn check_eval_result(result: i32) -> Result<(), MtmdEvalError> { if result == 0 { Ok(()) } else { @@ -109,7 +109,7 @@ impl MtmdInputChunks { ) -> Result { let context_max_batch = llama_ctx.n_batch(); - if n_batch > 0 && (n_batch as u32) > context_max_batch { + if n_batch > 0 && n_batch.cast_unsigned() > context_max_batch { return Err(MtmdEvalError::BatchSizeExceedsContextLimit { requested: n_batch, context_max: context_max_batch, From 49babbbb09f4f08d62f5a0541a431ddc46a0375b Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Wed, 1 Apr 2026 00:17:22 +0200 Subject: [PATCH 2/3] Add clippy and rustfmt components to rust-toolchain.toml --- rust-toolchain.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f19782d3..711b3a48 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "1.92.0" +components = ["clippy", "rustfmt"] From 15834fe7f63b2d8b6a9d12582b7cccb51abda5fa Mon Sep 17 00:00:00 2001 From: Mateusz Charytoniuk Date: Wed, 1 Apr 2026 00:18:52 +0200 Subject: [PATCH 3/3] Remove separate clippy CI job, test.unit already runs it --- .github/workflows/ci.yml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0db0a71..8e1ebf03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,26 +23,6 @@ jobs: - run: make fmt - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Install system dependencies - run: sudo apt-get update && sudo apt-get install -y cmake libclang-dev - - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: "1.92.0" - components: clippy - - - uses: Swatinem/rust-cache@v2 - - - run: make clippy - test: name: Tests runs-on: ubuntu-latest