| 144 | } |
| 145 | |
| 146 | static void add_dll_directories() { |
| 147 | #ifdef _WIN32 |
| 148 | // Python 3.8+ on Windows requires os.add_dll_directory() for DLL loading |
| 149 | // First add the executable directory using C++ (more reliable) |
| 150 | const auto exe_dir = lfs::core::getExecutableDir(); |
| 151 | const auto exe_dir_str = lfs::core::path_to_utf8(exe_dir); |
| 152 | |
| 153 | std::string add_dll_code = std::format(R"( |
| 154 | import os |
| 155 | def _add_dll_dirs(): |
| 156 | dirs_to_add = [ |
| 157 | r'{}', # Executable directory |
| 158 | ] |
| 159 | # Also add CUDA path if available |
| 160 | cuda_path = os.environ.get('CUDA_PATH') |
| 161 | if cuda_path: |
| 162 | dirs_to_add.append(os.path.join(cuda_path, 'bin')) |
| 163 | |
| 164 | # Add vcpkg bin if it exists |
| 165 | vcpkg_bin = os.path.join(r'{}', 'vcpkg_installed', 'x64-windows', 'bin') |
| 166 | if os.path.isdir(vcpkg_bin): |
| 167 | dirs_to_add.append(vcpkg_bin) |
| 168 | |
| 169 | for d in dirs_to_add: |
| 170 | if os.path.isdir(d): |
| 171 | try: |
| 172 | os.add_dll_directory(d) |
| 173 | print(f'[DLL] Added: {{d}}') |
| 174 | except Exception as e: |
| 175 | print(f'[DLL] Failed to add {{d}}: {{e}}') |
| 176 | _add_dll_dirs() |
| 177 | )", |
| 178 | exe_dir_str, exe_dir_str); |
| 179 | |
| 180 | PyRun_SimpleString(add_dll_code.c_str()); |
| 181 | LOG_INFO("Windows DLL directories configured for: {}", exe_dir_str); |
| 182 | #endif |
| 183 | } |
| 184 | |
| 185 | namespace { |
| 186 | bool env_flag_enabled(const char* name, const bool default_value) { |
no test coverage detected