Skip to content

Commit 5078fe6

Browse files
juenglinrwgk
andauthored
build: keep _build_shared.py as identical copies (#3036)
* build: keep _build_shared.py as identical copies Replace the cuda_core symlink with a regular file and restore a pre-commit check that uses git diff --no-index so the two packages stay byte-identical without requiring Git symlink support to build. --------- Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent 4c893de commit 5078fe6

12 files changed

Lines changed: 542 additions & 54 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ repos:
8181
language: python
8282
files: '^cuda_core/tests/.*\.py$'
8383

84+
- id: check-build-shared-sync
85+
name: Check _build_shared.py copies are identical
86+
language: system
87+
pass_filenames: false
88+
files: '^(cuda_bindings|cuda_core)/_build_shared\.py$'
89+
entry: bash -c
90+
args:
91+
- 'git diff --no-index --exit-code -- cuda_bindings/_build_shared.py cuda_core/_build_shared.py || { echo "ERROR: cuda_bindings/_build_shared.py and cuda_core/_build_shared.py must be byte-identical. Copy one onto the other and commit both." >&2; exit 1; }'
92+
- "_" # fake script name, because bash considers $0 (the first argument) to be the script name
93+
8494
- id: no-markdown-in-docs-source
8595
name: Prevent markdown files in docs/source directories
8696
entry: bash -c

‎CONTRIBUTING.md‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ Thank you for your interest in contributing to CUDA Python! Based on the type of
4444

4545
## Cloning the repository
4646

47-
> **Windows contributors (not WSL):** configure Git for symlinks *before*
48-
> cloning, or the shared PEP 517 build-hook file lands as a text stub instead
49-
> of a working symlink. See [Enabling git symlinks](#enabling-git-symlinks)
50-
> under Development on Windows.
47+
> **Windows contributors (not WSL):** source builds and tests work with
48+
> `core.symlinks=false`. Git symlink support is optional and only affects the
49+
> remaining documentation and metadata links (`CLAUDE.md`,
50+
> `cuda_python/README.md`, and `.git_archival.txt`). See
51+
> [Enabling git symlinks](#enabling-git-symlinks) if you want those links materialized.
5152
5253
Every package in this repository derives its version from git tags using
5354
[`setuptools-scm`](https://setuptools-scm.readthedocs.io/), so **how you clone
@@ -137,18 +138,18 @@ genuinely cannot provide tags; it is not a substitute for a correct clone.
137138

138139
## Development on Windows
139140

140-
This section collects the Windows-specific setup a contributor needs when
141-
working outside of WSL. WSL contributors can follow the Linux flow in the rest
142-
of this document.
141+
This section collects Windows-specific guidance for contributors working
142+
outside of WSL. WSL contributors can follow the Linux flow in the rest of this
143+
document.
143144

144145
### Enabling git symlinks
145146

146-
The `cuda_core` PEP 517 backend shares source-of-truth helper files with
147-
`cuda_bindings` via symbolic links. Git materializes symlinks by default on
148-
Linux and macOS, but on Windows it needs to be configured before cloning,
149-
otherwise the "symlinks" land in your working tree as plain text files that
150-
contain the target path — enough to look right in `git status`, but not enough
151-
to actually build.
147+
The repository still contains documentation and metadata symlinks, including
148+
`CLAUDE.md`, `cuda_python/README.md`, and the per-package `.git_archival.txt`
149+
files. With `core.symlinks=false`, Git checks them out as plain text files
150+
containing the target path. This does not affect source builds or tests.
151+
152+
If you want these links materialized as symlinks:
152153

153154
1. **[Activate Developer Mode](https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development#activate-developer-mode)**
154155
so Git can create symlinks without Administrator privileges.
@@ -162,22 +163,19 @@ to actually build.
162163

163164
Then clone as usual (see [Cloning the repository](#cloning-the-repository)).
164165

165-
If you already cloned without these settings, note that `git clone` probes
166-
symlink support at clone time and writes `core.symlinks=false` into the
167-
repo-local config when the probe fails. Repo-local config overrides
168-
`--global`, so you must clear it *inside the existing clone* — the global
169-
setting alone won't take effect:
166+
If you already cloned with `core.symlinks=false`, the repository-local
167+
setting overrides the global setting. Enable it locally, then rematerialize
168+
all tracked symlinks. For example:
170169

171170
```console
172-
$ git config core.symlinks true # no --global — clears the repo-local override
173-
$ git rm --cached cuda_core/_build_shared.py
174-
$ git checkout HEAD -- cuda_core/_build_shared.py
171+
$ git config core.symlinks true
172+
$ git rm --cached cuda_python/README.md
173+
$ git checkout HEAD -- cuda_python/README.md
175174
```
176175

177-
In practice, deleting the checkout and re-cloning after the two steps at
178-
the top of this section (Developer Mode + `git config --global core.symlinks
179-
true`) is usually simpler and less error-prone than repairing an existing
180-
clone in place.
176+
Repeat the last two commands for every other tracked symlink. Re-cloning after
177+
enabling Developer Mode and setting the global option is simpler if you want
178+
all links restored.
181179

182180
### Pre-commit lychee workaround
183181

‎cuda_bindings/AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ subpackage in the `cuda-python` monorepo.
2121
- **Build backend**: `build_hooks.py` drives extension configuration and
2222
Cythonization. Logic shared with `cuda_core` (toolchain selection, the
2323
compiler flag set, the Cython cache helpers and the rebuild stamps) lives
24-
in `_build_shared.py`; `cuda_core/_build_shared.py` is a symlink to this
25-
file, so an edit here changes both packages.
24+
in `_build_shared.py`. `cuda_bindings/_build_shared.py` is canonical;
25+
`cuda_core/_build_shared.py` must be either a symlink to it or a byte-for-byte
26+
identical copy.
2627

2728
## Generated-source workflow
2829

‎cuda_bindings/MANIFEST.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ recursive-include cuda/ *.pyx *.pxd *.pxi *.pyx.in *.pxd.in *.pxi.in *.h
66
# to the payload, causing file copying to the build environment failed
77
exclude cuda/bindings cuda?bindings
88
exclude cuda/bindings/_bindings cuda?bindings?_bindings
9-
# canonical shared PEP 517 helper (cuda_core/_build_shared.py symlinks to the cuda_bindings copy)
9+
# package-local shared PEP 517 helper
1010
include _build_shared.py

‎cuda_bindings/_build_shared.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
"""Build helpers shared by the cuda-bindings and cuda-core PEP 517 backends.
55
6-
This is the single source of truth. ``cuda_core/_build_shared.py`` is a symlink
7-
to this file. Python does not dereference symlinks in ``__file__``, so any
8-
``Path(__file__)``-relative location in here resolves under whichever package
9-
loads it.
6+
``cuda_bindings/_build_shared.py`` is canonical. ``cuda_core/_build_shared.py``
7+
is either a symlink to it or a byte-for-byte identical copy. Both backends load
8+
the helper through their package-local path, keeping ``Path(__file__)``-relative
9+
state package-local.
1010
1111
PEP 517 build isolation gives each backend its own ``build_hooks.py`` but not a
1212
shared import path. Both packages declare ``backend-path = ["."]``, which puts
@@ -385,9 +385,8 @@ def _stable_cython_alias(target: Path, alias: Path):
385385
unstable across runs. This context manager creates a fixed, worktree-
386386
relative symlink so Cython sees a stable lexical path.
387387
388-
The symlink is created in the *package directory* (the directory containing
389-
this file, which is the package's own copy through the symlink), not in
390-
the cwd, to keep aliases package-local and avoid cross-package races.
388+
The symlink is created in the package directory containing this file, not
389+
in the cwd, to keep aliases package-local and avoid cross-package races.
391390
392391
alias must not already exist as a real file or directory; if it is a
393392
symlink (including a dangling one) it is atomically replaced.

‎cuda_bindings/docs/source/install.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Requirements
126126

127127
[^2]: The CUDA Runtime static library (``libcudart_static.a`` on Linux, ``cudart_static.lib`` on Windows) is part of the CUDA Toolkit. If using conda packages, it is contained in the ``cuda-cudart-static`` package.
128128

129-
[^3]: The version is derived from git tags via ``setuptools-scm``, so the clone must include tags reaching back to at least the latest ``v*`` tag. Clone with ``git clone https://github.com/NVIDIA/cuda-python.git``; do not use ``--depth`` or ``--no-tags``, since a shallow clone builds without error but produces a bogus version such as ``0.1.dev1+g0d22cb444``. See `Cloning the repository <https://github.com/NVIDIA/cuda-python/blob/main/CONTRIBUTING.md>`_ for details and recovery steps. Windows contributors building outside of WSL should also see `Development on Windows <https://github.com/NVIDIA/cuda-python/blob/main/CONTRIBUTING.md#development-on-windows>`_ for the git-symlink configuration that must be set *before* cloning.
129+
[^3]: The version is derived from git tags via ``setuptools-scm``, so the clone must include tags reaching back to at least the latest ``v*`` tag. Clone with ``git clone https://github.com/NVIDIA/cuda-python.git``; do not use ``--depth`` or ``--no-tags``, since a shallow clone builds without error but produces a bogus version such as ``0.1.dev1+g0d22cb444``. See `Cloning the repository <https://github.com/NVIDIA/cuda-python/blob/main/CONTRIBUTING.md>`_ for details and recovery steps.
130130

131131
Source builds require that the provided CUDA headers are of the same major.minor version as the ``cuda.bindings`` you're trying to build. Despite this requirement, note that the minor version compatibility is still maintained. The build checks the header before it compiles anything. A mismatch stops the build with a message that names the ``cuda.h`` it found and the version this source tree needs. Use the ``CUDA_PATH`` (or ``CUDA_HOME``) environment variable to specify the location of your headers. If both are set, ``CUDA_PATH`` takes precedence. For example, if your headers are located in ``/usr/local/cuda/include``, then you should set ``CUDA_PATH`` with:
132132

‎cuda_core/AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ This file describes `cuda_core`, the high-level Pythonic CUDA subpackage in the
2525
- **Build backend**: `build_hooks.py` handles Cython extension setup and build
2626
dependency wiring. Logic shared with `cuda_bindings` (toolchain selection,
2727
the compiler flag set, the Cython cache helpers and the rebuild stamps)
28-
lives in `_build_shared.py`, a symlink to `cuda_bindings/_build_shared.py`; an edit through either path changes both
29-
packages.
28+
lives in `_build_shared.py`. `cuda_bindings/_build_shared.py` is canonical;
29+
`cuda_core/_build_shared.py` must be either a symlink to it or a byte-for-byte
30+
identical copy.
3031

3132
## Build and version coupling
3233

‎cuda_core/MANIFEST.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ recursive-include cuda/core/_cpp *.cpp *.h *.hpp
77
recursive-include cuda/core/_include *.h *.hpp
88
include cuda/core/py.typed
99
include NOTICE
10-
# canonical shared PEP 517 helper (cuda_core/_build_shared.py symlinks to the cuda_bindings copy)
10+
# package-local shared PEP 517 helper
1111
include _build_shared.py

‎cuda_core/_build_shared.py‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)