Skip to content

Commit 8cb5749

Browse files
committed
Add pybind extension to the dll search path on Windows
1 parent 90ee347 commit 8cb5749

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

extension/pybindings/portable_lib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
This API is experimental and subject to change without notice.
1414
"""
1515

16+
import os
17+
import sys
1618
import warnings as _warnings
1719

1820
import executorch.exir._warnings as _exir_warnings
@@ -28,6 +30,13 @@
2830
# dependencies.
2931
import torch as _torch
3032

33+
# Update the DLL search path on Windows. This is the recommended way to handle native
34+
# extensions.
35+
if sys.platform == "win32":
36+
# The extension DLL should be in the same directory as this file.
37+
pybindings_dir = os.path.dirname(__file__)
38+
os.add_dll_directory(pybindings_dir)
39+
3140
# Let users import everything from the C++ _portable_lib extension as if this
3241
# python file defined them. Although we could import these dynamically, it
3342
# wouldn't preserve the static type annotations.

0 commit comments

Comments
 (0)