@@ -323,8 +323,10 @@ def initialize_options(self):
323
323
# setuptools/_distutils/command/build.py for the default.
324
324
self .build_base = "pip-out"
325
325
326
- # Default to 9 jobs, but allow overriding through the environment.
327
- self .parallel = os .environ .get ("CMAKE_BUILD_PARALLEL_LEVEL" , "9" )
326
+ # Default build parallelism based on number of cores, but allow
327
+ # overriding through the environment.
328
+ default_parallel = str (os .cpu_count () - 1 )
329
+ self .parallel = os .environ .get ("CMAKE_BUILD_PARALLEL_LEVEL" , default_parallel )
328
330
329
331
def run (self ):
330
332
self .dump_options ()
@@ -352,20 +354,28 @@ def run(self):
352
354
f"-DCMAKE_BUILD_TYPE={ cfg } " ,
353
355
]
354
356
355
- # TODO(dbort): This block should also assemble the list of targets to
356
- # build so we only build what we need.
357
+ build_args = [f"-j{ self .parallel } " ]
358
+
359
+ # TODO(dbort): Try to manage these targets and the cmake args from the
360
+ # extension entries themselves instead of hard-coding them here.
361
+ build_args += ["--target" , "flatc" ]
362
+
357
363
if ShouldBuild .aot_util :
358
364
cmake_args += [
359
365
"-DEXECUTORCH_BUILD_EXTENSION_AOT_UTIL=ON" ,
360
366
]
367
+ build_args += ["--target" , "aot_util" ]
361
368
if ShouldBuild .pybindings :
362
369
cmake_args += [
363
370
"-DEXECUTORCH_BUILD_PYBIND=ON" ,
364
371
]
372
+ build_args += ["--target" , "portable_lib" ]
365
373
if ShouldBuild .xnnpack :
366
374
cmake_args += [
367
375
"-DEXECUTORCH_BUILD_XNNPACK=ON" ,
368
376
]
377
+ # No target needed; the cmake arg will link xnnpack
378
+ # into the portable_lib target.
369
379
# TODO(dbort): Add MPS/CoreML backends when building on macos.
370
380
371
381
# Allow adding extra cmake args through the environment. Used by some
@@ -374,8 +384,6 @@ def run(self):
374
384
if "CMAKE_ARGS" in os .environ :
375
385
cmake_args += [item for item in os .environ ["CMAKE_ARGS" ].split (" " ) if item ]
376
386
377
- build_args = [f"-j{ self .parallel } " ]
378
-
379
387
# Put the cmake cache under the temp directory, like
380
388
# "pip-out/temp.<plat>/cmake-out".
381
389
cmake_cache_dir = os .path .join (repo_root , self .build_temp , "cmake-out" )
0 commit comments