Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/177640
Note: Links to docs will display an error until the docs builds have been completed. ❌ 21 New Failures, 3 Unrelated FailuresAs of commit 931b93c with merge base f063873 ( NEW FAILURES - The following jobs have failed:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b825e1b Pull-Request: pytorch#177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b825e1b Pull-Request: #177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b825e1b Pull-Request: #177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b825e1b Pull-Request: pytorch#177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b825e1b Pull-Request: #177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: b7fb6b7 Pull-Request: pytorch#177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 5c1a291 Pull-Request: pytorch#177640
|
@pytorchbot merge |
|
FWIW, you also can pass custom defines on the CLI using I've had some design ideas for custom CLI flags somewhere, by the way, if it's something you are interested in. You'd be able to make new |
|
Maybe the better way to start this conversion is to go through scikit-build first, because it's way closer to the current setup.py setup and then convert it to the newer core API? |
|
I think you'd want to use the scikit-build-core setuptools plugin. Though I think it would be fine to try to just go all the way to the native one if possible. |
|
Thanks for all the feedback! @malfet, I have refocused this PR to make only the move described in the title. I also have addressed your individual suggestions and put the finding of the Python interpreter as an unconditional @albanD, I have updated the forwarding pattern to include @Skylion007 and @henryiii, I did look at the override mechanism and the
My hope is that mid- to long-term we can do away with environment variables (almost) all-together and instead use the Regarding the possible interims use of scikit-build or the setuptools plugin, I'll follow @henryiii here and say that the price of doing essentially two migrations doesn't seem worthwhile to me at the moment, as the full transition seems very feasible. |
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: 5f3c995 Pull-Request: pytorch#177640
Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Co-Generated with [Claude Code](https://claude.com/claude-code) ghstack-source-id: dcb0361 Pull-Request: pytorch#177640
malfet
left a comment
There was a problem hiding this comment.
LGTM, though I have to say I'm much more comfortable at reading Python files that CMake ones
|
@pytorchmergebot merge -f "looks good to land" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…7640) Migration PR on top of stack: * pytorch#177031 Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#177640 Approved by: https://github.com/atalman, https://github.com/malfet
…takes effect CMAKE_SYSTEM_NAME/CMAKE_SYSTEM_PROCESSOR must be set before project() for CMake to enter cross-compile mode. Since pytorch#177640 moved env-var forwarding into cmake/EnvVarForwarding.cmake (included after project(), skipping already-defined vars), the target values were dropped and CMAKE_SYSTEM_PROCESSOR stayed at the x86 host value -- so arch guards (e.g. NNPACK) selected x86 kernels for riscv64. Forward the toolchain-determining vars before project() to restore correct cross configuration.
…7640) Migration PR on top of stack: * pytorch#177031 Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#177640 Approved by: https://github.com/atalman, https://github.com/malfet
Fixes a cross-compilation regression: target `CMAKE_SYSTEM_NAME` / `CMAKE_SYSTEM_PROCESSOR` passed via the environment are silently dropped, so the build configures for the host architecture. ## Root cause CMake requires `CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` to be set **before** `project()` in order to enter cross-compile mode and report the target architecture. #177640 moved environment variable handling out of `setup.py` into `cmake/EnvVarForwarding.cmake`. That file is included at `CMakeLists.txt:24`, which is **after** `project(Torch CXX C)` at `CMakeLists.txt:13`. It forwards a variable only when it is not already defined (`EnvVarForwarding.cmake:61,68`): ```cmake if(DEFINED ENV{${_var}} AND NOT DEFINED ${_var}) ``` By line 24 `project()` has already defined the toolchain variables to their **host** values, so the guard skips them and the target values from the environment are lost. Architecture guards downstream (for example the `{Q,X}NNPACK` selection in `cmake/Dependencies.cmake`) then evaluate against the host and build host kernels while cross-compiling. Before #177640 these were passed as `-D` arguments from `setup.py`, which took effect at `project()` time. This restores that behavior. ## Why it went unnoticed This only affects **true** cross-compilation. Architectures that build natively under emulation never rely on the forwarded triplet, so their CI stays green. ## Reproduction Minimal, isolated, mirroring the include order and the skip-if-defined guard. Host is `arm64`, environment sets `CMAKE_SYSTEM_PROCESSOR=riscv64 CMAKE_SYSTEM_NAME=Linux`: | forwarding position | `CMAKE_SYSTEM_PROCESSOR` | `CMAKE_CROSSCOMPILING` | | --- | --- | --- | | after `project()` (current) | `arm64` (env dropped) | `FALSE` | | before `project()` (this PR) | `riscv64` | `TRUE` | | before `project()`, no env set | `arm64` | `FALSE` | ## The change Forward only the toolchain-determining variables before `project()`. Every assignment is guarded by `DEFINED ENV{...} AND NOT DEFINED ...`, so this is a **no-op for native builds** (third row above) and does not override anything already passed via `-D` or a toolchain file. `EnvVarForwarding.cmake` keeps handling everything else, unchanged. ## Validation Verified against current `main` that the ordering issue is still present and that no other change forwards these variables before `project()`. Mechanism verified with the isolated reproduction above (cmake 4.3.4), including the native no-op case. Downstream effect previously observed on a riscv64 cross configure: with the fix cmake correctly reports `Target architecture "riscv64" is not supported in {Q/X}NNPACK` and disables them, instead of silently selecting host kernels. A full riscv64 cross build is gated on separate, unrelated blockers, so CI here is the build gate. Refs #180975 Pull Request resolved: #190003 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang via mergedog <[email protected]>
…ch#190003) Fixes a cross-compilation regression: target `CMAKE_SYSTEM_NAME` / `CMAKE_SYSTEM_PROCESSOR` passed via the environment are silently dropped, so the build configures for the host architecture. ## Root cause CMake requires `CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` to be set **before** `project()` in order to enter cross-compile mode and report the target architecture. pytorch#177640 moved environment variable handling out of `setup.py` into `cmake/EnvVarForwarding.cmake`. That file is included at `CMakeLists.txt:24`, which is **after** `project(Torch CXX C)` at `CMakeLists.txt:13`. It forwards a variable only when it is not already defined (`EnvVarForwarding.cmake:61,68`): ```cmake if(DEFINED ENV{${_var}} AND NOT DEFINED ${_var}) ``` By line 24 `project()` has already defined the toolchain variables to their **host** values, so the guard skips them and the target values from the environment are lost. Architecture guards downstream (for example the `{Q,X}NNPACK` selection in `cmake/Dependencies.cmake`) then evaluate against the host and build host kernels while cross-compiling. Before pytorch#177640 these were passed as `-D` arguments from `setup.py`, which took effect at `project()` time. This restores that behavior. ## Why it went unnoticed This only affects **true** cross-compilation. Architectures that build natively under emulation never rely on the forwarded triplet, so their CI stays green. ## Reproduction Minimal, isolated, mirroring the include order and the skip-if-defined guard. Host is `arm64`, environment sets `CMAKE_SYSTEM_PROCESSOR=riscv64 CMAKE_SYSTEM_NAME=Linux`: | forwarding position | `CMAKE_SYSTEM_PROCESSOR` | `CMAKE_CROSSCOMPILING` | | --- | --- | --- | | after `project()` (current) | `arm64` (env dropped) | `FALSE` | | before `project()` (this PR) | `riscv64` | `TRUE` | | before `project()`, no env set | `arm64` | `FALSE` | ## The change Forward only the toolchain-determining variables before `project()`. Every assignment is guarded by `DEFINED ENV{...} AND NOT DEFINED ...`, so this is a **no-op for native builds** (third row above) and does not override anything already passed via `-D` or a toolchain file. `EnvVarForwarding.cmake` keeps handling everything else, unchanged. ## Validation Verified against current `main` that the ordering issue is still present and that no other change forwards these variables before `project()`. Mechanism verified with the isolated reproduction above (cmake 4.3.4), including the native no-op case. Downstream effect previously observed on a riscv64 cross configure: with the fix cmake correctly reports `Target architecture "riscv64" is not supported in {Q/X}NNPACK` and disables them, instead of silently selecting host kernels. A full riscv64 cross build is gated on separate, unrelated blockers, so CI here is the build gate. Refs pytorch#180975 Pull Request resolved: pytorch#190003 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang via mergedog <[email protected]>
…ch#190003) Fixes a cross-compilation regression: target `CMAKE_SYSTEM_NAME` / `CMAKE_SYSTEM_PROCESSOR` passed via the environment are silently dropped, so the build configures for the host architecture. ## Root cause CMake requires `CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` to be set **before** `project()` in order to enter cross-compile mode and report the target architecture. pytorch#177640 moved environment variable handling out of `setup.py` into `cmake/EnvVarForwarding.cmake`. That file is included at `CMakeLists.txt:24`, which is **after** `project(Torch CXX C)` at `CMakeLists.txt:13`. It forwards a variable only when it is not already defined (`EnvVarForwarding.cmake:61,68`): ```cmake if(DEFINED ENV{${_var}} AND NOT DEFINED ${_var}) ``` By line 24 `project()` has already defined the toolchain variables to their **host** values, so the guard skips them and the target values from the environment are lost. Architecture guards downstream (for example the `{Q,X}NNPACK` selection in `cmake/Dependencies.cmake`) then evaluate against the host and build host kernels while cross-compiling. Before pytorch#177640 these were passed as `-D` arguments from `setup.py`, which took effect at `project()` time. This restores that behavior. ## Why it went unnoticed This only affects **true** cross-compilation. Architectures that build natively under emulation never rely on the forwarded triplet, so their CI stays green. ## Reproduction Minimal, isolated, mirroring the include order and the skip-if-defined guard. Host is `arm64`, environment sets `CMAKE_SYSTEM_PROCESSOR=riscv64 CMAKE_SYSTEM_NAME=Linux`: | forwarding position | `CMAKE_SYSTEM_PROCESSOR` | `CMAKE_CROSSCOMPILING` | | --- | --- | --- | | after `project()` (current) | `arm64` (env dropped) | `FALSE` | | before `project()` (this PR) | `riscv64` | `TRUE` | | before `project()`, no env set | `arm64` | `FALSE` | ## The change Forward only the toolchain-determining variables before `project()`. Every assignment is guarded by `DEFINED ENV{...} AND NOT DEFINED ...`, so this is a **no-op for native builds** (third row above) and does not override anything already passed via `-D` or a toolchain file. `EnvVarForwarding.cmake` keeps handling everything else, unchanged. ## Validation Verified against current `main` that the ordering issue is still present and that no other change forwards these variables before `project()`. Mechanism verified with the isolated reproduction above (cmake 4.3.4), including the native no-op case. Downstream effect previously observed on a riscv64 cross configure: with the fix cmake correctly reports `Target architecture "riscv64" is not supported in {Q/X}NNPACK` and disables them, instead of silently selecting host kernels. A full riscv64 cross build is gated on separate, unrelated blockers, so CI here is the build gate. Refs pytorch#180975 Pull Request resolved: pytorch#190003 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang via mergedog <[email protected]>
…7640) Migration PR on top of stack: * pytorch#177031 Forward BUILD_*/USE_*/CMAKE_* and other environment variables to CMake variables, replicating the behavior of setup.py's cmake.py generate method. Also update the project() call to read the version from version.txt and set Torch_SOURCE_DIR for compatibility. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: pytorch#177640 Approved by: https://github.com/atalman, https://github.com/malfet
…ch#190003) Fixes a cross-compilation regression: target `CMAKE_SYSTEM_NAME` / `CMAKE_SYSTEM_PROCESSOR` passed via the environment are silently dropped, so the build configures for the host architecture. ## Root cause CMake requires `CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` to be set **before** `project()` in order to enter cross-compile mode and report the target architecture. pytorch#177640 moved environment variable handling out of `setup.py` into `cmake/EnvVarForwarding.cmake`. That file is included at `CMakeLists.txt:24`, which is **after** `project(Torch CXX C)` at `CMakeLists.txt:13`. It forwards a variable only when it is not already defined (`EnvVarForwarding.cmake:61,68`): ```cmake if(DEFINED ENV{${_var}} AND NOT DEFINED ${_var}) ``` By line 24 `project()` has already defined the toolchain variables to their **host** values, so the guard skips them and the target values from the environment are lost. Architecture guards downstream (for example the `{Q,X}NNPACK` selection in `cmake/Dependencies.cmake`) then evaluate against the host and build host kernels while cross-compiling. Before pytorch#177640 these were passed as `-D` arguments from `setup.py`, which took effect at `project()` time. This restores that behavior. ## Why it went unnoticed This only affects **true** cross-compilation. Architectures that build natively under emulation never rely on the forwarded triplet, so their CI stays green. ## Reproduction Minimal, isolated, mirroring the include order and the skip-if-defined guard. Host is `arm64`, environment sets `CMAKE_SYSTEM_PROCESSOR=riscv64 CMAKE_SYSTEM_NAME=Linux`: | forwarding position | `CMAKE_SYSTEM_PROCESSOR` | `CMAKE_CROSSCOMPILING` | | --- | --- | --- | | after `project()` (current) | `arm64` (env dropped) | `FALSE` | | before `project()` (this PR) | `riscv64` | `TRUE` | | before `project()`, no env set | `arm64` | `FALSE` | ## The change Forward only the toolchain-determining variables before `project()`. Every assignment is guarded by `DEFINED ENV{...} AND NOT DEFINED ...`, so this is a **no-op for native builds** (third row above) and does not override anything already passed via `-D` or a toolchain file. `EnvVarForwarding.cmake` keeps handling everything else, unchanged. ## Validation Verified against current `main` that the ordering issue is still present and that no other change forwards these variables before `project()`. Mechanism verified with the isolated reproduction above (cmake 4.3.4), including the native no-op case. Downstream effect previously observed on a riscv64 cross configure: with the fix cmake correctly reports `Target architecture "riscv64" is not supported in {Q/X}NNPACK` and disables them, instead of silently selecting host kernels. A full riscv64 cross build is gated on separate, unrelated blockers, so CI here is the build gate. Refs pytorch#180975 Pull Request resolved: pytorch#190003 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang via mergedog <[email protected]>
…ch#190003) Fixes a cross-compilation regression: target `CMAKE_SYSTEM_NAME` / `CMAKE_SYSTEM_PROCESSOR` passed via the environment are silently dropped, so the build configures for the host architecture. ## Root cause CMake requires `CMAKE_SYSTEM_NAME` and `CMAKE_SYSTEM_PROCESSOR` to be set **before** `project()` in order to enter cross-compile mode and report the target architecture. pytorch#177640 moved environment variable handling out of `setup.py` into `cmake/EnvVarForwarding.cmake`. That file is included at `CMakeLists.txt:24`, which is **after** `project(Torch CXX C)` at `CMakeLists.txt:13`. It forwards a variable only when it is not already defined (`EnvVarForwarding.cmake:61,68`): ```cmake if(DEFINED ENV{${_var}} AND NOT DEFINED ${_var}) ``` By line 24 `project()` has already defined the toolchain variables to their **host** values, so the guard skips them and the target values from the environment are lost. Architecture guards downstream (for example the `{Q,X}NNPACK` selection in `cmake/Dependencies.cmake`) then evaluate against the host and build host kernels while cross-compiling. Before pytorch#177640 these were passed as `-D` arguments from `setup.py`, which took effect at `project()` time. This restores that behavior. ## Why it went unnoticed This only affects **true** cross-compilation. Architectures that build natively under emulation never rely on the forwarded triplet, so their CI stays green. ## Reproduction Minimal, isolated, mirroring the include order and the skip-if-defined guard. Host is `arm64`, environment sets `CMAKE_SYSTEM_PROCESSOR=riscv64 CMAKE_SYSTEM_NAME=Linux`: | forwarding position | `CMAKE_SYSTEM_PROCESSOR` | `CMAKE_CROSSCOMPILING` | | --- | --- | --- | | after `project()` (current) | `arm64` (env dropped) | `FALSE` | | before `project()` (this PR) | `riscv64` | `TRUE` | | before `project()`, no env set | `arm64` | `FALSE` | ## The change Forward only the toolchain-determining variables before `project()`. Every assignment is guarded by `DEFINED ENV{...} AND NOT DEFINED ...`, so this is a **no-op for native builds** (third row above) and does not override anything already passed via `-D` or a toolchain file. `EnvVarForwarding.cmake` keeps handling everything else, unchanged. ## Validation Verified against current `main` that the ordering issue is still present and that no other change forwards these variables before `project()`. Mechanism verified with the isolated reproduction above (cmake 4.3.4), including the native no-op case. Downstream effect previously observed on a riscv64 cross configure: with the fix cmake correctly reports `Target architecture "riscv64" is not supported in {Q/X}NNPACK` and disables them, instead of silently selecting host kernels. A full riscv64 cross build is gated on separate, unrelated blockers, so CI here is the build gate. Refs pytorch#180975 Pull Request resolved: pytorch#190003 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang via mergedog <[email protected]>
Migration PR on top of stack:
Stack from ghstack (oldest at bottom):
Forward BUILD_/USE_/CMAKE_* and other environment variables to CMake
variables, replicating the behavior of setup.py's cmake.py generate
method.
Also update the project() call to read the version from version.txt
and set Torch_SOURCE_DIR for compatibility.
Co-Generated with Claude Code