Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 6112ff3

Browse files
authored
Install windows (#47)
* Modify CMakeLists for Windows * Add documents for Nitro on Windows * Copy zlib dynamic lib * Modify CMakeLists for Windows * Add documents for Nitro on Windows * Copy zlib dynamic lib * Fix cmd to run nitro * Add path to binary file * Fix flag * Fix format * Add Windows condition
1 parent 40d9ec5 commit 6112ff3

File tree

4 files changed

+80
-16
lines changed

4 files changed

+80
-16
lines changed

README_temp.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
### Step 1:
44

55
Install dependencies static files
6-
7-
```zsh
8-
./install_deps.sh
9-
```
10-
6+
- On MacOS with Apple silicon
7+
```zsh
8+
./install_deps.sh
9+
```
10+
- On Windows
11+
```
12+
cmake -S ./nitro_deps -B ./build_deps/nitro_deps
13+
cmake --build ./build_deps/nitro_deps --config Release
14+
```
1115
This will create a build_deps folder, just ignore it
1216

1317
### Step 2:
1418

1519
Generate build file
16-
- On MacOS with Apple silicon:
20+
- On MacOS, Linux, and Windows
1721

1822
```zsh
1923
mkdir build && cd build
2024
cmake ..
2125
```
2226

23-
- On MacOS with Intel processors:
27+
- On MacOS with Intel processors
2428
```zsh
2529
mkdir build && cd build
2630
cmake -DLLAMA_METAL=OFF ..
@@ -42,8 +46,18 @@ Build the app
4246
make -j $(%NUMBER_OF_PROCESSORS%)
4347
```
4448

45-
### Step 3:
49+
- On Windows
50+
```
51+
cmake --build . --config Release
52+
```
4653

47-
Run ./nitro to start the process.
54+
### Step 3:
55+
- On MacOS and Linux run ./nitro to start the process.
56+
- On Windows:
57+
```
58+
cd Release
59+
# add zlib dynamic lib
60+
copy ..\..\build_deps\_install\bin\zlib.dll .
61+
nitro.exe
4862

4963
To see if the build was successful, visit `localhost:8080/test`

controllers/llamaCPP.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if defined(_WIN32)
2+
#define NOMINMAX
3+
#endif
4+
15
#pragma once
26

37
#include "controllers/nitro_utils.h"

main.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
#elif defined(__linux__)
99
#include <libgen.h> // for dirname()
1010
#include <unistd.h> // for readlink()
11+
#elif defined(_WIN32)
12+
#include <windows.h>
1113
#else
1214
#error "Unsupported platform!"
1315
#endif
1416

1517
int main() {
16-
char path[PATH_MAX];
1718
std::string configPath;
1819

1920
#if defined(__APPLE__) && defined(__MACH__)
21+
char path[PATH_MAX];
2022
uint32_t size = sizeof(path);
2123
if (_NSGetExecutablePath(path, &size) == 0) {
2224
path[size] = '\0'; // Null-terminate the string
@@ -27,6 +29,7 @@ int main() {
2729
return 1;
2830
}
2931
#elif defined(__linux__)
32+
char path[PATH_MAX];
3033
ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1);
3134
if (len != -1) {
3235
path[len] = '\0';
@@ -36,6 +39,23 @@ int main() {
3639
LOG_ERROR << "Failed to get binary location!";
3740
return 1;
3841
}
42+
#elif defined(_WIN32)
43+
char path[MAX_PATH];
44+
char dir[MAX_PATH];
45+
// char dir[MAX_PATH];
46+
if(GetModuleFileNameA(NULL, path, sizeof(path))) {
47+
char* lastBackslash = strrchr(path, '\\');
48+
if (lastBackslash == nullptr) {
49+
return 1;
50+
}
51+
lastBackslash[0] = '\0';
52+
strcpy(dir, path);
53+
configPath = std::string(dir) + "/config/config.json";
54+
}
55+
else {
56+
LOG_ERROR << "Failed to get binary location!";
57+
return 1;
58+
}
3959
#else
4060
LOG_ERROR << "Unsupported platform!";
4161
return 1;

nitro_deps/CMakeLists.txt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ set(THIRD_PARTY_INSTALL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../build_deps/_install)
1616
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
1717
#
1818
# Add the external project
19+
set(ZLIB_USE_STATIC_LIBS OFF)
20+
find_package(ZLIB)
21+
if(NOT ZLIB_FOUND)
22+
set(ZLIB_USE_STATIC_LIBS ON)
23+
ExternalProject_Add(
24+
zlib
25+
GIT_REPOSITORY https://github.com/madler/zlib.git
26+
GIT_TAG v1.2.11
27+
CMAKE_ARGS
28+
-DBUILD_SHARED_LIBS=OFF
29+
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
30+
)
31+
endif()
32+
1933
ExternalProject_Add(
2034
brotli
2135
GIT_REPOSITORY https://github.com/google/brotli
@@ -24,7 +38,7 @@ ExternalProject_Add(
2438
-DCMAKE_BUILD_TYPE=Release
2539
-DBUILD_SHARED_LIBS=OFF
2640
-DSHARE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/share
27-
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
41+
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
2842
)
2943

3044
ExternalProject_Add(
@@ -34,7 +48,6 @@ ExternalProject_Add(
3448
CMAKE_ARGS
3549
-DBUILD_SHARED_LIBS=OFF
3650
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
37-
3851
)
3952

4053
ExternalProject_Add(
@@ -52,24 +65,37 @@ ExternalProject_Add(
5265
GIT_REPOSITORY https://github.com/drogonframework/drogon
5366
GIT_TAG v1.8.6
5467
CMAKE_ARGS
55-
-DCMAKE_BUILD_TYPE=release
68+
-DCMAKE_BUILD_TYPE=release
5669
-DOPENSSL_USE_STATIC_LIBS=TRUE
57-
# -DZLIB_USE_STATIC_LIBS=ON
70+
-DZLIB_USE_STATIC_LIBS=${ZLIB_USE_STATIC_LIBS}
5871
-DBUILD_ORM=OFF
5972
-DBUILD_YAML_CONFIG=OFF
6073
-DBUILD_EXAMPLES=OFF
6174
-DBUILD_CTL=OFF
6275
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
6376
-DBUILD_BROTLI=ON
6477
-DCMAKE_PREFIX_PATH=${THIRD_PARTY_INSTALL_PATH}
65-
# -DCMAKE_FIND_ROOT_PATH=${THIRD_PARTY_INSTALL_PATH} # To set the dir (that will be used to force the look for .a)
66-
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
78+
# -DCMAKE_FIND_ROOT_PATH=${THIRD_PARTY_INSTALL_PATH} # To set the dir (that will be used to force the look for .a)
79+
-DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH}
6780
)
6881

82+
# Fix trantor cmakelists to link c-ares on Windows
83+
if(WIN32)
84+
set(TRANTOR_CMAKE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../build_deps/nitro_deps/drogon-prefix/src/drogon/trantor/CMakeLists.txt)
85+
ExternalProject_Add_Step(drogon trantor_custom_target
86+
COMMAND ${CMAKE_COMMAND} -E echo add_definitions(-DCARES_STATICLIB) >> ${TRANTOR_CMAKE_FILE}
87+
DEPENDEES download
88+
)
89+
endif()
90+
6991
include_directories(${THIRD_PARTY_INSTALL_PATH}/include)
7092
link_directories(${THIRD_PARTY_INSTALL_PATH}/lib)
7193
# Optionally link or add dependencies to your targets
7294
add_dependencies(drogon c-ares jsoncpp brotli)
95+
96+
if(ZLIB_USE_STATIC_LIBS)
97+
add_dependencies(drogon zlib)
98+
endif()
7399
# target_link_libraries(<your-target> ...)
74100

75101

0 commit comments

Comments
 (0)