Skip to content

Commit

Permalink
Add test to FindRust with Rust_USE_RUSTUP_PROXY
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-nextsilicon authored and jschwe committed Jul 12, 2023
1 parent 5be52d4 commit 317e53a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/find_rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
corrosion_tests_add_test(find_rust "")
corrosion_tests_add_test(rustup_proxy "")

47 changes: 47 additions & 0 deletions test/find_rust/rustup_proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.15)
project(RustupProxy LANGUAGES CXX)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH})

function(_assert_is_rustup_proxy executable_path)
execute_process(
COMMAND
${CMAKE_COMMAND} -E env
RUSTUP_FORCE_ARG0=rustup
"${executable_path}" --version
OUTPUT_VARIABLE _VERSION_RAW
ERROR_VARIABLE _VERSION_STDERR
RESULT_VARIABLE _VERSION_RESULT
)

if(NOT _VERSION_RESULT EQUAL "0")
message(FATAL_ERROR "`${executable_path} --version` failed with ${_VERSION_RESULT}\n"
"stderr:\n${_VERSION_STDERR}"
)
endif()

if (NOT _VERSION_RAW MATCHES "rustup [0-9\\.]+")
message(FATAL_ERROR "`${executable_path} --version` output does not match rustup: ${_VERSION_RAW}\n")
endif()
endfunction()

set(Rust_RESOLVE_RUSTUP_TOOLCHAINS OFF CACHE BOOL "" FORCE)
find_package(Rust REQUIRED)

if (NOT Rust_FOUND)
message(FATAL_ERROR "Rustup not found")
endif()

get_property(
RUSTC_EXECUTABLE
TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION
)

_assert_is_rustup_proxy(${RUSTC_EXECUTABLE})

get_property(
CARGO_EXECUTABLE
TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION
)

_assert_is_rustup_proxy(${CARGO_EXECUTABLE})

0 comments on commit 317e53a

Please sign in to comment.