Skip to content

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time#1652

Open
kkraus14 wants to merge 2 commits intoNVIDIA:mainfrom
kkraus14:kkraus14/defer-cuda-home-to-build-time
Open

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time#1652
kkraus14 wants to merge 2 commits intoNVIDIA:mainfrom
kkraus14:kkraus14/defer-cuda-home-to-build-time

Conversation

@kkraus14
Copy link
Collaborator

Summary

  • Introduces cuda_bindings/build_hooks.py as a custom PEP 517 build backend that defers all CUDA-dependent logic (header parsing, code generation, cythonization) to build_wheel/build_editable
  • Rewrites cuda_bindings/setup.py as a thin shim (matching cuda_core/setup.py) that only provides the ext_modules bridge and parallel build_ext
  • Changes pyproject.toml build-backend from setuptools.build_meta to build_hooks

Metadata queries (uv lock, uv sync, pip install --dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

Follows the same pattern already used by cuda_core/build_hooks.py.

Test plan

  • Verify python -c "import build_hooks" succeeds without CUDA_HOME (confirmed locally)
  • Verify uv lock / uv pip compile works without CUDA_HOME
  • Verify CUDA_HOME=/usr/local/cuda uv build --wheel produces a working wheel
  • Verify pip install -e . with CUDA_HOME set works for editable installs
  • CI wheel builds pass on Linux and Windows

Closes #1635

Made with Cursor

@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 19, 2026

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@kkraus14 kkraus14 marked this pull request as draft February 19, 2026 05:38
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Feb 19, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Move all CUDA-dependent logic (header parsing, code generation,
cythonization) from setup.py into a custom PEP 517 build backend
(build_hooks.py). Metadata queries (uv lock, uv sync, pip install
--dry-run) no longer require CUDA_HOME or CUDA_PATH to be set.

This follows the same pattern already used by cuda_core/build_hooks.py:
- Metadata hooks delegate directly to setuptools
- build_wheel/build_editable defer to _build_cuda_bindings()
- setup.py becomes a thin shim for ext_modules + parallel build_ext

Closes NVIDIA#1635

Co-authored-by: Cursor <cursoragent@cursor.com>
@kkraus14 kkraus14 force-pushed the kkraus14/defer-cuda-home-to-build-time branch from 30954a9 to dc8be9b Compare February 19, 2026 05:46
@kkraus14
Copy link
Collaborator Author

/ok to test

@kkraus14 kkraus14 added the to-be-backported Trigger the bot to raise a backport PR upon merge label Feb 19, 2026
@github-actions
Copy link

@kkraus14 kkraus14 marked this pull request as ready for review February 19, 2026 17:26
@mdboom mdboom added the cuda.bindings Everything related to the cuda.bindings module label Feb 19, 2026
Copy link
Contributor

@mdboom mdboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments, none critical.


if strip and sys.platform == "linux" and "--debug" not in sys.argv:
for ext in extensions:
ext.extra_link_args.append("-Wl,--strip-all")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be less confusing to handle extra_link_args in parallel with extra_compile_args, (there is already a "non debug build" path above) rather than handling it separately here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in be4dedc

ext.extra_link_args.append("-Wl,--strip-all")

# Cythonize
compiler_directives = dict(language_level=3, embedsignature=True, binding=True, freethreading_compatible=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name was less confusing in its old location. But now since it's in a function doing a lot more things, maybe change it to cython_directives?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in be4dedc

- Move extra_link_args (strip) handling alongside extra_compile_args
  in the non-debug build path instead of a separate post-loop
- Rename compiler_directives to cython_directives for clarity
- Restore deprecated PARALLEL_LEVEL env var support in setup.py
  for build_ext parallelism parity with the old code

Co-authored-by: Cursor <cursoragent@cursor.com>
@kkraus14
Copy link
Collaborator Author

/ok to test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module to-be-backported Trigger the bot to raise a backport PR upon merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor cuda-bindings setup.py to defer CUDA_HOME check to build time

2 participants

Comments