Skip to content

Commit b14e4dd

Browse files
python3kgaeSamGondelman
authored andcommitted
[Build] Support windows for pybindings install in setup.py
Set the src directory based on build configuration for windows. Rename _portable_lib.* to _portable_lib.cp* to avoid _portable_lib.lib is selected on windows. For #4661
1 parent 24671a9 commit b14e4dd

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

setup.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def src_path(self, installer: "InstallerBuildExt") -> Path:
243243
src_path = src_path.replace("%BUILD_TYPE%", cfg)
244244
else:
245245
# Remove %BUILD_TYPE% from the path.
246-
src_path = src_path.replace("/%BUILD_TYPE%", "")
246+
src_path = src_path.replace("%BUILD_TYPE%/", "")
247247

248248
# Construct the full source path, resolving globs. If there are no glob
249249
# pattern characters, this will just ensure that the source file exists.
@@ -291,7 +291,7 @@ def __init__(
291291
output is in a subdirectory named after the build type. For single-
292292
config generators (like Makefile Generators or Ninja), this placeholder
293293
will be removed.
294-
src_name: The name of the file to install
294+
src_name: The name of the file to install.
295295
dst: The path to install to, relative to the root of the pip
296296
package. If dst ends in "/", it is treated as a directory.
297297
Otherwise it is treated as a filename.
@@ -345,20 +345,25 @@ def inplace_dir(self, installer: "InstallerBuildExt") -> Path:
345345
class BuiltExtension(_BaseExtension):
346346
"""An extension that installs a python extension that was built by cmake."""
347347

348-
def __init__(self, src: str, modpath: str):
348+
def __init__(self, src_dir: str, src_name: str, modpath: str):
349349
"""Initializes a BuiltExtension.
350350
351351
Args:
352-
src: The path to the file to install (typically a shared library),
353-
relative to the cmake-out directory. May be an fnmatch-style
354-
glob that matches exactly one file. If the path ends in `.so`,
352+
src_dir: The directory of the file to install, relative to the cmake-out
353+
directory. A placeholder %BUILD_TYPE% will be replaced with the build
354+
type for multi-config generators (like Visual Studio) where the build
355+
output is in a subdirectory named after the build type. For single-
356+
config generators (like Makefile Generators or Ninja), this placeholder
357+
will be removed.
358+
src_name: The name of the file to install. If the path ends in `.so`,
355359
this class will also look for similarly-named `.dylib` files.
356360
modpath: The dotted path of the python module that maps to the
357361
extension.
358362
"""
359363
assert (
360364
"/" not in modpath
361365
), f"modpath must be a dotted python module path: saw '{modpath}'"
366+
src = os.path.join(src_dir, src_name)
362367
# This is a real extension, so use the modpath as the name.
363368
super().__init__(src=f"%CMAKE_CACHE_DIR%/{src}", dst=modpath, name=modpath)
364369

@@ -783,7 +788,9 @@ def get_ext_modules() -> List[Extension]:
783788
# portable kernels, and a selection of backends. This lets users
784789
# load and execute .pte files from python.
785790
BuiltExtension(
786-
"_portable_lib.*", "executorch.extension.pybindings._portable_lib"
791+
src_dir="%BUILD_TYPE%/",
792+
src_name="_portable_lib.cp*",
793+
modpath="executorch.extension.pybindings._portable_lib",
787794
)
788795
)
789796
if ShouldBuild.training():

0 commit comments

Comments
 (0)