Skip to content

Commit

Permalink
make FindRust gracefully fail if rustc not found
Browse files Browse the repository at this point in the history
Earlier a missing .cargo/bin/rustc would fail with

The system cannot find the file specified
CMake Error at corrosion/cmake/FindRust.cmake:171 (get_filename_component):
  get_filename_component called with incorrect number of arguments

Now it prints a more descriptive errormessage, sets Rust_FOUND to false
and returns.
It also sets Rust_FOUND to true if a rust target is successfully created
  • Loading branch information
trondhe authored and ogoffart committed Sep 17, 2021
1 parent ae88df0 commit f679545
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,19 @@ if (_RESOLVE_RUSTUP_TOOLCHAINS)
NO_DEFAULT_PATH)
else()
find_program(Rust_COMPILER_CACHED rustc)
if (Rust_COMPILER_CACHED)
get_filename_component(_RUST_TOOLCHAIN_PATH ${Rust_COMPILER_CACHED} DIRECTORY)
get_filename_component(_RUST_TOOLCHAIN_PATH ${_RUST_TOOLCHAIN_PATH} DIRECTORY)
endif()
endif()

get_filename_component(_RUST_TOOLCHAIN_PATH ${Rust_COMPILER_CACHED} DIRECTORY)
get_filename_component(_RUST_TOOLCHAIN_PATH ${_RUST_TOOLCHAIN_PATH} DIRECTORY)
if (NOT Rust_COMPILER_CACHED)
message(
WARNING "The rustc executable was not found. "
"Rust not installed or ~/.cargo/bin not added to path? "
"Aborting further actions of find_package(Rust). ")
set(Rust_FOUND false)
return()
endif()

# Look for Cargo next to rustc.
Expand Down Expand Up @@ -358,4 +368,5 @@ if(NOT TARGET Rust::Rustc)
TARGET Rust::Cargo
PROPERTY IMPORTED_LOCATION ${Rust_CARGO_CACHED}
)
set(Rust_FOUND true)
endif()

0 comments on commit f679545

Please sign in to comment.