From f30c1deb72a34cd8b15b604376c427c07121339e Mon Sep 17 00:00:00 2001 From: bmerkle Date: Sun, 20 Oct 2024 00:32:02 +0200 Subject: [PATCH] check for build requirements and abort build process if not satisied - python>=3.9 - cmake>=3.22 - clang>=18 on windows use the msvc-clang (>=17) fix https://github.com/microsoft/BitNet/issues/34 --- CMakeLists.txt | 2 +- setup_env.py | 8 ++++++++ src/CMakeLists.txt | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7a0c994..176a9f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) # for add_link_options and implicit target directories. +cmake_minimum_required(VERSION 3.22) # for add_link_options and implicit target directories. project("bitnet.cpp" C CXX) include(CheckIncludeFileCXX) diff --git a/setup_env.py b/setup_env.py index b9bf5fc5..939b6e51 100644 --- a/setup_env.py +++ b/setup_env.py @@ -173,7 +173,15 @@ def compile(): # run_command(["cmake", "--build", "build", "--target", "llama-cli", "--config", "Release"]) run_command(["cmake", "--build", "build", "--config", "Release"], log_step="compile") +def check_python_version(): + python_version = sys.version_info + if python_version < (3, 9): + logging.error("Python 3.9 or higher is required for Bitnet.cpp.") + sys.exit(1) + logging.info(f"Python version: {python_version.major}.{python_version.minor}.{python_version.micro}") + def main(): + check_python_version() setup_gguf() gen_code() compile() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cead70f..ba2cc8a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,26 @@ set(GGML_SOURCES_BITNET ggml-bitnet-lut.cpp) include_directories(3rdparty/llama.cpp/ggml/include) +if(CMAKE_VERSION VERSION_LESS "3.22") + message(FATAL_ERROR "CMake version 3.22 or higher is required for Bitnet.cpp compilation") +endif() + if ((NOT ${CMAKE_C_COMPILER_ID} MATCHES "Clang") OR (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) message(FATAL_ERROR "Clang is required for Bitnet.cpp compilation") +else() + # Check for minimum Clang version: + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC") + # on Windows we use the Visual Studio Clang compiler (in 2022 it is version 17.) + message(STATUS "Visual Studio Clang compiler is being used.") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0) + message(FATAL_ERROR "Visual Studio Clang version 17.0 or higher is required for Bitnet.cpp compilation") + endif() + else() + # on Linux Clang compiler >= 18.0 is required. + message(STATUS "Linux/Mac Clang compiler is being used.") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) + message(FATAL_ERROR "Clang version 18.0 or higher is required for Bitnet.cpp compilation") + endif() + endif() endif() \ No newline at end of file