Skip to content

Commit 64748f5

Browse files
committed
WIP: only build the targets we need
1 parent 97ae340 commit 64748f5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

setup.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,10 @@ def initialize_options(self):
323323
# setuptools/_distutils/command/build.py for the default.
324324
self.build_base = "pip-out"
325325

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)
328330

329331
def run(self):
330332
self.dump_options()
@@ -352,20 +354,28 @@ def run(self):
352354
f"-DCMAKE_BUILD_TYPE={cfg}",
353355
]
354356

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+
357363
if ShouldBuild.aot_util:
358364
cmake_args += [
359365
"-DEXECUTORCH_BUILD_EXTENSION_AOT_UTIL=ON",
360366
]
367+
build_args += ["--target", "aot_util"]
361368
if ShouldBuild.pybindings:
362369
cmake_args += [
363370
"-DEXECUTORCH_BUILD_PYBIND=ON",
364371
]
372+
build_args += ["--target", "portable_lib"]
365373
if ShouldBuild.xnnpack:
366374
cmake_args += [
367375
"-DEXECUTORCH_BUILD_XNNPACK=ON",
368376
]
377+
# No target needed; the cmake arg will link xnnpack
378+
# into the portable_lib target.
369379
# TODO(dbort): Add MPS/CoreML backends when building on macos.
370380

371381
# Allow adding extra cmake args through the environment. Used by some
@@ -374,8 +384,6 @@ def run(self):
374384
if "CMAKE_ARGS" in os.environ:
375385
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
376386

377-
build_args = [f"-j{self.parallel}"]
378-
379387
# Put the cmake cache under the temp directory, like
380388
# "pip-out/temp.<plat>/cmake-out".
381389
cmake_cache_dir = os.path.join(repo_root, self.build_temp, "cmake-out")

0 commit comments

Comments
 (0)