Skip to content

Commit

Permalink
FindRust: Fix finding rustc with rustup from package manager
Browse files Browse the repository at this point in the history
rustup can be installed from a package manager.
If Rust_RESOLVE_RUSTUP_TOOLCHAINS is set to OFF, but rustup is
installed, we can't assume rustc will be next to rustup.
  • Loading branch information
jschwe committed Aug 5, 2024
1 parent 7b6110b commit 2d7680b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,15 @@ if (Rust_RESOLVE_RUSTUP_TOOLCHAINS)
rustc
HINTS "${_RUST_TOOLCHAIN_PATH}/bin"
NO_DEFAULT_PATH)
elseif (Rust_RUSTUP)
get_filename_component(_RUST_TOOLCHAIN_PATH "${Rust_RUSTUP}" DIRECTORY)
get_filename_component(_RUST_TOOLCHAIN_PATH "${_RUST_TOOLCHAIN_PATH}" DIRECTORY)
find_program(
Rust_COMPILER_CACHED
rustc
HINTS "${_RUST_TOOLCHAIN_PATH}/bin"
NO_DEFAULT_PATH)
else()
find_program(Rust_COMPILER_CACHED rustc)
message(DEBUG "Rust_RESOLVE_RUSTUP_TOOLCHAINS=OFF and Rust_RUSTUP=${Rust_RUSTUP}")
if(Rust_RUSTUP)
get_filename_component(_RUSTUP_DIR "${Rust_RUSTUP}" DIRECTORY)
find_program(Rust_COMPILER_CACHED rustc HINTS "${_RUSTUP_DIR}")
else()
find_program(Rust_COMPILER_CACHED rustc)
endif()
message(DEBUG "find_program rustc: ${Rust_COMPILER_CACHED}")
if (EXISTS "${Rust_COMPILER_CACHED}")
# rustc is expected to be at `<toolchain_path>/bin/rustc`.
get_filename_component(_RUST_TOOLCHAIN_PATH "${Rust_COMPILER_CACHED}" DIRECTORY)
Expand Down

0 comments on commit 2d7680b

Please sign in to comment.