From 923a4bbf0344d9298ddbf01ddbae4e0c19dad710 Mon Sep 17 00:00:00 2001 From: Dariusz Trawinski Date: Fri, 24 Jul 2026 01:14:22 +0200 Subject: [PATCH 1/9] add extra env variable to support winget installation --- src/main_windows.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index bee821292d..e1cf29ad98 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "main_windows.hpp" #include "module_names.hpp" @@ -107,8 +108,30 @@ inline std::wstring stringToWstring(const std::string& str, UINT codePage = CP_T return str2; } +static void setOpenvinoTokenizersPathFromMsixDependencies() { + constexpr wchar_t PACKAGE_NAME[] = L"Intel.OpenVINO.Tokenizers.2026.3.0.0"; + constexpr wchar_t TOKENIZERS_RELATIVE_PATH[] = L"\\runtime\\bin\\intel64\\Release\\openvino_tokenizers.dll"; + + try { + winrt::Windows::Foundation::Collections::IVectorView deps = + winrt::Windows::ApplicationModel::Package::Current().Dependencies(); + for (const winrt::Windows::ApplicationModel::Package& dep : deps) { + if (dep.Id().Name() == PACKAGE_NAME) { + const std::wstring dllPath = dep.InstalledLocation().Path().c_str() + std::wstring(TOKENIZERS_RELATIVE_PATH); + SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); + DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from package dependency."); + return; + } + } + } catch (const winrt::hresult_error&) { + // Not all deployments are packaged; keep default behavior when package metadata is unavailable. + } +} + int main_windows(int argc, char** argv) { DEBUG_LOG("Windows Main - Entry"); + setOpenvinoTokenizersPathFromMsixDependencies(); + OvmsWindowsServiceManager::instance().ovmsParams.argc = argc; OvmsWindowsServiceManager::instance().ovmsParams.argv = argv; OvmsWindowsServiceManager::logParameters(argc, argv, "OVMS Main Argument"); From a3e8b97c70b11156b0d655e416608f9fdef07a6c Mon Sep 17 00:00:00 2001 From: Dariusz Trawinski Date: Fri, 24 Jul 2026 10:44:45 +0200 Subject: [PATCH 2/9] fix build --- src/main_windows.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index e1cf29ad98..66c31301b0 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "main_windows.hpp" #include "module_names.hpp" From b61f162ec1a283d1234ce6740e7fa54662abdf2e Mon Sep 17 00:00:00 2001 From: Dariusz Trawinski Date: Fri, 24 Jul 2026 11:04:17 +0200 Subject: [PATCH 3/9] fix build --- src/main_windows.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 66c31301b0..70992767ac 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -31,9 +31,12 @@ #include #include #include +#pragma warning(push) +#pragma warning(disable : 28252 28253 6101) #include #include #include +#pragma warning(pop) #include "main_windows.hpp" #include "module_names.hpp" From da8bb21ff2dbd519c989c45f240dfb9d85989423 Mon Sep 17 00:00:00 2001 From: Dariusz Trawinski Date: Fri, 24 Jul 2026 11:45:17 +0200 Subject: [PATCH 4/9] build --- src/BUILD | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BUILD b/src/BUILD index 0abf61f1f8..de196caaf8 100644 --- a/src/BUILD +++ b/src/BUILD @@ -2082,7 +2082,13 @@ cc_binary( ] + select({ "//conditions:default": [], "//src:windows" : ["main_windows.hpp", "main_windows.cpp",],}), - linkopts = LINKOPTS_ADJUSTED, + linkopts = LINKOPTS_ADJUSTED + select({ + "//conditions:default": [], + "//src:windows" : [ + "runtimeobject.lib", + "oleaut32.lib", + ], + }), copts = COMMON_STATIC_LIBS_COPTS, deps = [ "//src:ovms_lib", From a3fff4da58fea892e46f4de782ffd0705ba09bf5 Mon Sep 17 00:00:00 2001 From: "Trawinski, Dariusz" Date: Fri, 24 Jul 2026 12:21:08 +0200 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/main_windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 70992767ac..498e6d11ad 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -122,7 +122,7 @@ static void setOpenvinoTokenizersPathFromMsixDependencies() { winrt::Windows::ApplicationModel::Package::Current().Dependencies(); for (const winrt::Windows::ApplicationModel::Package& dep : deps) { if (dep.Id().Name() == PACKAGE_NAME) { - const std::wstring dllPath = dep.InstalledLocation().Path().c_str() + std::wstring(TOKENIZERS_RELATIVE_PATH); + const std::wstring dllPath = std::wstring(dep.InstalledLocation().Path().c_str()) + TOKENIZERS_RELATIVE_PATH; SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from package dependency."); return; From 6c41dd6516c13bea491cc639e64f2b5ee5e30ea6 Mon Sep 17 00:00:00 2001 From: Dariusz Trawinski Date: Fri, 24 Jul 2026 15:38:28 +0200 Subject: [PATCH 6/9] review updates --- src/main_windows.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 70992767ac..6db23e0cec 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -33,6 +33,7 @@ #include #pragma warning(push) #pragma warning(disable : 28252 28253 6101) +#include #include #include #include @@ -122,19 +123,21 @@ static void setOpenvinoTokenizersPathFromMsixDependencies() { winrt::Windows::ApplicationModel::Package::Current().Dependencies(); for (const winrt::Windows::ApplicationModel::Package& dep : deps) { if (dep.Id().Name() == PACKAGE_NAME) { - const std::wstring dllPath = dep.InstalledLocation().Path().c_str() + std::wstring(TOKENIZERS_RELATIVE_PATH); + const std::wstring dllPath = std::wstring(dep.InstalledLocation().Path().c_str()) + TOKENIZERS_RELATIVE_PATH; SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from package dependency."); return; } } - } catch (const winrt::hresult_error&) { + } catch (const winrt::hresult_error& ex) { // Not all deployments are packaged; keep default behavior when package metadata is unavailable. + DEBUG_LOG("Failed to resolve Tokenizer dependency. HRESULT: " + std::to_string(ex.code().value) + ", message: " + winrt::to_string(ex.message())); } } int main_windows(int argc, char** argv) { DEBUG_LOG("Windows Main - Entry"); + winrt::init_apartment(); setOpenvinoTokenizersPathFromMsixDependencies(); OvmsWindowsServiceManager::instance().ovmsParams.argc = argc; From e3e12d5b315cadef7b3973f833a49a22bb437b60 Mon Sep 17 00:00:00 2001 From: aanokhov Date: Fri, 24 Jul 2026 16:22:26 +0200 Subject: [PATCH 7/9] Fix WinRT apartment init and missing linker dep for MSIX tokenizers path detection. --- src/BUILD | 1 + src/main_windows.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BUILD b/src/BUILD index 9cc0e6de16..342fd23738 100644 --- a/src/BUILD +++ b/src/BUILD @@ -2087,6 +2087,7 @@ cc_binary( "//src:windows" : [ "runtimeobject.lib", "oleaut32.lib", + "ole32.lib", ], }), copts = COMMON_STATIC_LIBS_COPTS, diff --git a/src/main_windows.cpp b/src/main_windows.cpp index 6db23e0cec..e0e376e276 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -131,13 +131,17 @@ static void setOpenvinoTokenizersPathFromMsixDependencies() { } } catch (const winrt::hresult_error& ex) { // Not all deployments are packaged; keep default behavior when package metadata is unavailable. - DEBUG_LOG("Failed to resolve Tokenizer dependency. HRESULT: " + std::to_string(ex.code().value) + ", message: " + winrt::to_string(ex.message())); + std::ostringstream errMsg; + errMsg << "Failed to resolve Tokenizers MSIX dependency. HRESULT: 0x" << std::hex << std::uppercase + << static_cast(ex.code().value) << ", message: " << winrt::to_string(ex.message()); + DEBUG_LOG(errMsg.str()); } } int main_windows(int argc, char** argv) { DEBUG_LOG("Windows Main - Entry"); - winrt::init_apartment(); + // Multi-threaded apartment: OVMS is a server process with no STA/message-loop dependency. + winrt::init_apartment(winrt::apartment_type::multi_threaded); setOpenvinoTokenizersPathFromMsixDependencies(); OvmsWindowsServiceManager::instance().ovmsParams.argc = argc; From f7296100c3605d1cbf0eae7d39fb3c655f695678 Mon Sep 17 00:00:00 2001 From: aanokhov Date: Fri, 24 Jul 2026 17:46:30 +0200 Subject: [PATCH 8/9] Simplified the patch --- src/main_windows.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index e0e376e276..d01b0515a0 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #pragma warning(pop) @@ -114,21 +115,33 @@ inline std::wstring stringToWstring(const std::string& str, UINT codePage = CP_T return str2; } +// Short-term patch: look up the Tokenizers package directly by its known package name via +// PackageManager, regardless of whether/how it is declared as a dependency in any manifest. +// This avoids relying on Package::Current().Dependencies() at all. +static bool findInstalledPackageByName(const std::wstring& packageName, std::wstring& outInstalledPath) { + winrt::Windows::Management::Deployment::PackageManager packageManager; + for (const winrt::Windows::ApplicationModel::Package& pkg : packageManager.FindPackagesForUser(L"")) { + if (std::wstring(pkg.Id().Name().c_str()) == packageName) { + outInstalledPath = std::wstring(pkg.InstalledLocation().Path().c_str()); + return true; + } + } + return false; +} + static void setOpenvinoTokenizersPathFromMsixDependencies() { constexpr wchar_t PACKAGE_NAME[] = L"Intel.OpenVINO.Tokenizers.2026.3.0.0"; constexpr wchar_t TOKENIZERS_RELATIVE_PATH[] = L"\\runtime\\bin\\intel64\\Release\\openvino_tokenizers.dll"; try { - winrt::Windows::Foundation::Collections::IVectorView deps = - winrt::Windows::ApplicationModel::Package::Current().Dependencies(); - for (const winrt::Windows::ApplicationModel::Package& dep : deps) { - if (dep.Id().Name() == PACKAGE_NAME) { - const std::wstring dllPath = std::wstring(dep.InstalledLocation().Path().c_str()) + TOKENIZERS_RELATIVE_PATH; - SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); - DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from package dependency."); - return; - } + std::wstring installedPath; + if (findInstalledPackageByName(PACKAGE_NAME, installedPath)) { + const std::wstring dllPath = installedPath + TOKENIZERS_RELATIVE_PATH; + SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); + DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from installed package lookup: " << wstringToString(dllPath)); + return; } + DEBUG_LOG("Tokenizers MSIX package '" << wstringToString(std::wstring(PACKAGE_NAME)) << "' not found for current user. Keeping default behavior."); } catch (const winrt::hresult_error& ex) { // Not all deployments are packaged; keep default behavior when package metadata is unavailable. std::ostringstream errMsg; From 770f716cedbf0ffb0a190b47c5e9846b74fcdf18 Mon Sep 17 00:00:00 2001 From: aanokhov Date: Fri, 24 Jul 2026 18:13:18 +0200 Subject: [PATCH 9/9] Added _wputenv_s to ENV be visible for getenv(). --- src/main_windows.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main_windows.cpp b/src/main_windows.cpp index d01b0515a0..fe1925693f 100644 --- a/src/main_windows.cpp +++ b/src/main_windows.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -138,6 +139,7 @@ static void setOpenvinoTokenizersPathFromMsixDependencies() { if (findInstalledPackageByName(PACKAGE_NAME, installedPath)) { const std::wstring dllPath = installedPath + TOKENIZERS_RELATIVE_PATH; SetEnvironmentVariableW(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); + _wputenv_s(L"OPENVINO_TOKENIZERS_PATH_GENAI", dllPath.c_str()); DEBUG_LOG("OPENVINO_TOKENIZERS_PATH_GENAI initialized from installed package lookup: " << wstringToString(dllPath)); return; }