diff --git a/CMakeLists.txt b/CMakeLists.txt index 3df1d82dbe..d43eeef0d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.14...3.28) # for add_link_options and implicit project("llama.cpp" C CXX) include(CheckIncludeFileCXX) +### llama.cpp version +set(LLAMA_VERSION_MAJOR 0) +set(LLAMA_VERSION_MINOR 1) +set(LLAMA_VERSION_PATCH 0) +set(LLAMA_VERSION_BASE "${LLAMA_VERSION_MAJOR}.${LLAMA_VERSION_MINOR}.${LLAMA_VERSION_PATCH}") + #set(CMAKE_WARN_DEPRECATED YES) set(CMAKE_WARN_UNUSED_CLI YES) @@ -24,9 +30,6 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(LLAMA_STANDALONE ON) include(git-vars) - - # configure project version - # TODO else() set(LLAMA_STANDALONE OFF) endif() @@ -139,7 +142,15 @@ endif() if (NOT DEFINED LLAMA_BUILD_COMMIT) set(LLAMA_BUILD_COMMIT ${BUILD_COMMIT}) endif() -set(LLAMA_INSTALL_VERSION 0.0.${LLAMA_BUILD_NUMBER}) + +if (BUILD_RELEASE_TAG) + set(LLAMA_VERSION "${LLAMA_VERSION_BASE}") +else() + set(LLAMA_VERSION "${LLAMA_VERSION_BASE}-dev-b${LLAMA_BUILD_NUMBER}") +endif() +set(LLAMA_INSTALL_VERSION ${LLAMA_VERSION}) + +message(STATUS "llama.cpp version: ${LLAMA_INSTALL_VERSION}") # override ggml options set(GGML_ALL_WARNINGS ${LLAMA_ALL_WARNINGS}) @@ -275,12 +286,12 @@ configure_package_config_file( LLAMA_BIN_INSTALL_DIR ) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake + ${CMAKE_CURRENT_BINARY_DIR}/llama-config-version.cmake VERSION ${LLAMA_INSTALL_VERSION} COMPATIBILITY SameMajorVersion) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake + ${CMAKE_CURRENT_BINARY_DIR}/llama-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llama) configure_file(cmake/llama.pc.in diff --git a/cmake/build-info.cmake b/cmake/build-info.cmake index c7005950c5..9dd8548a6d 100644 --- a/cmake/build-info.cmake +++ b/cmake/build-info.cmake @@ -15,6 +15,8 @@ if(NOT Git_FOUND) endif() endif() +set(BUILD_RELEASE_TAG "") + # Get the commit count and hash if(Git_FOUND) execute_process( @@ -37,6 +39,18 @@ if(Git_FOUND) if (RES EQUAL 0) set(BUILD_NUMBER ${COUNT}) endif() + # Check if HEAD is tagged with a semver release tag (e.g. v0.0.1) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags --match "v[0-9]*" HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE BUILD_RELEASE_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RES + ERROR_QUIET + ) + if (NOT RES EQUAL 0) + set(BUILD_RELEASE_TAG "") + endif() endif() set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}") diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 799d227519..d6cfc9a008 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -121,8 +121,8 @@ add_library(${TARGET} ) set_target_properties(${TARGET} PROPERTIES - VERSION ${LLAMA_INSTALL_VERSION} - SOVERSION 0 + VERSION ${LLAMA_VERSION_BASE} + SOVERSION ${LLAMA_VERSION_MAJOR} MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number ) diff --git a/examples/test-cmake/.gitignore b/examples/test-cmake/.gitignore new file mode 100644 index 0000000000..0ddff317a4 --- /dev/null +++ b/examples/test-cmake/.gitignore @@ -0,0 +1,3 @@ +llama-build-install +install +build diff --git a/examples/test-cmake/CMakeLists.txt b/examples/test-cmake/CMakeLists.txt new file mode 100644 index 0000000000..76d9b1db3d --- /dev/null +++ b/examples/test-cmake/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.14) +project(llama-simple) + +set(CMAKE_CXX_STANDARD 17) + +find_package(llama 0.1.0 REQUIRED) + +add_executable(test-cmake test-cmake.cpp) +target_link_libraries(test-cmake PRIVATE llama) diff --git a/examples/test-cmake/README.md b/examples/test-cmake/README.md new file mode 100644 index 0000000000..48346d5bbc --- /dev/null +++ b/examples/test-cmake/README.md @@ -0,0 +1,55 @@ +## cmake-test + +This is just for manually testing/developing of a llama.cpp installation to +enable troubleshooting issues and exploration. The idea is that this can be used +after making changes to llama.cpp installation cmake configuration and then +verify it locally. + +### Usage +The following will configure, build, and install llama.cpp + +Configuring/build/install: +```console +./build-install.sh +``` +The above command will create a directory named `install` in the current directory +which will have the follwing files in its lib directory: +```console +(venv) $ ls install/lib/ +cmake libggml.so libllama-common.so.0 libllama.so.0.1.0 llama.cpp +libggml-base.so libggml.so.0 libllama-common.so.0.1.0 libmtmd.so pkgconfig +libggml-base.so.0 libggml.so.0.19.0 libllama.so libmtmd.so.0 +libggml-base.so.0.19.0 libllama-common.so libllama.so.0 libmtmd.so.0.1.0 + +``` + +Build/run this project using the installation created above: +```console +(venv) $ ./build.sh +-- Configuring done (0.0s) +-- Generating done (0.0s) +-- Build files have been written to: /home/danbev/work/ai/llama.cpp/examples/test-cmake/build +[100%] Built target test-cmake +[test-cmake] Using llama.cpp version 0.1.0-dev-b10335 +[test-cmake] Initializing backend... +load_backend: loaded CPU backend from /home/danbev/work/ai/llama.cpp/examples/test-cmake/install/lib/llama.cpp/libggml-cpu-alderlake.so +[test-cmake] Backend initialized. +``` +Notice that the llama.cpp version is currently `0.1.0-dev-b10335`. + +### Nightly builds +Currently nightly/daily builds use build number if the format `b10333`. This will +change if the changes in here are accepted and the build would be named in the +following format: `0.1.0-dev-b10335`. + +### Releases +Releases should now be able to create a tag with the target version, using the +example above `0.1.0-dev-b10335` was the pre-release version so we would tag +the real release with 0.1.0. + +After this we need to dump the version in CMakeLists.txt so that the pre-release +is for the next version, for example `0.2.0`. TODO: need to figure this out and +if this can be automated so that there are no builds that get created in the +time between the actual release and a new nightly/daily build. + +_wip_ diff --git a/examples/test-cmake/build-install.sh b/examples/test-cmake/build-install.sh new file mode 100755 index 0000000000..77a6713d67 --- /dev/null +++ b/examples/test-cmake/build-install.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +rm -rf llama-build-install install + +cmake --fresh -S ../../. -B llama-build-install -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=ON \ + -DGGML_BACKEND_DL=ON \ + -DGGML_CPU_ALL_VARIANTS=ON \ + -DLLAMA_TESTS_INSTALL=OFF \ + -DCMAKE_INSTALL_PREFIX="${PWD}/install" \ + -DGGML_BACKEND_DIR="${PWD}/install/lib/llama.cpp" \ + -DGGML_LIB_INSTALL_DIR="${PWD}/install/lib/llama.cpp" \ + -DLLAMA_LIB_INSTALL_DIR="${PWD}/install/lib/llama.cpp" \ + -DLLAMA_TOOLS_INSTALL=OFF + +cmake --build llama-build-install --parallel 12 +cmake --install llama-build-install diff --git a/examples/test-cmake/build.sh b/examples/test-cmake/build.sh new file mode 100755 index 0000000000..a212732b89 --- /dev/null +++ b/examples/test-cmake/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +cmake -S . -B build -DCMAKE_PREFIX_PATH="${PWD}/install" +cmake --build build +LD_LIBRARY_PATH="${PWD}/install/lib/llama.cpp:${PWD}/install/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" ./build/test-cmake diff --git a/examples/test-cmake/test-cmake.cpp b/examples/test-cmake/test-cmake.cpp new file mode 100644 index 0000000000..ead0c390ae --- /dev/null +++ b/examples/test-cmake/test-cmake.cpp @@ -0,0 +1,11 @@ +#include "llama.h" +#include + +int main(void) { + printf("[test-cmake] Using llama.cpp version %s\n", llama_version()); + printf("[test-cmake] Initializing backend...\n"); + llama_backend_init(); + printf("[test-cmake] Backend initialized.\n"); + llama_backend_free(); + return 0; +} diff --git a/include/llama.h b/include/llama.h index a14498925f..068b575330 100644 --- a/include/llama.h +++ b/include/llama.h @@ -455,6 +455,8 @@ extern "C" { // lora adapter struct llama_adapter_lora; + LLAMA_API const char * llama_version(void); + // Helpers for getting default parameters // TODO: update API to start accepting pointers to params structs (https://github.com/ggml-org/llama.cpp/discussions/9172) LLAMA_API struct llama_model_params llama_model_default_params(void); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24f05cc916..3bdd698576 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,11 +45,16 @@ add_library(llama ) set_target_properties(llama PROPERTIES - VERSION ${LLAMA_INSTALL_VERSION} - SOVERSION 0 + VERSION ${LLAMA_VERSION_BASE} + SOVERSION ${LLAMA_VERSION_MAJOR} MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number ) +target_compile_definitions(llama PRIVATE + LLAMA_VERSION="${LLAMA_INSTALL_VERSION}" + LLAMA_COMMIT="${LLAMA_BUILD_COMMIT}" +) + target_include_directories(llama PRIVATE .) target_include_directories(llama PUBLIC ../include) target_compile_features (llama PRIVATE cxx_std_17) # don't bump diff --git a/src/llama.cpp b/src/llama.cpp index d6e0bbfefa..b9918de402 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -111,6 +111,10 @@ bool llama_supports_rpc(void) { return ggml_backend_reg_by_name("RPC") != nullptr; } +const char * llama_version(void) { + return LLAMA_VERSION; +} + void llama_backend_init(void) { ggml_time_init(); diff --git a/tools/mtmd/CMakeLists.txt b/tools/mtmd/CMakeLists.txt index 4675fb9a97..6071c732b3 100644 --- a/tools/mtmd/CMakeLists.txt +++ b/tools/mtmd/CMakeLists.txt @@ -68,8 +68,8 @@ add_library(mtmd ) set_target_properties(mtmd PROPERTIES - VERSION ${LLAMA_INSTALL_VERSION} - SOVERSION 0 + VERSION ${LLAMA_VERSION_BASE} + SOVERSION ${LLAMA_VERSION_MAJOR} MACHO_CURRENT_VERSION 0 # keep macOS linker from seeing oversized version number )