Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install choco on Windows
if: runner.os == 'Windows'
run: |
Expand Down
33 changes: 26 additions & 7 deletions engine/main.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <drogon/HttpAppFramework.h>
#include <drogon/drogon.h>
#include <climits> // for PATH_MAX
#include "commands/cortex_upd_cmd.h"
#include "controllers/command_line_parser.h"
#include "cortex-common/cortexpythoni.h"
#include "utils/archive_utils.h"
Expand All @@ -9,7 +10,6 @@
#include "utils/file_logger.h"
#include "utils/file_manager_utils.h"
#include "utils/logging_utils.h"
#include "commands/cortex_upd_cmd.h"

#if defined(__APPLE__) && defined(__MACH__)
#include <libgen.h> // for dirname()
Expand All @@ -32,8 +32,9 @@ void RunServer() {
<< " Port: " << config.apiServerPort << "\n";

// Create logs/ folder and setup log to file
std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
std::filesystem::create_directories(
std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
trantor::FileLogger asyncFileLogger;
asyncFileLogger.setFileName(config.logFolderPath + "/" +
cortex_utils::logs_base_name);
Expand Down Expand Up @@ -123,8 +124,25 @@ void ForkProcess() {
std::cerr << "Could not start server: " << std::endl;
return;
} else if (pid == 0) {
// Child process
RunServer();
// No need to configure LD_LIBRARY_PATH for macOS
#if !defined(__APPLE__) || !defined(__MACH__)
const char* name = "LD_LIBRARY_PATH";
auto data = getenv(name);
std::string v;
if (auto g = getenv(name); g) {
v += g;
}
CTL_INF("LD_LIBRARY_PATH: " << v);
auto data_path = file_manager_utils::GetCortexDataPath();
auto llamacpp_path = data_path / "engines" / "cortex.llamacpp/";
auto trt_path = data_path / "engines" / "cortex.tensorrt-llm/";
auto new_v = trt_path.string() + ":" + llamacpp_path.string() + ":" + v;
setenv(name, new_v.c_str(), true);
CTL_INF("LD_LIBRARY_PATH: " << getenv(name));
#endif
auto exe = commands::GetCortexBinary();
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
execl(p.c_str(), exe.c_str(), "--start-server", (char*)0);
} else {
// Parent process
std::cout << "Server started" << std::endl;
Expand Down Expand Up @@ -173,8 +191,9 @@ int main(int argc, char* argv[]) {
return 0;
} else {
auto config = file_manager_utils::GetCortexConfig();
std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
std::filesystem::create_directories(
std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
trantor::FileLogger asyncFileLogger;
asyncFileLogger.setFileName(config.logFolderPath + "/" +
cortex_utils::logs_cli_base_name);
Expand Down
8 changes: 4 additions & 4 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ inline std::filesystem::path GetExecutableFolderContainerPath() {
uint32_t size = sizeof(buffer);

if (_NSGetExecutablePath(buffer, &size) == 0) {
LOG_INFO << "Executable path: " << buffer;
CTL_INF("Executable path: " << buffer);
return std::filesystem::path{buffer}.parent_path();
} else {
LOG_ERROR << "Failed to get executable path";
CTL_ERR("Failed to get executable path");
return std::filesystem::current_path();
}
#elif defined(__linux__)
char buffer[1024];
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
if (len != -1) {
buffer[len] = '\0';
LOG_INFO << "Executable path: " << buffer;
CTL_INF("Executable path: " << buffer);
return std::filesystem::path{buffer}.parent_path();
} else {
LOG_ERROR << "Failed to get executable path";
CTL_ERR("Failed to get executable path");
return std::filesystem::current_path();
}
#elif defined(_WIN32)
Expand Down