99// clang-format on
1010#include " utils/cuda_toolkit_utils.h"
1111#include " utils/engine_matcher_utils.h"
12+ #if defined(_WIN32) || defined(__linux__)
13+ #include " utils/file_manager_utils.h"
14+ #endif
1215
1316namespace commands {
1417
@@ -106,17 +109,46 @@ bool EngineInitCmd::Exec() const {
106109 }}};
107110
108111 DownloadService download_service;
109- download_service.AddDownloadTask (downloadTask, [](const std::string&
110- absolute_path,
111- bool unused) {
112+ download_service.AddDownloadTask (downloadTask, [this ](
113+ const std::string&
114+ absolute_path,
115+ bool unused) {
112116 // try to unzip the downloaded file
113117 std::filesystem::path downloadedEnginePath{absolute_path};
114118 LOG_INFO << " Downloaded engine path: "
115119 << downloadedEnginePath.string ();
116120
117- archive_utils::ExtractArchive (
118- downloadedEnginePath.string (),
119- downloadedEnginePath.parent_path ().parent_path ().string ());
121+ std::filesystem::path extract_path =
122+ downloadedEnginePath.parent_path ().parent_path ();
123+
124+ archive_utils::ExtractArchive (downloadedEnginePath.string (),
125+ extract_path.string ());
126+ #if defined(_WIN32) || defined(__linux__)
127+ // FIXME: hacky try to copy the file. Remove this when we are able to set the library path
128+ auto engine_path = extract_path / engineName_;
129+ LOG_INFO << " Source path: " << engine_path.string ();
130+ auto executable_path =
131+ file_manager_utils::GetExecutableFolderContainerPath ();
132+ for (const auto & entry :
133+ std::filesystem::recursive_directory_iterator (engine_path)) {
134+ if (entry.is_regular_file () &&
135+ entry.path ().extension () != " .gz" ) {
136+ std::filesystem::path relative_path =
137+ std::filesystem::relative (entry.path (), engine_path);
138+ std::filesystem::path destFile =
139+ executable_path / relative_path;
140+
141+ std::filesystem::create_directories (destFile.parent_path ());
142+ std::filesystem::copy_file (
143+ entry.path (), destFile,
144+ std::filesystem::copy_options::overwrite_existing);
145+
146+ std::cout << " Copied: " << entry.path ().filename ().string ()
147+ << " to " << destFile.string () << std::endl;
148+ }
149+ }
150+ std::cout << " DLL copying completed successfully." << std::endl;
151+ #endif
120152
121153 // remove the downloaded file
122154 // TODO(any) Could not delete file on Windows because it is currently hold by httplib(?)
@@ -138,7 +170,7 @@ bool EngineInitCmd::Exec() const {
138170 const std::string cuda_toolkit_file_name = " cuda.tar.gz" ;
139171 const std::string download_id = " cuda" ;
140172
141- // TODO: we don't have API to retrieve list of cuda toolkit dependencies atm
173+ // TODO: we don't have API to retrieve list of cuda toolkit dependencies atm because we hosting it at jan
142174 // will have better logic after https://github.com/janhq/cortex/issues/1046 finished
143175 // for now, assume that we have only 11.7 and 12.4
144176 auto suitable_toolkit_version = " " ;
@@ -147,9 +179,11 @@ bool EngineInitCmd::Exec() const {
147179 suitable_toolkit_version = " 12.4" ;
148180 } else {
149181 // llamacpp
150- if (cuda_driver_version.starts_with (" 11." )) {
182+ auto cuda_driver_semver =
183+ semantic_version_utils::SplitVersion (cuda_driver_version);
184+ if (cuda_driver_semver.major == 11 ) {
151185 suitable_toolkit_version = " 11.7" ;
152- } else if (cuda_driver_version. starts_with ( " 12. " ) ) {
186+ } else if (cuda_driver_semver. major == 12 ) {
153187 suitable_toolkit_version = " 12.4" ;
154188 }
155189 }
0 commit comments