Skip to content

Commit f679545

Browse files
trondheogoffart
authored andcommitted
make FindRust gracefully fail if rustc not found
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
1 parent ae88df0 commit f679545

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmake/FindRust.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,19 @@ if (_RESOLVE_RUSTUP_TOOLCHAINS)
166166
NO_DEFAULT_PATH)
167167
else()
168168
find_program(Rust_COMPILER_CACHED rustc)
169+
if (Rust_COMPILER_CACHED)
170+
get_filename_component(_RUST_TOOLCHAIN_PATH ${Rust_COMPILER_CACHED} DIRECTORY)
171+
get_filename_component(_RUST_TOOLCHAIN_PATH ${_RUST_TOOLCHAIN_PATH} DIRECTORY)
172+
endif()
173+
endif()
169174

170-
get_filename_component(_RUST_TOOLCHAIN_PATH ${Rust_COMPILER_CACHED} DIRECTORY)
171-
get_filename_component(_RUST_TOOLCHAIN_PATH ${_RUST_TOOLCHAIN_PATH} DIRECTORY)
175+
if (NOT Rust_COMPILER_CACHED)
176+
message(
177+
WARNING "The rustc executable was not found. "
178+
"Rust not installed or ~/.cargo/bin not added to path? "
179+
"Aborting further actions of find_package(Rust). ")
180+
set(Rust_FOUND false)
181+
return()
172182
endif()
173183

174184
# Look for Cargo next to rustc.
@@ -358,4 +368,5 @@ if(NOT TARGET Rust::Rustc)
358368
TARGET Rust::Cargo
359369
PROPERTY IMPORTED_LOCATION ${Rust_CARGO_CACHED}
360370
)
371+
set(Rust_FOUND true)
361372
endif()

0 commit comments

Comments
 (0)