Skip to content

Commit

Permalink
[torchcodec] Pass in CMAKE_BUILD_TYPE from the environment if it is set
Browse files Browse the repository at this point in the history
Summary:
Before this diff we could choose a Debug vs. Release cmake build by passing a flag to setup.py CLI.

In modern python projects setup.py is not supposed to be used from the CLI -- pip is used.

So in order to pass in the build type to cmake we use an env var.

Cmake itself does accept the environment variable in addiion to the flag for CMAKE_BUILD_TYPE. The reason we get the env var in setup.py and pass it down to cmake manually is we want to make sure Release is the default.

By default CMAKE_BUILD_TYPE is set to nothing, which is different from "Debug" or "Release":

https://cmake.org/cmake/help/v3.22/manual/cmake-buildsystem.7.html#default-and-custom-configurations

> The default value will often be none of the above standard configurations and will instead be an empty string. A common misunderstanding is that this is the same as Debug, but that is not the case. Users should always explicitly specify the build type instead to avoid this common problem.

Reviewed By: NicolasHug

Differential Revision: D58730309

fbshipit-source-id: fcd7fe1e1f17a9d45dc9da2efefa00af4fd29b41
  • Loading branch information
ahmadsharif1 authored and facebook-github-bot committed Jun 18, 2024
1 parent 8030065 commit 7c72351
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ def build_extension(self, ext):
def _build_all_extensions_with_cmake(self):
# Note that self.debug is True when you invoke setup.py like this:
# python setup.py build_ext --debug install
build_type = "Debug" if self.debug else "Release"
torch_dir = Path(torch.utils.cmake_prefix_path) / "Torch"
cmake_build_type = os.environ.get("CMAKE_BUILD_TYPE", "Release")
cmake_args = [
f"-DCMAKE_INSTALL_PREFIX={self._install_prefix}",
f"-DTorch_DIR={torch_dir}",
"-DCMAKE_VERBOSE_MAKEFILE=ON",
f"-DCMAKE_BUILD_TYPE={build_type}",
f"-DCMAKE_BUILD_TYPE={cmake_build_type}",
]

Path(self.build_temp).mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit 7c72351

Please sign in to comment.