Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
32 changes: 23 additions & 9 deletions README_temp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
Expand All @@ -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`
4 changes: 4 additions & 0 deletions controllers/llamaCPP.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if defined(_WIN32)
#define NOMINMAX
#endif

#pragma once

#include "controllers/nitro_utils.h"
Expand Down
22 changes: 21 additions & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
#elif defined(__linux__)
#include <libgen.h> // for dirname()
#include <unistd.h> // for readlink()
#elif defined(_WIN32)
#include <windows.h>
#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
Expand All @@ -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';
Expand All @@ -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;
Expand Down
38 changes: 32 additions & 6 deletions nitro_deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -34,7 +48,6 @@ ExternalProject_Add(
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}

)

ExternalProject_Add(
Expand All @@ -52,24 +65,37 @@ 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
-DBUILD_CTL=OFF
-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(<your-target> ...)