@@ -345,22 +345,28 @@ def inplace_dir(self, installer: "InstallerBuildExt") -> Path:
345
345
class BuiltExtension (_BaseExtension ):
346
346
"""An extension that installs a python extension that was built by cmake."""
347
347
348
- def __init__ (self , src : str , modpath : str ):
348
+ def __init__ (self , src : str , modpath : str , src_dir : Optional [ str ] = None ):
349
349
"""Initializes a BuiltExtension.
350
350
351
351
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`,
355
- this class will also look for similarly-named `.dylib` files.
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`,
356
359
modpath: The dotted path of the python module that maps to the
357
360
extension.
358
361
"""
359
362
assert (
360
363
"/" not in modpath
361
364
), f"modpath must be a dotted python module path: saw '{ modpath } '"
365
+ full_src = src
366
+ if src_dir is not None :
367
+ full_src = os .path .join (src_dir , src )
362
368
# This is a real extension, so use the modpath as the name.
363
- super ().__init__ (src = f"%CMAKE_CACHE_DIR%/{ src } " , dst = modpath , name = modpath )
369
+ super ().__init__ (src = f"%CMAKE_CACHE_DIR%/{ full_src } " , dst = modpath , name = modpath )
364
370
365
371
def src_path (self , installer : "InstallerBuildExt" ) -> Path :
366
372
"""Returns the path to the source file, resolving globs.
@@ -784,7 +790,9 @@ def get_ext_modules() -> List[Extension]:
784
790
# portable kernels, and a selection of backends. This lets users
785
791
# load and execute .pte files from python.
786
792
BuiltExtension (
787
- "_portable_lib.*" , "executorch.extension.pybindings._portable_lib"
793
+ src = "_portable_lib.cp*" ,
794
+ modpath = "executorch.extension.pybindings._portable_lib" ,
795
+ src_dir = "%BUILD_TYPE%/" ,
788
796
)
789
797
)
790
798
if ShouldBuild .training ():
0 commit comments