fix(cuda): look for nvcc instead of leaving it to PATH
cfg.cuda compiled with a bare "nvcc", which the shell looked up on PATH. In crafter-build's Flatpak PATH is /app/bin:/usr/bin, as its manifest sets it, which never holds the host's toolkit, so with it every build with CUDA sources stopped at "sh: line 1: nvcc: command not found", although the sandbox sees /opt/cuda through --filesystem=host. ResolveToolchain now finds nvcc as it finds clang++: CUDA_PATH, which is exclusive as CRAFTER_BUILD_LLVM_DIR is, else /opt/cuda (Arch's package) or /usr/local/cuda (NVIDIA's installer and packages), else the absolute entries of PATH, which it searches itself so that a build without a toolkit can say where it looked. A relative CUDA_PATH is made absolute there, once, as CRAFTER_MINGW_DIR is, since nvcc runs later from whatever working directory a build is in. The sandbox shows the host's /usr and /etc under /run/host, with its own runtime at /usr, and NVIDIA's /usr/local/cuda is a link, to /usr/local/cuda-<version> or through /etc/alternatives. A link to an absolute path names a path of the host, /opt/cuda pointing at /usr/local/cuda-<version> too, and the sandbox would look it up in its own root, so where the path of a toolkit, CUDA_PATH, /opt/cuda or /usr/local/cuda, is such a link, HostPath follows it, and the link its target is in turn, each taken as the host's; a link partway along that path, or inside the toolkit, is the kernel's to resolve, in the sandbox's root. A missing toolkit is reported by the build that has a .cu to compile and not by GetToolchain(), so no other build fails for want of one. crafter-build --version prints the nvcc it found, whether or not the compiler could be resolved.
This commit is contained in:
parent
ff3cc20e70
commit
fdba70d176
4 changed files with 132 additions and 4 deletions
|
|
@ -55,6 +55,18 @@ export namespace Crafter {
|
|||
// its mingw-w64 parts; any other prefix is the sysroot itself, and
|
||||
// Windows libraries installed into its include/ and lib/ are found.
|
||||
bool mingwPrefixIsSystem = false;
|
||||
// The nvcc that compiles cfg.cuda: <CUDA_PATH>/bin/nvcc when CUDA_PATH
|
||||
// is set, else bin/nvcc of the first toolkit that has one among
|
||||
// ToolchainInputs::cudaRoots, else the first nvcc in an absolute entry
|
||||
// of PATH. In a sandbox, a toolkit is looked up as the host has it:
|
||||
// under hostRoot where it is in the host's /usr or /etc, and, where
|
||||
// its path is a link, through that link and the link its target is in
|
||||
// turn, each taken as the host's, wherever they point. Empty when
|
||||
// there is none, and nvccError says where it was looked for; only a
|
||||
// build with a .cu to compile reports that, so no other build fails
|
||||
// for want of a CUDA toolkit.
|
||||
fs::path nvcc;
|
||||
std::string nvccError;
|
||||
// The Flatpak runtime crafter-build runs on, from the
|
||||
// runtime=runtime/<id>/<arch>/<branch> line of /.flatpak-info:
|
||||
// "x86_64" and "26.08" in the Flatpak, both empty outside one. A
|
||||
|
|
@ -98,7 +110,8 @@ export namespace Crafter {
|
|||
|
||||
// What ResolveToolchain reads, so a test can feed it a staged layout.
|
||||
struct ToolchainInputs {
|
||||
// The CRAFTER_* variables, present only when set and non-empty.
|
||||
// The CRAFTER_* variables, CUDA_PATH and PATH, present only when set
|
||||
// and non-empty.
|
||||
std::map<std::string, std::string, std::less<>> env;
|
||||
// The <prefix> of <prefix>/share/crafter-build; empty when unknown.
|
||||
fs::path crafterPrefix;
|
||||
|
|
@ -108,10 +121,16 @@ export namespace Crafter {
|
|||
// What /.flatpak-info holds, or the file CRAFTER_BUILD_FLATPAK_INFO
|
||||
// names; empty outside a Flatpak.
|
||||
std::string flatpakInfo;
|
||||
// Where a CUDA toolkit is installed when CUDA_PATH names none, in the
|
||||
// order they are tried and as the host names them: GetToolchain()
|
||||
// passes /opt/cuda, Arch's, and /usr/local/cuda, NVIDIA's installers'.
|
||||
std::vector<fs::path> cudaRoots;
|
||||
};
|
||||
// Pure path resolution: an env override wins, then a toolchain installed
|
||||
// beside crafter-build (<crafterPrefix>/bin/clang++), then bare names on
|
||||
// PATH. Never runs a process, so hostTriple and clangVersion stay empty.
|
||||
// nvcc is not left to the shell's PATH lookup but searched for here,
|
||||
// PATH included, so a build that cannot find one can say where it looked.
|
||||
Toolchain ResolveToolchain(const ToolchainInputs& inputs);
|
||||
// ResolveToolchain over the real environment plus the two clang probes,
|
||||
// computed once and cached. Never throws.
|
||||
|
|
|
|||
Loading…
Reference in a new issue