Skip to content

Add Windows runtime DLL bundling to PostBuildSteps - #180238

Closed
zklaus wants to merge 31 commits into
gh/zklaus/44/basefrom
gh/zklaus/44/head
Closed

zklaus wants to merge 31 commits into
gh/zklaus/44/basefrom
gh/zklaus/44/head

Conversation

@zklaus

@zklaus zklaus commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with Claude Code

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180238

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (3 Unrelated Failures)

As of commit 97e8259 with merge base bef98a5 (image):

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.

zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 13, 2026
Install the _C.lib export library and bundle runtime DLLs (OpenMP,
libuv, CUDA) into the wheel on Windows. Replaces the equivalent
setup.py logic for _C.lib and the CI copy.bat/copy_cpu.bat scripts
for runtime DLLs.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: e28eab9
Pull-Request: pytorch#180238
@zklaus
zklaus marked this pull request as ready for review April 14, 2026 18:30
@zklaus zklaus added ciflow/binaries Trigger all binary build and upload jobs on the PR release notes: releng release notes category labels Apr 14, 2026
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 15, 2026
Install the _C.lib export library and bundle runtime DLLs (OpenMP,
libuv, CUDA) into the wheel on Windows. Replaces the equivalent
setup.py logic for _C.lib and the CI copy.bat/copy_cpu.bat scripts
for runtime DLLs.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: e28eab9
Pull-Request: pytorch#180238
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 17, 2026
Install the _C.lib export library and bundle runtime DLLs (OpenMP,
libuv, CUDA) into the wheel on Windows. Replaces the equivalent
setup.py logic for _C.lib and the CI copy.bat/copy_cpu.bat scripts
for runtime DLLs.

Co-Generated with [Claude Code](https://claude.com/claude-code)


ghstack-source-id: e28eab9
Pull-Request: pytorch#180238
zklaus added 3 commits April 20, 2026 13:41
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
pytorchmergebot added a commit that referenced this pull request May 13, 2026
This reverts commit a938856.

Reverted #180238 on behalf of https://github.com/huydhn due to Sorry for reverting your change but another dynamo test failure shows up ([comment](#180237 (comment)))
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@zklaus your PR has been reverted as part of the stack under #180237.

[ghstack-poisoned]
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

Co-Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…80238)"

This reverts commit 1e2a0b0.

Reverted pytorch#180238 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180237 (comment)))
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…80238)"

This reverts commit a938856.

Reverted pytorch#180238 on behalf of https://github.com/huydhn due to Sorry for reverting your change but another dynamo test failure shows up ([comment](pytorch#180237 (comment)))
@zklaus

zklaus commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the gh/zklaus/44/head branch June 16, 2026 02:27
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

Co-Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

Co-Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…80238)"

This reverts commit 1e2a0b0.

Reverted pytorch#180238 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180237 (comment)))
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#183700, pytorch#180237
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

Co-Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…80238)"

This reverts commit 1e2a0b0.

Reverted pytorch#180238 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180237 (comment)))
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#183700, pytorch#180237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: releng release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants