-
Notifications
You must be signed in to change notification settings - Fork 264
add extra env variable to support winget installation #4398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dtrawins
wants to merge
12
commits into
main
Choose a base branch
from
winget_env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−1
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
923a4bb
add extra env variable to support winget installation
dtrawins a3e8b97
fix build
dtrawins b61f162
fix build
dtrawins da8bb21
build
dtrawins a3fff4d
Apply suggestions from code review
dtrawins 4e83238
Merge branch 'main' into winget_env
dtrawins 6c41dd6
review updates
dtrawins 454232d
Merge remote-tracking branch 'origin/main' into winget_env
dtrawins 86d3856
Merge branch 'winget_env' of https://github.com/openvinotoolkit/model…
dtrawins e3e12d5
Fix WinRT apartment init and missing linker dep for MSIX tokenizers p…
artanokhov f729610
Simplified the patch
artanokhov 770f716
Added _wputenv_s to ENV be visible for getenv().
artanokhov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||
| #include <sstream> | ||||||||
| #include <string> | ||||||||
| #include <chrono> | ||||||||
| #include <cstdlib> | ||||||||
| #include <iomanip> | ||||||||
| #include <utility> | ||||||||
| #include <vector> | ||||||||
|
|
@@ -31,6 +32,14 @@ | |||||||
| #include <windows.h> | ||||||||
| #include <tchar.h> | ||||||||
| #include <errors.h> | ||||||||
| #pragma warning(push) | ||||||||
| #pragma warning(disable : 28252 28253 6101) | ||||||||
| #include <winrt/base.h> | ||||||||
| #include <winrt/Windows.ApplicationModel.h> | ||||||||
| #include <winrt/Windows.Foundation.Collections.h> | ||||||||
| #include <winrt/Windows.Management.Deployment.h> | ||||||||
| #include <winrt/Windows.Storage.h> | ||||||||
| #pragma warning(pop) | ||||||||
|
|
||||||||
| #include "main_windows.hpp" | ||||||||
| #include "module_names.hpp" | ||||||||
|
|
@@ -107,8 +116,49 @@ 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 { | ||||||||
| 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()); | ||||||||
| _wputenv_s(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; | ||||||||
| errMsg << "Failed to resolve Tokenizers MSIX dependency. HRESULT: 0x" << std::hex << std::uppercase | ||||||||
| << static_cast<unsigned int>(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"); | ||||||||
| // Multi-threaded apartment: OVMS is a server process with no STA/message-loop dependency. | ||||||||
| winrt::init_apartment(winrt::apartment_type::multi_threaded); | ||||||||
| setOpenvinoTokenizersPathFromMsixDependencies(); | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| OvmsWindowsServiceManager::instance().ovmsParams.argc = argc; | ||||||||
| OvmsWindowsServiceManager::instance().ovmsParams.argv = argv; | ||||||||
| OvmsWindowsServiceManager::logParameters(argc, argv, "OVMS Main Argument"); | ||||||||
|
|
||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.