On Fri, 18 Sep 2026 22:32:18 +0200,
Thomas Frohwein <[email protected]> wrote:
>
> Kirill, ports,
>
> While searching for where getexecpath can/should be used, I found this
> here in libggml. This diff should replicate what is done on other
> platforms by their idiosyncratic methods (_NSGetExecutablePath,
> procfs). It builds, but I don't really know how to use this library.
> Could maybe use a test run.
>
OK kirill@
Also, please backport it to upstream
>
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/devel/libggml/Makefile,v
> diff -u -p -r1.27 Makefile
> --- Makefile 15 Sep 2026 19:31:59 -0000 1.27
> +++ Makefile 18 Sep 2026 20:21:58 -0000
> @@ -4,6 +4,7 @@ GH_ACCOUNT= ggml-org
> GH_PROJECT= ggml
> GH_TAGNAME = v0.24.0
> PKGNAME= lib${DISTNAME}
> +REVISION = 0
>
> SHARED_LIBS += ggml 5.1
> SHARED_LIBS += ggml-base 5.1
> Index: patches/patch-src_ggml-backend-reg_cpp
> ===================================================================
> RCS file: /cvs/ports/devel/libggml/patches/patch-src_ggml-backend-reg_cpp,v
> diff -u -p -r1.8 patch-src_ggml-backend-reg_cpp
> --- patches/patch-src_ggml-backend-reg_cpp 4 Sep 2026 22:27:19 -0000
> 1.8
> +++ patches/patch-src_ggml-backend-reg_cpp 18 Sep 2026 20:21:58 -0000
> @@ -1,13 +1,23 @@
> +getexecpath
> +
> Index: src/ggml-backend-reg.cpp
> --- src/ggml-backend-reg.cpp.orig
> +++ src/ggml-backend-reg.cpp
> -@@ -489,7 +489,9 @@ static ggml_backend_reg_t ggml_backend_load_best(const
> - search_paths.push_back(fs::u8path(GGML_BACKEND_DIR));
> +@@ -456,6 +456,17 @@ static fs::path get_executable_path() {
> + base_path = base_path.substr(0, last_slash);
> + }
> + return base_path + L"\\";
> ++#elif defined(__OpenBSD__)
> ++ std::vector<char> path(PATH_MAX);
> ++ if (getexecpath(path.data(), path.size()) != 0)
> ++ return {};
> ++ std::string base_path(path.data(), path.size());
> ++ // remove executable name
> ++ auto last_slash = base_path.find_last_of('/');
> ++ if (last_slash != std::string::npos) {
> ++ base_path = base_path.substr(0, last_slash);
> ++ }
> ++ return base_path + "/";
> + #else
> + return {};
> #endif
> - // default search paths: executable directory, current directory
> -+#ifndef __OpenBSD__
> - search_paths.push_back(get_executable_path());
> -+#endif
> - std::error_code cwd_ec;
> - const fs::path cwd = fs::current_path(cwd_ec);
> - if (cwd_ec) {
--
wbr, Kirill