66
77#include < nlohmann/json.hpp>
88
9+ #include < climits>
910#include < cstdlib>
11+ #include < cstdint>
1012#include < filesystem>
1113#include < fstream>
1214#include < stdexcept>
2022# define NOMINMAX
2123# endif
2224# include < windows.h>
25+ #elif defined(__APPLE__)
26+ # include < mach-o/dyld.h>
2327#else
2428# include < unistd.h>
2529#endif
@@ -43,7 +47,7 @@ static std::string detect_llama_server_binary() {
4347
4448 std::filesystem::path path (buffer.begin (), buffer.begin () + static_cast <std::ptrdiff_t >(len));
4549 return (path.parent_path () / " llama-server.exe" ).string ();
46- #else
50+ #elif defined(__linux__)
4751 std::vector<char > buffer (1024 );
4852 while (true ) {
4953 ssize_t len = readlink (" /proc/self/exe" , buffer.data (), buffer.size () - 1 );
@@ -59,6 +63,21 @@ static std::string detect_llama_server_binary() {
5963
6064 std::filesystem::path path (buffer.data ());
6165 return (path.parent_path () / " llama-server" ).string ();
66+ #elif defined(__APPLE__)
67+ std::vector<char > buffer (PATH_MAX);
68+ uint32_t size = static_cast <uint32_t >(buffer.size ());
69+ if (_NSGetExecutablePath (buffer.data (), &size) != 0 ) {
70+ buffer.resize (size);
71+ size = static_cast <uint32_t >(buffer.size ());
72+ if (_NSGetExecutablePath (buffer.data (), &size) != 0 ) {
73+ return std::string ();
74+ }
75+ }
76+
77+ std::filesystem::path path (buffer.data ());
78+ return (path.parent_path () / " llama-server" ).string ();
79+ #else
80+ return std::string ();
6281#endif
6382}
6483
@@ -339,11 +358,6 @@ RouterConfig load_config(const std::string & path) {
339358 if (spawn.command .empty ()) {
340359 throw std::runtime_error (" spawn command missing for model: " + model.name );
341360 }
342-
343- const std::string & cmd = spawn.command .front ();
344- if (!cmd.empty () && cmd.find (' /' ) != std::string::npos && !std::filesystem::exists (cmd, ec)) {
345- throw std::runtime_error (" spawn command not executable: " + cmd);
346- }
347361 }
348362
349363 if (rescan_result.added > 0 || rescan_result.removed > 0 ) {
0 commit comments