Repository navigation
fix(cuda-bindings): select targets/ by full build target, and reach Tegra - #700
Merged
Merged
Conversation
…egra `toolkit_target_dir` matched only the first segment of the `TARGET` triple, so the architecture alone decided the CUDA `targets/<dir>` layout and the OS was never consulted. Every non-Linux target therefore claimed a Linux directory: `aarch64-apple-darwin` resolved to `sbsa-linux` and `x86_64-pc-windows-msvc` to `x86_64-linux`, both of which then fed `find_cuda_include_dir` and `collect_lib_paths` a path that cannot exist on those platforms. The arch-only match also left CUDA for Tegra unreachable. Tegra installs (Jetson, Drive) put their headers under `targets/aarch64-linux/`, while `sbsa-linux` is the ARM *server* tree -- and both build natively as `aarch64-unknown-linux-gnu`, so the triple cannot tell them apart. aarch64 Linux now yields both names as ordered candidates and the existing `cuda.h` existence probe picks the one actually installed. `sbsa-linux` stays first, so an install carrying both trees resolves exactly as it does today. Selection keys off `CARGO_CFG_TARGET_ARCH`/`CARGO_CFG_TARGET_OS` rather than splitting the triple: the triple's field count varies (`arch-vendor-os-env` vs `arch-os-env`), and `aarch64-linux-android` would otherwise read as a Linux target. This is not the `targets/*` glob proposed in NVIDIA#88 and rejected. Every candidate returned is for the requested architecture only, so a multi-target install can never hand an x86_64 build the `sbsa-linux` headers that sort ahead of it; `multi_target_install_never_hands_x86_64_ the_sbsa_headers` pins that. The table and the candidate-path construction live in `toolkit_target.rs` and are pulled into both `build.rs` and `tests/toolkit_target.rs` with `include!`, because cargo never builds a build script as a test target. Eight tests cover the selection table, the Tegra and sbsa layouts, a multi-target install, the standard top-level `include/`, and non-Linux targets. They fail against the previous arch-only behavior. Signed-off-by: Nils Homer <[email protected]>
…he targets/ selection Two completions on top of the targets/ selection rework: - CUDA_TOOLKIT_TARGET_DIR names one targets/ tree by hand, like nvcc's -target-dir flag and CMake's CUDAToolkit_TARGET_DIR. When set (and not blank) it is the single targets/ candidate; the directory is still probed for cuda.h, so a wrong value fails with the clear discovery error instead of silently falling back to the table. build.rs emits rerun-if-env-changed for it, and the synthetic-tree tests cover both the resolving and the deliberately-failing override. - The two hand-kept mirrors catch up with the shared table in crates/cuda-bindings/toolkit_target.rs: doctor's cuda_header_candidates in cargo-oxide and the multicast probe in cuda-core/build.rs now key on arch+OS instead of the first triple segment, probe both aarch64 Linux trees (sbsa-linux, then aarch64-linux), and honor the same override. Their lockstep comments now name toolkit_target.rs.
Collaborator
|
Gist: The toolkit directory is now chosen from both the target's CPU architecture and its operating system, instead of the first word of the triple. Concretely: Mac and Windows builds stop probing Linux-only directories, and Jetson/Drive installs (which live under I pushed one commit on top:
Verified here: 10/10 toolkit tests linking against the real toolkit on this box; both mirrors compile clean. Closes #698. #139 (Windows lib paths) stays open, as you noted. Merging. |
nihalpasham
approved these changes
Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #698.
Problem
toolkit_target_dir()matched only the first segment of the target triple, so architecture alone decided the CUDAtargets/<dir>layout and the OS was never consulted:aarch64-apple-darwinprobedtargets/sbsa-linux/(a Linux-only tree) andx86_64-pc-windows-msvcprobedtargets/x86_64-linux/.targets/aarch64-linux/, while aarch64 was hard-wired to the ARM server tree (sbsa-linux).Fix
CARGO_CFG_TARGET_ARCH+CARGO_CFG_TARGET_OS(robust against 3- vs 4-field triples; correctly excludes Android), returns nothing for non-Linux, and yields ordered candidates for aarch64 Linux:["sbsa-linux", "aarch64-linux"], walked by the existingcuda.hexistence probe.sbsa-linuxstays first, so installs carrying both trees resolve exactly as today.toolkit_target.rs) used by bothbuild.rsconsumers and a synthetic-tree integration suite. Preserves the single-architecture anti-glob decision from cuda-bindings: clean error for missing cuda.h, target-aware toolkit layout #172, with a test asserting it.FindCUDAToolkitselection almost exactly.Maintainer commit on top (b65208b)
CUDA_TOOLKIT_TARGET_DIRenv override (the nvcc-target-dir/ CMakeCUDAToolkit_TARGET_DIRequivalent): if set, it is the singletargets/candidate, still existence-probed so typos fail with the existing clear error;cargo:rerun-if-env-changedwired; two override tests added. This settles the dual-tree ambiguity (a Jetson cross sysroot carrying both trees can now pinaarch64-linux).cuda_header_candidates) and cuda-core'sbuild.rs. Without this, a Tegra user would build fine and thencargo oxide doctorwould exit 1 claiming cuda.h is missing. Their lockstep comments now nametoolkit_target.rs.