code: def build_extension(self, ext):
      # Since two library files (libtorchaudio and _torchaudio) need to be
      # recognized by setuptools, we instantiate `Extension` twice. (see `get_ext_modules`)
      # This leads to the situation where this `build_extension` method is called twice.
      # However, the following `cmake` command will build all of them at the same time,
      # so, we do not need to perform `cmake` twice.
      # Therefore we call `cmake` only for `torchaudio._torchaudio`.
      if ext.name != "torchaudio.lib.libtorchaudio":
          return
  
      # Note:
      # the last part "lib" does not really matter. We want to get the full path of
      # the root build directory. Passing "torchaudio" will be interpreted as
      # `torchaudio.[so|dylib|pyd]`, so we need something `torchaudio.foo`, that is
      # interpreted as `torchaudio/foo.so` then use dirname to get the `torchaudio`
      # directory.
      extdir = os.path.abspath(
          os.path.dirname(self.get_ext_fullpath("foo"))
      )
  
      # required for auto-detection of auxiliary "native" libs
      if not extdir.endswith(os.path.sep):
          extdir += os.path.sep
  
      cfg = "Debug" if self.debug else "Release"
  
      cmake_args = [
          f"-DCMAKE_BUILD_TYPE={cfg}",
          f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}",
          f"-DCMAKE_INSTALL_PREFIX={extdir}",
          "-DCMAKE_VERBOSE_MAKEFILE=ON",
          f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
          f"-DBUILD_CPP_TEST={'ON' if _BUILD_CPP_TEST else 'OFF'}",
          f"-DBUILD_SOX:BOOL={'ON' if _BUILD_SOX else 'OFF'}",
          f"-DBUILD_RIR:BOOL={'ON' if _BUILD_RIR else 'OFF'}",
          f"-DBUILD_RNNT:BOOL={'ON' if _BUILD_RNNT else 'OFF'}",
          f"-DBUILD_ALIGN:BOOL={'ON' if _BUILD_ALIGN else 'OFF'}",
          f"-DBUILD_CUDA_CTC_DECODER:BOOL={'ON' if _BUILD_CUDA_CTC_DECODER else 'OFF'}",
          "-DBUILD_TORCHAUDIO_PYTHON_EXTENSION:BOOL=ON",
          "-DBUILD_TORIO_PYTHON_EXTENSION:BOOL=ON",
          f"-DUSE_ROCM:BOOL={'ON' if _USE_ROCM else 'OFF'}",
          f"-DUSE_CUDA:BOOL={'ON' if _USE_CUDA else 'OFF'}",
          f"-DUSE_OPENMP:BOOL={'ON' if _USE_OPENMP else 'OFF'}",
          f"-DUSE_FFMPEG:BOOL={'ON' if _USE_FFMPEG else 'OFF'}",
      ]
      build_args = ["--target", "install"]
      # Pass CUDA architecture to cmake
      if _TORCH_CUDA_ARCH_LIST is not None:
          # Convert MAJOR.MINOR[+PTX] list to new style one
          # defined at https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html
          _arches = (
              _TORCH_CUDA_ARCH_LIST.replace(".", "")
              .replace(" ", ";")
              .split(";")
          )
          _arches = [
              arch[:-4] if arch.endswith("+PTX") else f"{arch}-real"
              for arch in _arches
          ]
          cmake_args += [
              f"-DCMAKE_CUDA_ARCHITECTURES={';'.join(_arches)}"
          ]
  
      if platform.system() != "Windows" and CUDA_HOME is not None:
          cmake_args += [
              f"-DCMAKE_CUDA_COMPILER='{CUDA_HOME}/bin/nvcc'"
          ]
          cmake_args += [f"-DCUDA_TOOLKIT_ROOT_DIR='{CUDA_HOME}'"]
  
      # Default to Ninja
      if (
          "CMAKE_GENERATOR" not in os.environ
          or platform.system() == "Windows"
      ):
          cmake_args += ["-GNinja"]
      if platform.system() == "Windows":
          import sys
  
          python_version = sys.version_info
          cmake_args += [
              "-DCMAKE_C_COMPILER=cl",
              "-DCMAKE_CXX_COMPILER=cl",
              f"-DPYTHON_VERSION={python_version.major}.{python_version.minor}",
          ]
  
      # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
      # across all generators.
      if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
          # self.parallel is a Python 3 only way to set parallel jobs by hand
          # using -j in the build_ext call, not supported by pip or PyPA-build.
          if hasattr(self, "parallel") and self.parallel:
              # CMake 3.12+ only.
              build_args += ["-j{}".format(self.parallel)]
  
      if not os.path.exists(self.build_temp):
          os.makedirs(self.build_temp)
  
      subprocess.check_call(
          ["cmake", str(_ROOT_DIR)] + cmake_args, cwd=self.build_temp
      )
      subprocess.check_call(
          ["cmake", "--build", "."] + build_args, cwd=self.build_temp
      )
  
file_path: audio/tools/setup_helpers/extension.py
imports: import distutils.sysconfig
  import os
  import platform
  import subprocess
  from pathlib import Path
  import torch
  from setuptools import Extension
  from setuptools.command.build_ext import build_ext
  from torch.utils.cpp_extension import CUDA_HOME
label_desc: Use image node_id 2 for calling the CMakeBuild obj's underlying member method code with example usage: obj.build_extension(ext) without return types