From 8dc2c5963aac5ebcb73ad2ef67d6875f538dc822 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Wed, 20 Nov 2019 12:26:31 -0800 Subject: [PATCH] cmake: automatically decide whether to use vendored rust crates Summary: Update `RustStaticLibrary.cmake` to automatically decide to try and download vendored Rust crates or not, based on the presence of the script it uses to download them. Reviewed By: fanzeyi Differential Revision: D18588007 fbshipit-source-id: 995365f0cc2368897ddf94b5617bdb9bc0682edc --- eden/scm/CMake/RustStaticLibrary.cmake | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/eden/scm/CMake/RustStaticLibrary.cmake b/eden/scm/CMake/RustStaticLibrary.cmake index 6a84f3313c..7f946526ac 100644 --- a/eden/scm/CMake/RustStaticLibrary.cmake +++ b/eden/scm/CMake/RustStaticLibrary.cmake @@ -1,9 +1,21 @@ include(FBCMakeParseArgs) +set( + USE_CARGO_VENDOR AUTO CACHE STRING + "Download Rust Crates from an internally vendored location" +) +set_property(CACHE USE_CARGO_VENDOR PROPERTY STRINGS AUTO ON OFF) + +set(RUST_VENDORED_CRATES_SCRIPT "${CMAKE_SOURCE_DIR}/tools/lfs/crates-io.py") +if("${USE_CARGO_VENDOR}" STREQUAL "AUTO") + if(EXISTS "${RUST_VENDORED_CRATES_SCRIPT}") + set(USE_CARGO_VENDOR ON) + else() + set(USE_CARGO_VENDOR OFF) + endif() +endif() + if(USE_CARGO_VENDOR AND NOT TARGET rust_vendored_crates) - set(RUST_VENDORED_CRATES_DIR "${CMAKE_BINARY_DIR}/_rust_crates/vendor") - set(RUST_VENDORED_CRATES_SCRIPT "${CMAKE_SOURCE_DIR}/tools/lfs/crates-io.py") - set(RUST_CARGO_HOME "${CMAKE_BINARY_DIR}/_rust_crates/cargo_home") if(NOT EXISTS "${RUST_VENDORED_CRATES_SCRIPT}") message( FATAL "vendored rust crates script does not exist: " @@ -11,6 +23,8 @@ if(USE_CARGO_VENDOR AND NOT TARGET rust_vendored_crates) ) endif() + set(RUST_VENDORED_CRATES_DIR "${CMAKE_BINARY_DIR}/_rust_crates/vendor") + set(RUST_CARGO_HOME "${CMAKE_BINARY_DIR}/_rust_crates/cargo_home") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/_rust_crates") file(MAKE_DIRECTORY "${RUST_CARGO_HOME}") file(