Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scripts/package-native-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ if [[ "$runtime_os" == "windows" ]]; then
for library in "${runtime_libraries[@]}"; do
dependency_args+=(--search-dir "$(dirname "$library")")
done
# The Vulkan SDK can contain an older MinGW runtime. Let the dependency
# resolver discover the compiler runtime before searching SDK directories.
# This also keeps CPU packages self-contained when their DLLs use MinGW.
if [[ "$BACKEND" == "cpu" || "$BACKEND" == "vulkan" ]]; then
mingw_compiler="${MINGW_CXX:-${CXX:-g++}}"
mingw_compiler_path="$(command -v "$mingw_compiler" || true)"
if [[ -n "$mingw_compiler_path" ]]; then
dependency_args+=(--search-dir "$(dirname "$mingw_compiler_path")")
fi
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
for dependency_root in CUDA_PATH ROCM_PATH VULKAN_SDK; do
dependency_dir="${!dependency_root:-}"
if [[ -n "$dependency_dir" ]]; then
Expand Down
33 changes: 33 additions & 0 deletions scripts/tests/test_windows_native_runtime_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import tempfile
import unittest
from unittest import mock


SCRIPT = pathlib.Path(__file__).parents[1] / "windows-native-runtime-deps.py"
Expand Down Expand Up @@ -88,6 +89,38 @@ def test_collects_mingw_dependency_closure(self):
)
DEPS.verify_dependencies(lib_dir)

def test_compiler_runtime_wins_over_vulkan_sdk_runtime(self):
with tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory)
lib_dir = root / "artifact" / "lib"
compiler_dir = root / "mingw" / "bin"
sdk_dir = root / "vulkan" / "Bin"
lib_dir.mkdir(parents=True)
compiler_dir.mkdir(parents=True)
sdk_dir.mkdir(parents=True)
write_pe(lib_dir / "ggml-vulkan.dll", ["libstdc++-6.dll"])
write_pe(compiler_dir / "libstdc++-6.dll", ["KERNEL32.dll"])
write_pe(sdk_dir / "libstdc++-6.dll", ["missing-sdk-runtime.dll"])

with mock.patch.object(
DEPS.shutil, "which", return_value=str(compiler_dir / "g++.exe")
), mock.patch.dict(
DEPS.os.environ,
{
"PATH": str(sdk_dir),
"VULKAN_SDK": str(root / "vulkan"),
},
clear=False,
):
copied = DEPS.collect_dependencies(lib_dir, [])

self.assertEqual([path.name for path in copied], ["libstdc++-6.dll"])
self.assertEqual(
(lib_dir / "libstdc++-6.dll").read_bytes(),
(compiler_dir / "libstdc++-6.dll").read_bytes(),
)
DEPS.verify_dependencies(lib_dir)

def test_verification_rejects_missing_non_system_dependency(self):
with tempfile.TemporaryDirectory() as directory:
lib_dir = pathlib.Path(directory)
Expand Down
15 changes: 10 additions & 5 deletions scripts/windows-native-runtime-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,21 @@ def is_host_dll(name: str) -> bool:

def default_search_dirs() -> list[pathlib.Path]:
candidates: list[pathlib.Path] = []
vulkan_sdk = os.environ.get("VULKAN_SDK")
if vulkan_sdk:
candidates.extend(
[pathlib.Path(vulkan_sdk) / "Bin", pathlib.Path(vulkan_sdk) / "Bin32"]
)
for compiler in ("g++", "gcc"):
compiler_path = shutil.which(compiler)
if compiler_path:
candidates.append(pathlib.Path(compiler_path).parent)
break
candidates.extend(
pathlib.Path(entry)
for entry in os.environ.get("PATH", "").split(os.pathsep)
if entry
)
vulkan_sdk = os.environ.get("VULKAN_SDK")
if vulkan_sdk:
candidates.extend(
[pathlib.Path(vulkan_sdk) / "Bin", pathlib.Path(vulkan_sdk) / "Bin32"]
)
return candidates


Expand Down
Loading