@@ -225,7 +225,7 @@ def src_path(self, installer: "InstallerBuildExt") -> Path:
225225 self .src = self .src .replace ("%BUILD_TYPE%" , cfg )
226226 else :
227227 # Remove %BUILD_TYPE% from the path.
228- self .src = self .src .replace ("/ %BUILD_TYPE%" , "" )
228+ self .src = self .src .replace ("%BUILD_TYPE%/ " , "" )
229229
230230 # Construct the full source path, resolving globs. If there are no glob
231231 # pattern characters, this will just ensure that the source file exists.
@@ -263,7 +263,7 @@ def __init__(
263263 output is in a subdirectory named after the build type. For single-
264264 config generators (like Makefile Generators or Ninja), this placeholder
265265 will be removed.
266- src_name: The name of the file to install
266+ src_name: The name of the file to install.
267267 dst: The path to install to, relative to the root of the pip
268268 package. If dst ends in "/", it is treated as a directory.
269269 Otherwise it is treated as a filename.
@@ -305,20 +305,25 @@ def dst_path(self, installer: "InstallerBuildExt") -> Path:
305305class BuiltExtension (_BaseExtension ):
306306 """An extension that installs a python extension that was built by cmake."""
307307
308- def __init__ (self , src : str , modpath : str ):
308+ def __init__ (self , src_dir : str , src_name : str , modpath : str ):
309309 """Initializes a BuiltExtension.
310310
311311 Args:
312- src: The path to the file to install (typically a shared library),
313- relative to the cmake-out directory. May be an fnmatch-style
314- glob that matches exactly one file. If the path ends in `.so`,
312+ src_dir: The directory of the file to install, relative to the cmake-out
313+ directory. A placeholder %BUILD_TYPE% will be replaced with the build
314+ type for multi-config generators (like Visual Studio) where the build
315+ output is in a subdirectory named after the build type. For single-
316+ config generators (like Makefile Generators or Ninja), this placeholder
317+ will be removed.
318+ src_name: The name of the file to install. If the path ends in `.so`,
315319 this class will also look for similarly-named `.dylib` files.
316320 modpath: The dotted path of the python module that maps to the
317321 extension.
318322 """
319323 assert (
320324 "/" not in modpath
321325 ), f"modpath must be a dotted python module path: saw '{ modpath } '"
326+ src = os .path .join (src_dir , src_name )
322327 # This is a real extension, so use the modpath as the name.
323328 super ().__init__ (src = src , dst = modpath , name = modpath )
324329
@@ -658,7 +663,9 @@ def get_ext_modules() -> List[Extension]:
658663 # portable kernels, and a selection of backends. This lets users
659664 # load and execute .pte files from python.
660665 BuiltExtension (
661- "_portable_lib.*" , "executorch.extension.pybindings._portable_lib"
666+ src_dir = "%BUILD_TYPE%/" , # Set the src directory based on build configuration for windows.
667+ src_name = "_portable_lib.cp*" , # Rename _portable_lib.* to _portable_lib.cp* to avoid _portable_lib.lib is selected on windows.
668+ modpath = "executorch.extension.pybindings._portable_lib" ,
662669 )
663670 )
664671 if ShouldBuild .llama_custom_ops ():
0 commit comments