forked from rustls/rustls-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrust.cmake
More file actions
114 lines (101 loc) · 3.69 KB
/
rust.cmake
File metadata and controls
114 lines (101 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
include(ExternalProject)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/rust)
if(FORCE_SYSTEM_RUSTLS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(RUSTLS_FFI REQUIRED rustls)
if(NOT RUSTLS_FFI_FOUND)
message(FATAL_ERROR "System rustls-ffi required but not found")
endif()
message(STATUS "RUSTLS_FFI_INCLUDE_DIRS: ${RUSTLS_FFI_INCLUDE_DIRS}")
message(STATUS "RUSTLS_FFI_LIBRARY_DIRS: ${RUSTLS_FFI_LIBRARY_DIRS}")
message(STATUS "RUSTLS_FFI_LIBRARIES: ${RUSTLS_FFI_LIBRARIES}")
else()
ExternalProject_Add(
rustls-ffi
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND
cargo capi build --locked ${CARGO_FEATURES}
"$<IF:$<CONFIG:Release>,--release,-->"
# Rely on cargo checking timestamps, rather than tell CMake where every
# output is.
BUILD_ALWAYS true
INSTALL_COMMAND
cargo capi install --libdir=lib --prefix=${CMAKE_BINARY_DIR}/rust
--locked ${CARGO_FEATURES}
"$<IF:$<CONFIG:Release>,--release,--debug>"
# Run cargo test with --quiet because msbuild will treat the presence
# of "error" in stdout as an error, and we have some test functions that
# end in "_error". Quiet mode suppresses test names, so this is a
# sufficient workaround.
TEST_COMMAND
cargo test --locked ${CARGO_FEATURES}
"$<IF:$<CONFIG:Release>,--release,-->" --quiet
)
endif()
add_custom_target(
cbindgen
# TODO(@cpu): I suspect this won't work on Windows :P
COMMAND cbindgen > "src/rustls.h"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(connect-test DEPENDS client)
# For WIN32 when using dynamic linking we need to put the .dll
# in the search path for the binaries.
if(WIN32 AND DYN_LINK)
add_custom_command(
TARGET connect-test
PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/rust/bin/rustls.dll"
"${CMAKE_BINARY_DIR}\\tests\\$<CONFIG>\\"
)
endif()
add_custom_command(
TARGET connect-test
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E env RUSTLS_PLATFORM_VERIFIER=1
"$<TARGET_FILE:client>" example.com 443 /
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(integration-test DEPENDS client server)
if(WIN32 AND DYN_LINK)
add_custom_command(
TARGET integration-test
PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/rust/bin/rustls.dll"
"${CMAKE_BINARY_DIR}\\tests\\$<CONFIG>\\"
)
endif()
add_custom_command(
TARGET integration-test
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E env CLIENT_BINARY="$<TARGET_FILE:client>"
${CMAKE_COMMAND} -E env SERVER_BINARY="$<TARGET_FILE:server>" cargo test
--locked ${CARGO_FEATURES} "$<IF:$<CONFIG:Release>,--release,>" --test
client_server client_server_integration -- --ignored --exact
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_target(ech-test DEPENDS client)
if(WIN32 AND DYN_LINK)
add_custom_command(
TARGET ech-test
PRE_BUILD
COMMAND
${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/rust/bin/rustls.dll"
"${CMAKE_BINARY_DIR}\\tests\\$<CONFIG>\\"
)
endif()
add_custom_command(
TARGET ech-test
POST_BUILD
COMMAND cargo run -p rustls-ffi-tools --bin ech_fetch
COMMAND
${CMAKE_COMMAND} -E env RUSTLS_PLATFORM_VERIFIER=1 ${CMAKE_COMMAND} -E
env ECH_CONFIG_LIST="research.cloudflare.com.ech.configs.bin"
$<TARGET_FILE:client> cloudflare-ech.com 443 /cdn-cgi/trace
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)