Skip to content

Commit b959d11

Browse files
authored
Avoid absolute generated source paths in cuda.core builds (#2720)
1 parent 0244727 commit b959d11

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎cuda_core/build_hooks.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ def record_build_major() -> None:
174174
_BUILD_MAJOR_STAMP.write_text(_determine_cuda_major_version() + "\n", encoding="utf-8")
175175

176176

177+
def _relativize_extension_sources(extensions) -> None:
178+
"""Keep absolute source paths out of setuptools' temporary build tree."""
179+
for extension in extensions:
180+
extension.sources = [
181+
os.path.relpath(source, start=Path.cwd()) if os.path.isabs(source) else source
182+
for source in extension.sources
183+
]
184+
185+
177186
def _build_cuda_core(debug=False):
178187
# Customizing the build hooks is needed because we must defer cythonization until cuda-bindings,
179188
# now a required build-time dependency that's dynamically installed via the other hook below,
@@ -292,6 +301,10 @@ def get_sources(mod_name):
292301
compile_time_env=compile_time_env,
293302
**extra_cythonize_kwargs,
294303
)
304+
# Cython returns generated sources under the absolute build_dir above.
305+
# setuptools mirrors absolute source paths into build/temp, which can push
306+
# MSVC linker output paths past MAX_PATH in deeper Windows checkouts.
307+
_relativize_extension_sources(_extensions)
295308

296309
return
297310

‎cuda_core/tests/test_build_hooks.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ def test_dir_is_anchored_not_relative_to_cwd(self, monkeypatch):
268268
assert build_dir.parent.parent == build_hooks._BUILD_MAJOR_STAMP.parent
269269

270270

271+
class TestSetuptoolsSourcePaths:
272+
@pytest.mark.agent_authored(model="gpt-5.6-sol")
273+
def test_absolute_sources_are_made_relative(self, tmp_path, monkeypatch):
274+
monkeypatch.chdir(tmp_path)
275+
generated = tmp_path / "build" / "cython" / "cu13" / "cuda" / "core" / "_device.cpp"
276+
relative = "cuda/core/_cpp/helper.cpp"
277+
extension = build_hooks.Extension("cuda.core._device", [str(generated), relative])
278+
279+
build_hooks._relativize_extension_sources([extension])
280+
281+
assert extension.sources == [os.path.relpath(generated, start=tmp_path), relative]
282+
283+
271284
def _load_setup_py(monkeypatch):
272285
"""Import setup.py for its command classes.
273286

0 commit comments

Comments
 (0)