Skip to content

Commit

Permalink
feat: beta updater (#1197)
Browse files Browse the repository at this point in the history
* feat: beta updater

* fix: add --version

* fix: more checks

* fix: more

* fix: no target name changes

* fix: download binary to temp folder for cortex update

* fix: rename should be in the same folder

* fix: comment

* fix: more

* fix: use constants

* fix: comments
  • Loading branch information
vansangpfiev authored Sep 16, 2024
1 parent 05d67be commit 6abf575
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 172 deletions.
123 changes: 25 additions & 98 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ cmake_minimum_required(VERSION 3.5)

project(cortex C CXX)

# Build using CMAKE-JS
if(DEFINED CMAKE_JS_INC)
if(WIN32)
add_definitions(
-DV8_COMPRESS_POINTERS
-DV8_REVERSE_JSARGS
-DV8_COMPRESS_POINTERS_IN_ISOLATE_CAGE
)
endif()
include_directories(${CMAKE_JS_INC})
endif()

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
Expand All @@ -33,8 +21,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build-deps/_install)
# This is the critical line for installing another package

if(MSVC)
add_compile_options(
Expand All @@ -43,16 +29,6 @@ if(MSVC)
$<$<CONFIG:Release>:/MT> #--|
)
endif()

if(LLAMA_CUDA)
cmake_minimum_required(VERSION 3.17)

find_package(CUDAToolkit)
if(CUDAToolkit_FOUND)
message(STATUS "cuBLAS found")
add_compile_definitions(GGML_USE_CUDA)
endif()
endif()

if(DEBUG)
message(STATUS "CORTEX-CPP DEBUG IS ON")
Expand All @@ -63,29 +39,24 @@ if(NOT DEFINED CORTEX_VARIANT)
set(CORTEX_VARIANT "prod")
endif()

set(TARGET_NAME ${PROJECT_NAME})
if(RENAME_EXE)
if(CORTEX_VARIANT STREQUAL "beta")
set(TARGET_NAME "${PROJECT_NAME}-beta")
elseif(CORTEX_VARIANT STREQUAL "nightly")
set(TARGET_NAME "${PROJECT_NAME}-nightly")
else()
set(TARGET_NAME ${PROJECT_NAME})
endif()
endif()

if(NOT DEFINED CORTEX_CONFIG_FILE_PATH)
set(CORTEX_CONFIG_FILE_PATH "user_home")
endif()

if(NOT DEFINED CORTEX_CPP_VERSION)
set(CORTEX_CPP_VERSION "default_version")
endif()

if(APPLE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm.*|ARM64)$")
# MacOS silicon
set(LLAMA_METAL_EMBED_LIBRARY ON)
set(WHISPER_COREML 1)
else()
# MacOS amd64
set(LLAMA_METAL OFF)
endif()
endif()

if(DEFINED CMAKE_JS_INC)
# define NPI_VERSION
add_compile_definitions(NAPI_VERSION=8)
endif()

add_compile_definitions(CORTEX_VARIANT="${CORTEX_VARIANT}")
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
Expand All @@ -108,73 +79,29 @@ find_package(LibArchive REQUIRED)
find_package(tabulate CONFIG REQUIRED)
find_package(CURL REQUIRED)

# Build using CMAKE-JS
if(DEFINED CMAKE_JS_INC)
if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") OR("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()

add_library(${PROJECT_NAME} SHARED addon.cc
add_executable(${TARGET_NAME} main.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/cpuid/cpu_info.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/file_logger.cc
${CMAKE_JS_SRC}
)

if(WIN32)
target_link_libraries(${PROJECT_NAME}
PRIVATE
msvcprt.lib
msvcrt.lib
vcruntime.lib
ucrt.lib
${CMAKE_JS_LIB}
)
endif()
else() # Official build
add_executable(${PROJECT_NAME} main.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/cpuid/cpu_info.cc
${CMAKE_CURRENT_SOURCE_DIR}/utils/file_logger.cc
)
endif()

# ##############################################################################
# If you include the drogon source code locally in your project, use this method
# to add drogon add_subdirectory(cortex-cpp-deps)
# target_link_libraries(${PROJECT_NAME} PRIVATE cortex-cpp-deps)
#
# and comment out the following lines

target_link_libraries(${PROJECT_NAME} PRIVATE httplib::httplib)
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(${PROJECT_NAME} PRIVATE jinja2cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE CLI11::CLI11)
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::minizip::minizip)
target_link_libraries(${PROJECT_NAME} PRIVATE LibArchive::LibArchive)
target_link_libraries(${PROJECT_NAME} PRIVATE tabulate::tabulate)
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)

# Build using CMAKE-JS
if(DEFINED CMAKE_JS_INC)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")

target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_JS_LIB})

if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
else()
target_link_libraries(${PROJECT_NAME} PRIVATE JsonCpp::JsonCpp Drogon::Drogon OpenSSL::SSL OpenSSL::Crypto yaml-cpp::yaml-cpp
target_link_libraries(${TARGET_NAME} PRIVATE httplib::httplib)
target_link_libraries(${TARGET_NAME} PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(${TARGET_NAME} PRIVATE jinja2cpp)
target_link_libraries(${TARGET_NAME} PRIVATE CLI11::CLI11)
target_link_libraries(${TARGET_NAME} PRIVATE unofficial::minizip::minizip)
target_link_libraries(${TARGET_NAME} PRIVATE LibArchive::LibArchive)
target_link_libraries(${TARGET_NAME} PRIVATE tabulate::tabulate)
target_link_libraries(${TARGET_NAME} PRIVATE CURL::libcurl)
target_link_libraries(${TARGET_NAME} PRIVATE JsonCpp::JsonCpp Drogon::Drogon OpenSSL::SSL OpenSSL::Crypto yaml-cpp::yaml-cpp
${CMAKE_THREAD_LIBS_INIT})
endif()

# ##############################################################################

if(CMAKE_CXX_STANDARD LESS 17)
# With C++14, use boost to support any and std::string_view
message(STATUS "use c++14")
find_package(Boost 1.61.0 REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(${TARGET_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
elseif(CMAKE_CXX_STANDARD LESS 20)
message(STATUS "use c++17")
else()
Expand All @@ -189,6 +116,6 @@ aux_source_directory(cortex-common CORTEX_COMMON)
aux_source_directory(config CONFIG_SRC)
aux_source_directory(commands COMMANDS_SRC)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} )
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} )

target_sources(${PROJECT_NAME} PRIVATE ${COMMANDS_SRC} ${CONFIG_SRC} ${CTL_SRC} ${COMMON_SRC} ${SERVICES_SRC})
target_sources(${TARGET_NAME} PRIVATE ${COMMANDS_SRC} ${CONFIG_SRC} ${CTL_SRC} ${COMMON_SRC} ${SERVICES_SRC})
Loading

0 comments on commit 6abf575

Please sign in to comment.