-
-
Notifications
You must be signed in to change notification settings - Fork 419
fix: Windows Vulkan runtime dependencies #1046
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
Merged
ndizazzo
merged 5 commits into
codex/issue-653-mi300-utilization
from
codex/issue-1022-windows-vulkan
Jul 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b03e97
Fix Windows Vulkan runtime dependencies
ndizazzo c3588c3
Fix Windows dependency test path
ndizazzo c04245f
Address Windows GPU routing review
ndizazzo 938079d
Normalize verifier path on Windows
ndizazzo 5817676
Use Git Bash in Windows verifier test
ndizazzo 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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| use libloading::Library; | ||
| use std::path::Path; | ||
|
|
||
| #[cfg(target_os = "windows")] | ||
| pub(crate) unsafe fn load(path: &Path) -> Result<Library, libloading::Error> { | ||
| use libloading::os::windows::{LOAD_WITH_ALTERED_SEARCH_PATH, Library as WindowsLibrary}; | ||
|
|
||
| // LoadLibraryExW normally searches the application directory for a | ||
| // dependent DLL, even when the requested DLL has an absolute path. Native | ||
| // runtimes are installed elsewhere, so make the loaded DLL's directory the | ||
| // first dependency search location. | ||
| unsafe { WindowsLibrary::load_with_flags(path, LOAD_WITH_ALTERED_SEARCH_PATH) }.map(Into::into) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "windows"))] | ||
| pub(crate) unsafe fn load(path: &Path) -> Result<Library, libloading::Error> { | ||
| unsafe { Library::new(path) } | ||
| } |
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
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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import importlib.util | ||
| import json | ||
| import os | ||
| import pathlib | ||
| import shutil | ||
| import struct | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
|
|
||
|
|
||
| SCRIPT = pathlib.Path(__file__).parents[1] / "windows-native-runtime-deps.py" | ||
| VERIFY_SCRIPT = pathlib.Path(__file__).parents[1] / "verify-native-runtime-package.sh" | ||
| SPEC = importlib.util.spec_from_file_location("windows_native_runtime_deps", SCRIPT) | ||
| DEPS = importlib.util.module_from_spec(SPEC) | ||
| assert SPEC.loader is not None | ||
| SPEC.loader.exec_module(DEPS) | ||
|
|
||
|
|
||
| def bash_executable() -> str: | ||
| if os.name != "nt": | ||
| return shutil.which("bash") or "bash" | ||
| git = shutil.which("git") | ||
| if git: | ||
| candidate = pathlib.Path(git).parent.parent / "bin" / "bash.exe" | ||
| if candidate.is_file(): | ||
| return str(candidate) | ||
| raise RuntimeError("Git Bash is required for native-runtime verifier tests") | ||
|
|
||
|
|
||
| def write_pe(path: pathlib.Path, imports: list[str]) -> None: | ||
| data = bytearray(0x800) | ||
| data[:2] = b"MZ" | ||
| struct.pack_into("<I", data, 0x3C, 0x80) | ||
| data[0x80:0x84] = b"PE\0\0" | ||
| struct.pack_into("<HHIIIHH", data, 0x84, 0x8664, 1, 0, 0, 0, 0xF0, 0) | ||
| optional = 0x98 | ||
| struct.pack_into("<H", data, optional, 0x20B) | ||
| struct.pack_into("<II", data, optional + 120, 0x1000, (len(imports) + 1) * 20) | ||
| section = optional + 0xF0 | ||
| data[section : section + 8] = b".rdata\0\0" | ||
| struct.pack_into("<IIII", data, section + 8, 0x500, 0x1000, 0x500, 0x200) | ||
| name_offset = 0x300 | ||
| for index, name in enumerate(imports): | ||
| descriptor = 0x200 + index * 20 | ||
| name_rva = 0x1000 + name_offset - 0x200 | ||
| struct.pack_into("<IIIII", data, descriptor, 0, 0, 0, name_rva, 0) | ||
| encoded = name.encode("ascii") + b"\0" | ||
| data[name_offset : name_offset + len(encoded)] = encoded | ||
| name_offset += len(encoded) | ||
| path.write_bytes(data) | ||
|
|
||
|
|
||
| class WindowsNativeRuntimeDepsTests(unittest.TestCase): | ||
| def test_reads_pe_import_table(self): | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| library = pathlib.Path(directory) / "ggml-vulkan.dll" | ||
| write_pe(library, ["KERNEL32.dll", "libstdc++-6.dll"]) | ||
|
|
||
| self.assertEqual( | ||
| DEPS.imported_dlls(library), ["KERNEL32.dll", "libstdc++-6.dll"] | ||
| ) | ||
|
|
||
| def test_collects_mingw_dependency_closure(self): | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| root = pathlib.Path(directory) | ||
| lib_dir = root / "artifact" / "lib" | ||
| search_dir = root / "sdk" / "Bin" | ||
| lib_dir.mkdir(parents=True) | ||
| search_dir.mkdir(parents=True) | ||
| write_pe( | ||
| lib_dir / "ggml-vulkan.dll", | ||
| ["vulkan-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll"], | ||
| ) | ||
| write_pe( | ||
| search_dir / "libstdc++-6.dll", | ||
| ["KERNEL32.dll", "libgcc_s_seh-1.dll"], | ||
| ) | ||
| write_pe(search_dir / "libwinpthread-1.dll", ["KERNEL32.dll"]) | ||
| write_pe(search_dir / "libgcc_s_seh-1.dll", ["KERNEL32.dll"]) | ||
|
|
||
| copied = DEPS.collect_dependencies(lib_dir, [search_dir]) | ||
|
|
||
| self.assertEqual( | ||
| {path.name for path in copied}, | ||
| {"libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll"}, | ||
| ) | ||
| DEPS.verify_dependencies(lib_dir) | ||
|
|
||
| def test_verification_rejects_missing_non_system_dependency(self): | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| lib_dir = pathlib.Path(directory) | ||
| write_pe(lib_dir / "ggml-vulkan.dll", ["libstdc++-6.dll"]) | ||
|
|
||
| with self.assertRaisesRegex(RuntimeError, "libstdc\\+\\+-6.dll"): | ||
| DEPS.verify_dependencies(lib_dir) | ||
|
|
||
| def test_package_verifier_accepts_closed_windows_dependency_graph(self): | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| artifact = pathlib.Path(directory) / "meshllm-native-runtime-windows-x86_64-vulkan" | ||
| lib_dir = artifact / "lib" | ||
| lib_dir.mkdir(parents=True) | ||
| write_pe(lib_dir / "ggml-vulkan.dll", ["vulkan-1.dll", "libstdc++-6.dll"]) | ||
| write_pe(lib_dir / "libstdc++-6.dll", ["KERNEL32.dll"]) | ||
| write_pe(lib_dir / "llama.dll", ["ggml-vulkan.dll"]) | ||
| manifest = { | ||
| "runtime": { | ||
| "id": artifact.name, | ||
| "mesh_version": "0.72.1", | ||
| "skippy_abi": "0.1.32", | ||
| "platform": {"os": "windows", "arch": "x86_64"}, | ||
| "backend": {"kind": "vulkan"}, | ||
| "libraries": [ | ||
| "lib/ggml-vulkan.dll", | ||
| "lib/libstdc++-6.dll", | ||
| "lib/llama.dll", | ||
| ], | ||
| } | ||
| } | ||
| (artifact / "manifest.json").write_text(json.dumps(manifest), encoding="utf-8") | ||
|
|
||
| result = subprocess.run( | ||
| [bash_executable(), VERIFY_SCRIPT.as_posix(), artifact.as_posix()], | ||
| check=False, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| self.assertEqual(result.returncode, 0, result.stdout + result.stderr) | ||
| self.assertIn("verified native runtime artifact", result.stdout) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.