diff --git a/README_temp.md b/README_temp.md index 4eb9e4111..d3e8ebeb0 100644 --- a/README_temp.md +++ b/README_temp.md @@ -3,24 +3,28 @@ ### Step 1: Install dependencies static files - -```zsh -./install_deps.sh -``` - +- On MacOS with Apple silicon + ```zsh + ./install_deps.sh + ``` +- On Windows + ``` + cmake -S ./nitro_deps -B ./build_deps/nitro_deps + cmake --build ./build_deps/nitro_deps --config Release + ``` This will create a build_deps folder, just ignore it ### Step 2: Generate build file -- On MacOS with Apple silicon: +- On MacOS, Linux, and Windows ```zsh mkdir build && cd build cmake .. ``` -- On MacOS with Intel processors: +- On MacOS with Intel processors ```zsh mkdir build && cd build cmake -DLLAMA_METAL=OFF .. @@ -42,8 +46,18 @@ Build the app make -j $(%NUMBER_OF_PROCESSORS%) ``` -### Step 3: +- On Windows + ``` + cmake --build . --config Release + ``` -Run ./nitro to start the process. +### Step 3: +- On MacOS and Linux run ./nitro to start the process. +- On Windows: + ``` + cd Release + # add zlib dynamic lib + copy ..\..\build_deps\_install\bin\zlib.dll . + nitro.exe To see if the build was successful, visit `localhost:8080/test` diff --git a/controllers/llamaCPP.h b/controllers/llamaCPP.h index fc719980c..e663e00aa 100644 --- a/controllers/llamaCPP.h +++ b/controllers/llamaCPP.h @@ -1,3 +1,7 @@ +#if defined(_WIN32) +#define NOMINMAX +#endif + #pragma once #include "controllers/nitro_utils.h" diff --git a/main.cc b/main.cc index d10ed5a49..5ac05720e 100644 --- a/main.cc +++ b/main.cc @@ -8,15 +8,17 @@ #elif defined(__linux__) #include // for dirname() #include // for readlink() +#elif defined(_WIN32) +#include #else #error "Unsupported platform!" #endif int main() { - char path[PATH_MAX]; std::string configPath; #if defined(__APPLE__) && defined(__MACH__) + char path[PATH_MAX]; uint32_t size = sizeof(path); if (_NSGetExecutablePath(path, &size) == 0) { path[size] = '\0'; // Null-terminate the string @@ -27,6 +29,7 @@ int main() { return 1; } #elif defined(__linux__) + char path[PATH_MAX]; ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1); if (len != -1) { path[len] = '\0'; @@ -36,6 +39,23 @@ int main() { LOG_ERROR << "Failed to get binary location!"; return 1; } +#elif defined(_WIN32) + char path[MAX_PATH]; + char dir[MAX_PATH]; + // char dir[MAX_PATH]; + if(GetModuleFileNameA(NULL, path, sizeof(path))) { + char* lastBackslash = strrchr(path, '\\'); + if (lastBackslash == nullptr) { + return 1; + } + lastBackslash[0] = '\0'; + strcpy(dir, path); + configPath = std::string(dir) + "/config/config.json"; + } + else { + LOG_ERROR << "Failed to get binary location!"; + return 1; + } #else LOG_ERROR << "Unsupported platform!"; return 1; diff --git a/nitro_deps/CMakeLists.txt b/nitro_deps/CMakeLists.txt index 6b106ac65..396e60647 100644 --- a/nitro_deps/CMakeLists.txt +++ b/nitro_deps/CMakeLists.txt @@ -16,6 +16,20 @@ set(THIRD_PARTY_INSTALL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../build_deps/_install) #set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) # # Add the external project +set(ZLIB_USE_STATIC_LIBS OFF) +find_package(ZLIB) +if(NOT ZLIB_FOUND) + set(ZLIB_USE_STATIC_LIBS ON) + ExternalProject_Add( + zlib + GIT_REPOSITORY https://github.com/madler/zlib.git + GIT_TAG v1.2.11 + CMAKE_ARGS + -DBUILD_SHARED_LIBS=OFF + -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} + ) +endif() + ExternalProject_Add( brotli GIT_REPOSITORY https://github.com/google/brotli @@ -24,7 +38,7 @@ ExternalProject_Add( -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DSHARE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/share - -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} + -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} ) ExternalProject_Add( @@ -34,7 +48,6 @@ ExternalProject_Add( CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} - ) ExternalProject_Add( @@ -52,9 +65,9 @@ ExternalProject_Add( GIT_REPOSITORY https://github.com/drogonframework/drogon GIT_TAG v1.8.6 CMAKE_ARGS - -DCMAKE_BUILD_TYPE=release + -DCMAKE_BUILD_TYPE=release -DOPENSSL_USE_STATIC_LIBS=TRUE - # -DZLIB_USE_STATIC_LIBS=ON + -DZLIB_USE_STATIC_LIBS=${ZLIB_USE_STATIC_LIBS} -DBUILD_ORM=OFF -DBUILD_YAML_CONFIG=OFF -DBUILD_EXAMPLES=OFF @@ -62,14 +75,27 @@ ExternalProject_Add( -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_BROTLI=ON -DCMAKE_PREFIX_PATH=${THIRD_PARTY_INSTALL_PATH} -# -DCMAKE_FIND_ROOT_PATH=${THIRD_PARTY_INSTALL_PATH} # To set the dir (that will be used to force the look for .a) - -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} + # -DCMAKE_FIND_ROOT_PATH=${THIRD_PARTY_INSTALL_PATH} # To set the dir (that will be used to force the look for .a) + -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} ) +# Fix trantor cmakelists to link c-ares on Windows +if(WIN32) + set(TRANTOR_CMAKE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../build_deps/nitro_deps/drogon-prefix/src/drogon/trantor/CMakeLists.txt) + ExternalProject_Add_Step(drogon trantor_custom_target + COMMAND ${CMAKE_COMMAND} -E echo add_definitions(-DCARES_STATICLIB) >> ${TRANTOR_CMAKE_FILE} + DEPENDEES download + ) +endif() + include_directories(${THIRD_PARTY_INSTALL_PATH}/include) link_directories(${THIRD_PARTY_INSTALL_PATH}/lib) # Optionally link or add dependencies to your targets add_dependencies(drogon c-ares jsoncpp brotli) + +if(ZLIB_USE_STATIC_LIBS) + add_dependencies(drogon zlib) +endif() # target_link_libraries( ...)