Skip to content
Merged
Changes from all commits
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
18 changes: 18 additions & 0 deletions extension/pybindings/portable_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
This API is experimental and subject to change without notice.
"""

import logging
import os
import sys
import warnings as _warnings

import executorch.exir._warnings as _exir_warnings
Expand All @@ -28,6 +31,21 @@
# dependencies.
import torch as _torch

logger = logging.getLogger(__name__)

# Update the DLL search path on Windows. This is the recommended way to handle native
# extensions.
if sys.platform == "win32":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sys.platform.startswith("win"):

so that it can catch "win64" and "windows"

Copy link
Member Author

@GregoryComer GregoryComer Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win32 is actually the stable value for sys.platform for both 32-bit and 64-bit Windows builds. I'm happy to change it, though it seems like direct comparison to "win32" is the idiomatic appoach.

try:
# The extension DLL should be in the same directory as this file.
pybindings_dir = os.path.dirname(os.path.abspath(__file__))
os.add_dll_directory(pybindings_dir)
except Exception as e:
logger.error(
"Failed to add the pybinding extension DLL to the search path. The extension may not work.",
e,
)

# Let users import everything from the C++ _portable_lib extension as if this
# python file defined them. Although we could import these dynamically, it
# wouldn't preserve the static type annotations.
Expand Down
Loading