Skip to content

Conversation

hongkongkiwi
Copy link

Summary

  • Fixes MTMD build issue identified in PR Include mtmd files for publishing in llama-cpp-sys-2 #806 by implementing dynamic tools CMakeLists.txt generation
  • Only builds MTMD tool when mtmd feature is enabled, avoiding building all 15+ unnecessary tools
  • Creates scalable foundation for other tool features (RPC, server, quantize) to extend cleanly

Key Changes

  • Dynamic CMakeLists.txt generation: generate_tools_cmake() creates tools/CMakeLists.txt at build time based on enabled features
  • Selective building: Only builds tools for enabled features instead of all tools
  • Merge-friendly architecture: Clear extension points for other feature branches to add their tools
  • Backward compatible: Existing MTMD functionality unchanged, just faster builds

Technical Implementation

  • Replaces static CMakeLists.txt with dynamic generation in build.rs
  • Uses feature flags to determine which tools to include
  • Provides commented template for future tool features
  • Eliminates need for including top-level tools/CMakeLists.txt that builds everything

Benefits

  • Fixes build error when mtmd feature enabled
  • Faster builds - no more compiling unused tools
  • Smaller binary - only includes needed functionality
  • Future-proof - easy for other branches to extend

Test Plan

  • Builds successfully with cargo build --features mtmd
  • Builds successfully without mtmd feature (no tools built)
  • MTMD functionality works as expected
  • No breaking changes to existing API

Resolves #806

🤖 Generated with Claude Code

… building

Replace static tools CMakeLists.txt approach with dynamic generation based on
enabled features. This creates a scalable, merge-friendly solution for our
feature branches.

Key improvements:
- Dynamic CMakeLists.txt generation via generate_tools_cmake() function
- Only builds tools for enabled features (currently just MTMD)
- Designed for easy extension by other feature branches
- No static files to conflict during merges
- Clear extension points with commented examples

Architecture:
- generate_tools_cmake() creates tools/CMakeLists.txt at build time
- any_tool_features flag determines if tools directory should be built
- Each feature branch can add their tool by uncommenting their section

This solves the original PR utilityai#806 issue (avoiding building all tools) while
providing a foundation for RPC, server, quantize, and other tool features.

Future branches can easily add their tools by:
1. Adding their feature to any_tool_features check
2. Uncommenting their add_subdirectory() line in generate_tools_cmake()
3. Including their tool's CMakeLists.txt in Cargo.toml

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@hongkongkiwi
Copy link
Author

This is a solution where we can fix the build errors identified in #810 but in a way which doesn't try to build the whole tools dir.

@MarcusDunn
Copy link
Contributor

MarcusDunn commented Aug 24, 2025

does the llama.cpp Cmake build the tools dir when there are no features enabled right now?

@altunenes
Copy link

I can confirm the same build issues (macos), and this pr solves my problem

Comment on lines +240 to +242
let tools_cmake_path = Path::new("llama.cpp/tools/CMakeLists.txt");
fs::write(tools_cmake_path, cmake_content)
.expect("Failed to write generated tools CMakeLists.txt");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this fail when building docs because it's built on a read-only file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants