diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index e2233c036..4391d3a90 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -51,7 +51,7 @@ jobs: uses: actions/checkout@v3 with: submodules: recursive - + - name: Install choco on Windows if: runner.os == 'Windows' run: | diff --git a/engine/main.cc b/engine/main.cc index cf123e16a..272aa7bb8 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -1,6 +1,7 @@ #include #include #include // 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" @@ -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 // for dirname() @@ -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); @@ -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; @@ -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); diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index 1e5c522e0..40d0df37f 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -27,10 +27,10 @@ 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__) @@ -38,10 +38,10 @@ inline std::filesystem::path GetExecutableFolderContainerPath() { 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)