From 1bb69c04c1e84d3cf215886647ad1de00011751c Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Tue, 18 Oct 2022 15:26:02 -0700 Subject: [PATCH] rust: find cargo with find_program to give a better error message when cargo isn't available Summary: If you build Watchman from source on a machine without cargo, the error message was confusing. You'd see "command not found" somewhere mixed into ninja's output. Change RustStaticLibrary, which is only used by Watchman and EdenFS, to find cargo with find_program instead of guessing its name and assuming it exists. This gives a much less confusing error message at CMake configure time. Reviewed By: genevievehelsel Differential Revision: D40441374 fbshipit-source-id: eeafe615616775c660c700e14cf1f6b2fd9715a8 --- .../fbcode_builder/CMake/RustStaticLibrary.cmake | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/build/fbcode_builder/CMake/RustStaticLibrary.cmake b/build/fbcode_builder/CMake/RustStaticLibrary.cmake index 8afe09f1e..dd57b2b3d 100644 --- a/build/fbcode_builder/CMake/RustStaticLibrary.cmake +++ b/build/fbcode_builder/CMake/RustStaticLibrary.cmake @@ -58,6 +58,8 @@ if(GENERATE_CARGO_VENDOR_CONFIG) ) endif() +find_program(CARGO_COMMAND cargo REQUIRED) + # Cargo is a build system in itself, and thus will try to take advantage of all # the cores on the system. Unfortunately, this conflicts with Ninja, since it # also tries to utilize all the cores. This can lead to a system that is @@ -119,11 +121,6 @@ function(rust_static_library TARGET) set(staticlib_name "${CMAKE_STATIC_LIBRARY_PREFIX}${crate_name}${CMAKE_STATIC_LIBRARY_SUFFIX}") set(rust_staticlib "${CMAKE_CURRENT_BINARY_DIR}/${target_dir}/${staticlib_name}") - set(cargo_cmd cargo) - if(WIN32) - set(cargo_cmd cargo.exe) - endif() - if(DEFINED ARG_FEATURES) set(cargo_flags build $,,--release> -p ${crate_name} --features ${ARG_FEATURES}) else() @@ -142,7 +139,7 @@ function(rust_static_library TARGET) "${CMAKE_COMMAND}" -E env "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}" ${extra_cargo_env} - ${cargo_cmd} + ${CARGO_COMMAND} ${cargo_flags} COMMENT "Building Rust crate '${crate_name}'..." JOB_POOL rust_job_pool @@ -195,11 +192,6 @@ function(rust_executable TARGET) set(features ) endif() - set(cargo_cmd cargo) - if(WIN32) - set(cargo_cmd cargo.exe) - endif() - if(DEFINED ARG_FEATURES) set(cargo_flags build $,,--release> -p ${crate_name} --features ${ARG_FEATURES}) else() @@ -219,7 +211,7 @@ function(rust_executable TARGET) "${CMAKE_COMMAND}" -E env "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}" ${extra_cargo_env} - ${cargo_cmd} + ${CARGO_COMMAND} ${cargo_flags} COMMENT "Building Rust executable '${crate_name}'..." JOB_POOL rust_job_pool