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
28 changes: 28 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# clang-tidy for the C++ FFI wrappers (llama-cpp-bindings-sys/*.cpp). Every check
# is enabled and every warning is an error, except:
# - Other-project convention groups this codebase is not and cannot satisfy
# (some of which contradict each other and the modernize checks, e.g.
# fuchsia-trailing-return vs modernize-use-trailing-return-type):
# abseil/altera/android/boost/darwin/fuchsia/linuxkernel/llvm/llvmlibc/mpi/openmp/zircon.
# - bugprone-easily-swappable-parameters: the wrapper signatures mirror the
# llama.cpp C API shape (adjacent llama_pos p0, p1, ...) and cannot be reshaped.
# Headers are out of scope here: they are C-ABI (bindgen parses them as C), so C++
# modernizations would break them. cppcheck lints the headers instead.
Checks: >
*,
-abseil-*,
-altera-*,
-android-*,
-boost-*,
-darwin-*,
-fuchsia-*,
-linuxkernel-*,
-llvm-*,
-llvmlibc-*,
-mpi-*,
-openmp-*,
-zircon-*,
-bugprone-easily-swappable-parameters
WarningsAsErrors: '*'
HeaderFilterRegex: '$^'
FormatStyle: none
26 changes: 26 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,29 @@ jobs:
- uses: ./.github/actions/install-rust-toolchain

- run: make test.unit

cppcheck:
name: cppcheck
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- run: sudo apt-get update && sudo apt-get install -y cppcheck

- run: make lint.cpp.cppcheck

clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- run: sudo apt-get update && sudo apt-get install -y clang-tidy

- run: make lint.cpp.clang-tidy
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "llama-cpp-bindings-sys/llama.cpp"]
path = llama-cpp-bindings-sys/llama.cpp
url = https://github.com/ggml-org/llama.cpp
[submodule "llama-cpp-bindings-sys/GSL"]
path = llama-cpp-bindings-sys/GSL
url = https://github.com/microsoft/GSL.git
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ fmt:
fmt.check:
cargo fmt --all --check

.PHONY: lint.cpp
lint.cpp: lint.cpp.clang-tidy lint.cpp.cppcheck

.PHONY: lint.cpp.clang-tidy
lint.cpp.clang-tidy:
cd llama-cpp-bindings-sys && clang-tidy wrapper_*.cpp -- \
-std=c++17 -I. -IGSL/include -Illama.cpp -Illama.cpp/common \
-Illama.cpp/include -Illama.cpp/ggml/include -Illama.cpp/vendor

.PHONY: lint.cpp.cppcheck
lint.cpp.cppcheck:
cd llama-cpp-bindings-sys && cppcheck --enable=all --inconclusive \
--check-level=exhaustive --std=c++17 --error-exitcode=1 \
-I. -IGSL/include -Illama.cpp -Illama.cpp/common -Illama.cpp/include \
-Illama.cpp/ggml/include -Illama.cpp/vendor \
--suppress='*:llama.cpp/*' --suppress='*:GSL/*' \
--suppress=missingIncludeSystem --suppress=unusedFunction \
--suppress=checkersReport --suppress=toomanyconfigs wrapper_*.cpp

.PHONY: test
test: test.unit test.llms

Expand Down
13 changes: 3 additions & 10 deletions llama-cpp-bindings-build/src/cmake_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn configure_base_defines(config: &mut Config) {
config.define("LLAMA_BUILD_EXAMPLES", "OFF");
config.define("LLAMA_BUILD_SERVER", "OFF");
config.define("LLAMA_BUILD_TOOLS", "OFF");
config.define("LLAMA_BUILD_APP", "OFF");
config.define("LLAMA_BUILD_COMMON", "ON");
config.define("LLAMA_CURL", "OFF");
config.cflag("-w");
Expand Down Expand Up @@ -231,16 +232,8 @@ fn configure_msvc_release_workaround(config: &mut Config, profile: &str) {
}

fn configure_android_cmake(config: &mut Config, ndk: &AndroidNdk, _target_triple: &str) {
#[expect(
clippy::assertions_on_constants,
reason = "the assertion enforces a feature flag invariant at build time"
)]
{
assert!(
!(cfg!(feature = "shared-stdcxx") && cfg!(feature = "static-stdcxx")),
"Features 'shared-stdcxx' and 'static-stdcxx' are mutually exclusive"
);
}
#[cfg(all(feature = "shared-stdcxx", feature = "static-stdcxx"))]
compile_error!("Features 'shared-stdcxx' and 'static-stdcxx' are mutually exclusive");

println!("cargo:rerun-if-env-changed=ANDROID_NDK");
println!("cargo:rerun-if-env-changed=NDK_ROOT");
Expand Down
3 changes: 2 additions & 1 deletion llama-cpp-bindings-build/src/cpp_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use crate::glob_paths;
use crate::target_os::TargetOs;

const WRAPPER_SOURCE_PATTERNS: &[&str] = &["wrapper_*.cpp", "marker_probes/**/*.cpp"];
const WRAPPER_SOURCE_PATTERNS: &[&str] = &["wrapper_*.cpp"];

pub fn compile_cpp_wrappers(llama_src: &Path, target_os: &TargetOs) {
let mut build = cc::Build::new();
Expand All @@ -12,6 +12,7 @@ pub fn compile_cpp_wrappers(llama_src: &Path, target_os: &TargetOs) {
.cpp(true)
.warnings(false)
.include(".")
.include("GSL/include")
.include(llama_src)
.include(llama_src.join("common"))
.include(llama_src.join("include"))
Expand Down
7 changes: 1 addition & 6 deletions llama-cpp-bindings-build/src/rebuild_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ use walkdir::DirEntry;

use crate::glob_paths;

const WRAPPER_TRACKING_PATTERNS: &[&str] = &[
"wrapper*.h",
"wrapper_*.cpp",
"marker_probes/**/*.h",
"marker_probes/**/*.cpp",
];
const WRAPPER_TRACKING_PATTERNS: &[&str] = &["wrapper*.h", "wrapper_*.cpp"];

fn is_hidden(entry: &DirEntry) -> bool {
entry
Expand Down
1 change: 1 addition & 0 deletions llama-cpp-bindings-sys/GSL
Submodule GSL added at 152d6e
2 changes: 1 addition & 1 deletion llama-cpp-bindings-sys/llama.cpp
Submodule llama.cpp updated 825 files
144 changes: 0 additions & 144 deletions llama-cpp-bindings-sys/marker_probes/chunked_thinking.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions llama-cpp-bindings-sys/marker_probes/chunked_thinking.h

This file was deleted.

20 changes: 0 additions & 20 deletions llama-cpp-bindings-sys/marker_probes/marker_probe.h

This file was deleted.

16 changes: 0 additions & 16 deletions llama-cpp-bindings-sys/marker_probes/registry.cpp

This file was deleted.

Loading
Loading