Skip to content

Commit abfa212

Browse files
authored
[Build] Allow out-of-tree build with TRITON_BUILD_DIR (#7347)
# Rationale Current Triton uses a fixed build directory `f"cmake.{plat_name}-{sys.implementation.name}-{python_version}"` when installing with `pip install .`, when the same python is used, regardless of the venv target or source code version. This creates conflicts when * Users switches Triton source version but did not clean the build directory. + This is a little hard to notice since most `pip install .` will use a temporary directory to build * Users installing Triton into multiple venv at the same time. With this option, users can specify an out-of-tree build directory to avoid such conflicts. # Alternatives PIP usually uses /tmp/pip-build-env-xxxx/ as the temporary build directory. However I have not found documentation about how to locate this directory in `pip/setuptools`.
1 parent ddacd46 commit abfa212

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

python/build_helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ def get_base_dir():
88
return os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
99

1010

11-
def get_cmake_dir():
11+
def _get_cmake_dir():
1212
plat_name = sysconfig.get_platform()
1313
python_version = sysconfig.get_python_version()
1414
dir_name = f"cmake.{plat_name}-{sys.implementation.name}-{python_version}"
15-
cmake_dir = Path(get_base_dir()) / "build" / dir_name
15+
return Path(get_base_dir()) / "build" / dir_name
16+
17+
18+
def get_cmake_dir():
19+
cmake_dir = os.getenv("TRITON_BUILD_DIR", default=_get_cmake_dir())
20+
cmake_dir = Path(cmake_dir)
1621
cmake_dir.mkdir(parents=True, exist_ok=True)
1722
return cmake_dir

0 commit comments

Comments
 (0)