Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci-pixi-source-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ on:
- "**/pixi.toml"
- "**/pixi.lock"
- "cuda_bindings/build_hooks.py"
- "cuda_bindings/pyproject.toml"
- "cuda_core/build_hooks.py"
- "cuda_core/CMakeLists.txt"
- "cuda_core/pyproject.toml"
- "cuda_bindings/cuda/bindings/**" # generated bindings sources
- "cuda_bindings/tests/cython/**"
- "cuda_core/tests/cython/**"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sdist-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
printf 'cuda-bindings @ %s\n' "${bindings_uri}"
} | tee wheel-constraints/cuda-core.txt

# cuda_core sdist delegates to setuptools (no CTK needed), but
# cuda_core sdist delegates directly to scikit-build-core (no CTK needed), but
# wheel-from-sdist needs CTK and cuda-bindings (dynamic build dep via
# get_requires_for_build_wheel in build_hooks.py).
- name: Build cuda.core sdist and wheel-from-sdist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sdist-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
printf 'cuda-bindings @ %s\n' "${bindings_uri}"
} | tee wheel-constraints/cuda-core.txt

# cuda_core sdist delegates to setuptools (no CTK needed), but
# cuda_core sdist delegates directly to scikit-build-core (no CTK needed), but
# wheel-from-sdist needs CTK and cuda-bindings (dynamic build dep via
# get_requires_for_build_wheel in build_hooks.py).
- name: Build cuda.core sdist and wheel-from-sdist
Expand Down
1 change: 1 addition & 0 deletions cuda_bindings/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ include = ["cuda*"]

[tool.setuptools]
include-package-data = false
package-dir = {"" = "."}

[tool.setuptools.package-data]
"*" = ["*.pxd", "*.pxi"]
Expand Down
78 changes: 78 additions & 0 deletions cuda_bindings/tests/test_build_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Tests for the cuda-bindings PEP 517 build wrapper."""

import base64
import csv
import hashlib
import importlib.util
import io
import zipfile
from pathlib import Path
from unittest import mock

import pytest


def _load_build_hooks():
build_hooks_path = Path(__file__).parent.parent / "build_hooks.py"
spec = importlib.util.spec_from_file_location("_cuda_bindings_test_build_hooks", build_hooks_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


build_hooks = _load_build_hooks()


def _record_row(path, contents):
digest = base64.urlsafe_b64encode(hashlib.sha256(contents).digest()).rstrip(b"=").decode("ascii")
return path, f"sha256={digest}", len(contents)


def _assert_valid_record(wheel):
record_path = next(name for name in wheel.namelist() if name.endswith(".dist-info/RECORD"))
rows = list(csv.reader(io.StringIO(wheel.read(record_path).decode("utf-8"), newline="")))
records = {path: (digest, size) for path, digest, size in rows}

assert set(records) == set(wheel.namelist())
for name in wheel.namelist():
digest, size = records[name]
if name == record_path:
assert (digest, size) == ("", "")
else:
contents = wheel.read(name)
assert (name, digest, int(size)) == _record_row(name, contents)


@pytest.mark.agent_authored(model="gpt-5.6")
def test_editable_wheel_uses_data_only_source_root_pth(tmp_path, monkeypatch):
project_root = Path(build_hooks.__file__).resolve().parent
bindings_build = mock.Mock()
monkeypatch.chdir(project_root)
monkeypatch.setattr(build_hooks, "_build_cuda_bindings", bindings_build)

wheel_name = build_hooks.build_editable(tmp_path, {"debug": False})

bindings_build.assert_called_once_with(debug=False)
with zipfile.ZipFile(tmp_path / wheel_name) as wheel:
pth_files = [name for name in wheel.namelist() if name.endswith(".pth")]
assert len(pth_files) == 1
assert wheel.read(pth_files[0]).decode("utf-8") == f"{project_root}\n"
_assert_valid_record(wheel)


@pytest.mark.agent_authored(model="gpt-5.6")
def test_regular_wheel_does_not_include_editable_path(tmp_path, monkeypatch):
project_root = Path(build_hooks.__file__).resolve().parent
bindings_build = mock.Mock()
monkeypatch.chdir(project_root)
monkeypatch.setattr(build_hooks, "_build_cuda_bindings", bindings_build)

wheel_name = build_hooks.build_wheel(tmp_path, {"debug": False})

bindings_build.assert_called_once_with(debug=False)
with zipfile.ZipFile(tmp_path / wheel_name) as wheel:
assert not any(name.endswith(".pth") for name in wheel.namelist())
_assert_valid_record(wheel)
3 changes: 2 additions & 1 deletion cuda_core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ This file describes `cuda_core`, the high-level Pythonic CUDA subpackage in the
- execution path: `_launcher.pyx`, `_launch_config.pyx`, `_stream.pyx`
- **C++ helpers**: module-specific C++ implementations live under
`cuda/core/_cpp/`.
- **Build backend**: `build_hooks.py` handles Cython extension setup and build
- **Build backend**: `CMakeLists.txt` defines the Cython extension build;
`build_hooks.py` wraps scikit-build-core to provide CUDA-major-specific build
dependency wiring.

## Build and version coupling
Expand Down
Loading