[build] Change --cmake{,-only} arguments to envvars to support modern Python build frontend (#156045)

See also:

- #156029
- #156027

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156045
Approved by: https://github.com/ezyang
ghstack dependencies: #156040, #156041
This commit is contained in:
Xuehai Pan
2025-06-16 22:37:05 +08:00
committed by PyTorch MergeBot
parent 57084ca846
commit 1cce73b5f4
9 changed files with 21 additions and 13 deletions

View File

@ -151,7 +151,7 @@ if [[ "$USE_SPLIT_BUILD" == "true" ]]; then
BUILD_LIBTORCH_WHL=0 BUILD_PYTHON_ONLY=1 \
BUILD_LIBTORCH_CPU_WITH_DEBUG=$BUILD_DEBUG_INFO \
USE_NCCL=${USE_NCCL} USE_RCCL=${USE_RCCL} USE_KINETO=${USE_KINETO} \
python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR --cmake
CMAKE_FRESH=1 python setup.py bdist_wheel -d /tmp/$WHEELHOUSE_DIR
echo "Finished setup.py bdist_wheel for split build (BUILD_PYTHON_ONLY)"
else
time CMAKE_ARGS=${CMAKE_ARGS[@]} \

View File

@ -206,7 +206,7 @@ if [[ "$USE_SPLIT_BUILD" == "true" ]]; then
BUILD_LIBTORCH_WHL=1 BUILD_PYTHON_ONLY=0 python setup.py bdist_wheel -d "$whl_tmp_dir"
echo "Finished setup.py bdist_wheel for split build (BUILD_LIBTORCH_WHL)"
echo "Calling setup.py bdist_wheel for split build (BUILD_PYTHON_ONLY)"
BUILD_PYTHON_ONLY=1 BUILD_LIBTORCH_WHL=0 python setup.py bdist_wheel -d "$whl_tmp_dir" --cmake
BUILD_LIBTORCH_WHL=0 BUILD_PYTHON_ONLY=1 CMAKE_FRESH=1 python setup.py bdist_wheel -d "$whl_tmp_dir"
echo "Finished setup.py bdist_wheel for split build (BUILD_PYTHON_ONLY)"
else
python setup.py bdist_wheel -d "$whl_tmp_dir"

View File

@ -384,14 +384,14 @@ with such a step.
On Linux
```bash
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
python setup.py build --cmake-only
CMAKE_ONLY=1 python setup.py build
ccmake build # or cmake-gui build
```
On macOS
```bash
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py build --cmake-only
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ CMAKE_ONLY=1 python setup.py build
ccmake build # or cmake-gui build
```

View File

@ -8,7 +8,7 @@ echo "----- USE_MKL=1 -----" >> $OUTFILE
rm -rf build
export USE_MKL=1
python setup.py build --cmake-only
CMAKE_ONLY=1 python setup.py build
ccmake build # or cmake-gui build
python setup.py install

View File

@ -1670,7 +1670,10 @@ if(USE_KINETO)
}" EXCEPTIONS_WORK)
set(CMAKE_REQUIRED_LINK_OPTIONS "")
if(NOT EXCEPTIONS_WORK)
message(FATAL_ERROR "Detected that statically linking against CUPTI causes exceptions to stop working. See https://github.com/pytorch/pytorch/issues/57744 for more details. Perhaps try: USE_CUPTI_SO=1 python setup.py develop --cmake")
message(FATAL_ERROR
"Detected that statically linking against CUPTI causes exceptions to stop working. "
"See https://github.com/pytorch/pytorch/issues/57744 for more details. "
"Perhaps try: USE_CUPTI_SO=1 CMAKE_FRESH=1 python setup.py develop")
endif()
endif()

View File

@ -1162,7 +1162,7 @@ build_update_message = """
To develop locally:
$ python setup.py develop
To force cmake to re-generate native build files (off by default):
$ python setup.py develop --cmake
$ CMAKE_FRESH=1 python setup.py develop
"""

View File

@ -40,8 +40,8 @@ We glob all the test files together in `CMakeLists.txt` so that you don't
have to edit it every time you add a test. Unfortunately, this means that in
order to get the build to pick up your new test file, you need to re-run
cmake:
```
python setup.py build --cmake
```bash
CMAKE_FRESH=1 python setup.py build
```
## How do I run the tests?

View File

@ -31,7 +31,8 @@ def gen_compile_commands() -> None:
os.environ["USE_PRECOMPILED_HEADERS"] = "1"
os.environ["CC"] = "clang"
os.environ["CXX"] = "clang++"
run_cmd([sys.executable, "setup.py", "--cmake-only", "build"])
os.environ["CMAKE_ONLY"] = "1"
run_cmd([sys.executable, "setup.py", "build"])
def run_autogen() -> None:

View File

@ -76,11 +76,15 @@ def split_build(cmd: str) -> None:
extra_env={"BUILD_LIBTORCH_WHL": "1", "BUILD_PYTHON_ONLY": "0"},
)
logger.info("Running %s for torch wheel", cmd)
# NOTE: Passing --cmake is necessary here since the torch frontend has it's
# NOTE: Passing CMAKE_FRESH=1 is necessary here since the torch frontend has it's
# own cmake files that it needs to generate
setup_py(
[cmd, "--cmake"],
extra_env={"BUILD_LIBTORCH_WHL": "0", "BUILD_PYTHON_ONLY": "1"},
[cmd],
extra_env={
"BUILD_LIBTORCH_WHL": "0",
"BUILD_PYTHON_ONLY": "1",
"CMAKE_FRESH": "1",
},
)