fb-mercurial-rust: make CMake build fetch vendored tp2 first

Summary: We do not have network access in Sandcastle but Mercurial needs some external crates to build. So we download the tp2 crates io tar from LFS and set up cargo to be able to find external crates from it.

Reviewed By: wez

Differential Revision: D17407962

fbshipit-source-id: 4fe6be42d52c79340b33687d13723fcbcd63754e
This commit is contained in:
Zeyi (Rice) Fan 2019-09-26 15:47:14 -07:00 committed by Facebook Github Bot
parent 951b9e95f5
commit 89c898a13e
2 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,8 @@ include(FBCMakeParseArgs)
# built by Cargo. It will call Cargo to build a staticlib and generate a CMake
# interface library with it.
#
# This function requires `find_package(Python COMPONENTS Interpreter)`.
#
# You need to set `lib:crate-type = ["staticlib"]` in your Cargo.toml to make
# Cargo build static library.
#
@ -43,6 +45,15 @@ 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}")
if(USE_CARGO_VENDOR)
# setup_cargo_vendor.py is present only in the internal FB version of this repo,
# and is used to avoid downloading crates directly from the internet each time
# our CI runs a build.
set(pre_cargo_cmd ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/CMake/facebook/setup_cargo_vendor.py)
else()
set(pre_cargo_cmd "${CMAKE_COMMAND} -E echo NOP")
endif()
if(WIN32)
# compatibility for cmd.exe
set(
@ -58,6 +69,7 @@ function(rust_static_library TARGET)
add_custom_target(
${cargo_target} ALL
COMMAND ${pre_cargo_cmd}
COMMAND ${cargo_cmd}
COMMENT "Building Rust crate '${crate_name}'..."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

View File

@ -16,6 +16,7 @@ find_package(Threads REQUIRED)
find_package(Gflags MODULE REQUIRED)
find_package(folly CONFIG REQUIRED)
find_package(Python COMPONENTS Interpreter)
include(RustStaticLibrary)
include(CMakePackageConfigHelpers)