Skip to content

Commit 8e644a2

Browse files
committed
automate libzstd.dll bundling in hatch build hook
1 parent 2de0757 commit 8e644a2

3 files changed

Lines changed: 19 additions & 37 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -86,41 +86,6 @@ jobs:
8686
-Dcpp_link_args=-static
8787
run: uv build --wheel --verbose
8888

89-
# HACK: only necessary for `libzstd.dll` for LLVM 17 and above.
90-
- name: Repair Wheel (Copy dependencies)
91-
run: |
92-
WHEEL_FILE=$(ls dist/*.whl | head -n 1)
93-
DLL_PATH=$(uvx delvewheel show "$WHEEL_FILE" --add-path /clang64/bin --include libzstd.dll | grep -oP '\(\K[^)]+')
94-
95-
if [ -z "$DLL_PATH" ]; then
96-
echo "Error: Could not find libzstd.dll path via delvewheel."
97-
exit 1
98-
fi
99-
100-
echo "Found DLL at: $DLL_PATH"
101-
echo "Targeting wheel: $WHEEL_FILE"
102-
103-
mkdir -p wheel_contents
104-
7z x "$WHEEL_FILE" -owheel_contents
105-
106-
TARGET_DIR="wheel_contents/vapoursynth/plugins/akarin"
107-
108-
if [ -d "$TARGET_DIR" ]; then
109-
cp "$DLL_PATH" "$TARGET_DIR/"
110-
echo "Successfully injected libzstd.dll into $TARGET_DIR"
111-
else
112-
echo "Error: Target directory $TARGET_DIR not found in wheel."
113-
exit 1
114-
fi
115-
116-
rm "$WHEEL_FILE"
117-
cd wheel_contents
118-
7z a -tzip "../$WHEEL_FILE" *
119-
cd ..
120-
121-
rm -rf wheel_contents
122-
echo "Wheel successfully rebuilt without delvewheel init-patch."
123-
12489
- name: Upload
12590
uses: actions/upload-artifact@v7.0.1
12691
with:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ pip install vapoursynth-akarin
211211
```
212212

213213
> [!NOTE]
214-
> When building with LLVM 17 or newer, the plugin will depend on `libzstd.dll`.
215-
> You may need to manually copy this DLL from your MSYS2 installation (`/clang64/bin/libzstd.dll`) to the plugin directory if it is not already in your PATH.
214+
> When building with LLVM 17 or newer, the plugin depends on `libzstd.dll`.
215+
> The wheel build process (via `uv build`) automatically bundles this DLL from your MSYS2 environment if it is found in your PATH.
216216
217217
### Linux & macOS
218218

hatch_build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,22 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
3131
if file_path.is_file() and file_path.suffix in [".dll", ".so", ".dylib"]:
3232
shutil.copy2(file_path, self.target_dir)
3333

34+
if sys.platform == "win32":
35+
dll_path = shutil.which("libzstd.dll")
36+
37+
if not dll_path:
38+
for prefix in [os.getenv("MSYSTEM_PREFIX"), "C:/msys64/clang64", "C:/msys64/ucrt64"]:
39+
if not prefix:
40+
continue
41+
if (candidate := Path(prefix) / "bin" / "libzstd.dll").exists():
42+
dll_path = candidate
43+
break
44+
45+
if dll_path:
46+
shutil.copy2(dll_path, self.target_dir)
47+
print(f"Bundled dependency: {dll_path}", file=sys.stderr)
48+
else:
49+
print("Warning: Could not find libzstd.dll in PATH or common MSYS2 locations.", file=sys.stderr)
50+
3451
def finalize(self, version: str, build_data: dict[str, Any], artifact_path: str) -> None:
3552
shutil.rmtree(self.target_dir.parent, ignore_errors=True)

0 commit comments

Comments
 (0)