Skip to content

Commit ff72516

Browse files
committed
rm CI dep on rustls-ffi-test for artifact test
Previously the artifacts.yaml CI job relied on an external repo that had a simple C/CMake application depending on librustls. When verifying artifacts we cloned this repo and tested a build against the artifact. This commit reworks the main repo's test application code/build to support this use-case. The main tweak required is to support _not_ building librustls from src, but instead finding it with pkg-config. We gate this behind a new `FORCE_SYSTEM_RUSTLS` option. The artifact test CI is updated to use this option. Annoyingly we have to patch the .pc prefix to an absolute dir to get this working nicely, which means handling Windows specially. Similarly, for yet to be determined reasons, on Win32 we have to add some extra target_link_libraries that don't propagate automatically through the pc config. For this we just shift the existing Win32 specific target_link_libraries invocation up and use it for both pkg-config librustls and build-it-ourselves librustls.
1 parent 2f0599f commit ff72516

File tree

4 files changed

+143
-89
lines changed

4 files changed

+143
-89
lines changed

.github/workflows/artifacts.yaml

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ jobs:
175175
- os: macos-13
176176
artifact: rustls-ffi-x86_64-macos
177177
steps:
178-
- name: Checkout rustls-ffi-test sources
178+
- name: Checkout sources
179179
uses: actions/checkout@v4
180180
with:
181-
repository: 'cpu/rustls-ffi-test'
181+
persist-credentials: false
182182
- name: Download rustls-ffi artifact
183183
uses: actions/download-artifact@v4
184184
with:
@@ -194,19 +194,29 @@ jobs:
194194
# the correct location that we extracted the archive. This seems more reliable
195195
# than using `--define-prefix` - it seems to tack an extra 'lib/' subcomponent
196196
# onto the include path that breaks the build.
197-
- name: Fix pkg-config prefix
198-
# We use bash shell explicitly to avoid PowerShell on Windows and to ensure we have 'sed'.
197+
- name: Fix pkg-config prefix (UNIX)
198+
if: matrix.os != 'windows-latest'
199199
shell: bash
200200
# For further fun, sed isn't consistent between macOS and Linux.
201201
run: |
202202
case "${{ runner.os }}" in
203203
"macOS")
204-
sed -i '' "s|prefix=.*|prefix=${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
204+
sed -i '' "s|prefix=.*|prefix=$(pwd)/${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
205205
;;
206206
*)
207-
sed -i "s|prefix=.*|prefix=${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
207+
sed -i "s|prefix=.*|prefix=$(pwd)/${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
208208
;;
209209
esac
210+
- name: Fix pkg-config prefix (Windows)
211+
if: matrix.os == 'windows-latest'
212+
shell: pwsh
213+
run: |
214+
$prefix = (Get-Location).Path + "/${{ matrix.artifact }}"
215+
$prefix = $prefix -replace '\\', '/'
216+
217+
$content = Get-Content "${{ matrix.artifact }}\lib\pkgconfig\rustls.pc"
218+
$content = $content -replace "prefix=.*", "prefix=$prefix"
219+
Set-Content "${{ matrix.artifact }}\lib\pkgconfig\rustls.pc" $content
210220
# Dump out what pkg-config says about the rustls package.
211221
- name: Debug pkg-config
212222
run: |
@@ -220,7 +230,7 @@ jobs:
220230
if: matrix.os != 'windows-latest'
221231
env:
222232
PKG_CONFIG_PATH: ${{ matrix.artifact }}/lib/pkgconfig
223-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
233+
run: cmake -S librustls -B build -DCMAKE_BUILD_TYPE=Release -DFORCE_SYSTEM_RUSTLS=ON
224234
# Set up the cmake build, overriding PKG_CONFIG_PATH to
225235
# point to the extracted rustls-ffi archive.
226236
#
@@ -230,26 +240,30 @@ jobs:
230240
if: matrix.os == 'windows-latest'
231241
env:
232242
PKG_CONFIG_PATH: ${{ matrix.artifact }}/lib/pkgconfig
233-
run: cmake -DPKG_CONFIG_EXECUTABLE=C:\Strawberry\perl\bin\pkg-config.bat -S . -B build
234-
# Build the rustls-ffi-test binary.
235-
- name: Build rustls-ffi-test (UNIX)
243+
run: cmake -DPKG_CONFIG_EXECUTABLE=C:\Strawberry\perl\bin\pkg-config.bat -DFORCE_SYSTEM_RUSTLS=ON -S librustls -B build
244+
# Build the client and server binaries
245+
- name: Build rustls-ffi client/server (UNIX)
236246
if: matrix.os != 'windows-latest'
237247
run: cmake --build build -v
238-
# Build the rustls-ffi-test binary.
248+
# Build the client and server binaries
239249
# On Windows we need to specify a configuration to avoid a warning about using the default
240250
# debug MSCRT runtime with a lib built with the release MSCRT runtime.
241-
- name: Build rustls-ffi-test (Windows)
251+
- name: Build rustls-ffi client/server (Windows)
242252
if: matrix.os == 'windows-latest'
243253
run: cmake --build build --config Release -v
244-
# Run the rustls-ffi-test binary.
245-
- name: Run rustls-ffi-test (UNIX)
254+
# Run the rustls-ffi client binary.
255+
- name: Run rustls-ffi client (UNIX)
246256
if: matrix.os != 'windows-latest'
247-
run: ./build/rustls-ffi-test
257+
env:
258+
RUSTLS_PLATFORM_VERIFIER: 1
259+
run: ./build/tests/client example.com 443 / 1
248260
# Run the rustls-ffi-test binary.
249261
# On Windows it's in a different output location under build.
250-
- name: Run rustls-ffi-test (Windows)
262+
- name: Run rustls-ffi client (Windows)
251263
if: matrix.os == 'windows-latest'
252-
run: ./build/Release/rustls-ffi-test.exe
264+
env:
265+
RUSTLS_PLATFORM_VERIFIER: 1
266+
run: .\build\tests\Release\client.exe example.com 443 / 1
253267

254268
test-deb:
255269
name: "Test Linux Deb (${{ matrix.os }})"
@@ -259,10 +273,10 @@ jobs:
259273
matrix:
260274
os: [ ubuntu-latest, ubuntu-20.04 ]
261275
steps:
262-
- name: Checkout rustls-ffi-test sources
276+
- name: Checkout sources
263277
uses: actions/checkout@v4
264278
with:
265-
repository: 'cpu/rustls-ffi-test'
279+
persist-credentials: false
266280
- name: Download rustls-ffi deb artifact
267281
uses: actions/download-artifact@v4
268282
with:
@@ -278,10 +292,12 @@ jobs:
278292
pkg-config --libs rustls
279293
# Set up the cmake build, no pkg-config ENV overrides needed.
280294
- name: Setup cmake build
281-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
282-
# Build the rustls-ffi-test binary.
283-
- name: Build rustls-ffi-test
295+
run: cmake -S librustls -B build -DCMAKE_BUILD_TYPE=Release -DFORCE_SYSTEM_RUSTLS=ON
296+
# Build the client and server binaries
297+
- name: Build rustls-ffi client/server
284298
run: cmake --build build -v
285-
# Run the rustls-ffi-test binary.
286-
- name: Run rustls-ffi-test
287-
run: ./build/rustls-ffi-test
299+
# Run the rustls-ffi client binary.
300+
- name: Run rustls-ffi client
301+
env:
302+
RUSTLS_PLATFORM_VERIFIER: 1
303+
run: ./build/tests/client example.com 443 / 1

librustls/cmake/options.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
7676
FORCE
7777
)
7878
endif()
79+
80+
# Useful for testing the client/server examples with a pre-built rustls-ffi.
81+
option(
82+
FORCE_SYSTEM_RUSTLS
83+
"Require system-installed rustls-ffi, never build"
84+
OFF
85+
)

librustls/cmake/rust.cmake

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
include(ExternalProject)
22
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/rust)
33

4-
ExternalProject_Add(
5-
rustls-ffi
6-
DOWNLOAD_COMMAND ""
7-
CONFIGURE_COMMAND ""
8-
BUILD_COMMAND
9-
cargo capi build --locked ${CARGO_FEATURES}
10-
"$<IF:$<CONFIG:Release>,--release,-->"
11-
# Rely on cargo checking timestamps, rather than tell CMake where every
12-
# output is.
13-
BUILD_ALWAYS true
14-
INSTALL_COMMAND
15-
cargo capi install --libdir=lib --prefix=${CMAKE_BINARY_DIR}/rust
16-
--locked ${CARGO_FEATURES} "$<IF:$<CONFIG:Release>,--release,--debug>"
17-
# Run cargo test with --quiet because msbuild will treat the presence
18-
# of "error" in stdout as an error, and we have some test functions that
19-
# end in "_error". Quiet mode suppresses test names, so this is a
20-
# sufficient workaround.
21-
TEST_COMMAND
22-
cargo test --locked ${CARGO_FEATURES}
23-
"$<IF:$<CONFIG:Release>,--release,-->" --quiet
24-
)
4+
if(FORCE_SYSTEM_RUSTLS)
5+
find_package(PkgConfig REQUIRED)
6+
pkg_check_modules(RUSTLS_FFI REQUIRED rustls)
7+
8+
if(NOT RUSTLS_FFI_FOUND)
9+
message(FATAL_ERROR "System rustls-ffi required but not found")
10+
endif()
11+
12+
message(STATUS "RUSTLS_FFI_INCLUDE_DIRS: ${RUSTLS_FFI_INCLUDE_DIRS}")
13+
message(STATUS "RUSTLS_FFI_LIBRARY_DIRS: ${RUSTLS_FFI_LIBRARY_DIRS}")
14+
message(STATUS "RUSTLS_FFI_LIBRARIES: ${RUSTLS_FFI_LIBRARIES}")
15+
else()
16+
ExternalProject_Add(
17+
rustls-ffi
18+
DOWNLOAD_COMMAND ""
19+
CONFIGURE_COMMAND ""
20+
BUILD_COMMAND
21+
cargo capi build --locked ${CARGO_FEATURES}
22+
"$<IF:$<CONFIG:Release>,--release,-->"
23+
# Rely on cargo checking timestamps, rather than tell CMake where every
24+
# output is.
25+
BUILD_ALWAYS true
26+
INSTALL_COMMAND
27+
cargo capi install --libdir=lib --prefix=${CMAKE_BINARY_DIR}/rust
28+
--locked ${CARGO_FEATURES}
29+
"$<IF:$<CONFIG:Release>,--release,--debug>"
30+
# Run cargo test with --quiet because msbuild will treat the presence
31+
# of "error" in stdout as an error, and we have some test functions that
32+
# end in "_error". Quiet mode suppresses test names, so this is a
33+
# sufficient workaround.
34+
TEST_COMMAND
35+
cargo test --locked ${CARGO_FEATURES}
36+
"$<IF:$<CONFIG:Release>,--release,-->" --quiet
37+
)
38+
endif()
2539

2640
add_custom_target(
2741
cbindgen

librustls/tests/CMakeLists.txt

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,62 +46,79 @@ endif()
4646
function(test_binary target_name)
4747
add_executable(${target_name})
4848
target_sources(${target_name} PRIVATE ${target_name}.c common.c common.h)
49-
add_dependencies(${target_name} rustls-ffi)
50-
51-
target_include_directories(
52-
${target_name}
53-
PRIVATE ${CMAKE_BINARY_DIR}/rust/include
54-
)
5549

5650
if(WIN32)
57-
target_compile_options(${target_name} PRIVATE ${sanitizer_flags})
5851
target_link_libraries(
5952
${target_name}
60-
"${CMAKE_BINARY_DIR}/rust/lib/rustls.${lib_extension}"
53+
PRIVATE
54+
advapi32.lib
55+
bcrypt.lib
56+
crypt32.lib
57+
cryptnet.lib
58+
kernel32.lib
59+
ncrypt.lib
60+
bcrypt.lib
61+
advapi32.lib
62+
legacy_stdio_definitions.lib
63+
kernel32.lib
64+
advapi32.lib
65+
kernel32.lib
66+
ntdll.lib
67+
userenv.lib
68+
ws2_32.lib
69+
synchronization.lib
70+
kernel32.lib
71+
ws2_32.lib
72+
kernel32.lib
73+
msvcrt.lib
6174
)
62-
target_link_libraries(
75+
endif()
76+
77+
if(RUSTLS_FFI_FOUND)
78+
target_include_directories(
6379
${target_name}
64-
advapi32.lib
65-
bcrypt.lib
66-
crypt32.lib
67-
cryptnet.lib
68-
kernel32.lib
69-
ncrypt.lib
70-
bcrypt.lib
71-
advapi32.lib
72-
legacy_stdio_definitions.lib
73-
kernel32.lib
74-
advapi32.lib
75-
kernel32.lib
76-
ntdll.lib
77-
userenv.lib
78-
ws2_32.lib
79-
synchronization.lib
80-
kernel32.lib
81-
ws2_32.lib
82-
kernel32.lib
83-
msvcrt.lib
80+
PRIVATE ${RUSTLS_FFI_INCLUDE_DIRS}
8481
)
85-
set_property(
86-
TARGET ${target_name}
87-
PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
82+
target_link_directories(
83+
${target_name}
84+
PRIVATE ${RUSTLS_FFI_LIBRARY_DIRS}
8885
)
89-
elseif(UNIX)
90-
target_compile_options(${target_name} PRIVATE ${sanitizer_flags})
91-
target_link_options(${target_name} PRIVATE ${sanitizer_flags})
92-
target_link_libraries(
86+
target_link_libraries(${target_name} PRIVATE ${RUSTLS_FFI_LIBRARIES})
87+
else()
88+
add_dependencies(${target_name} rustls-ffi)
89+
90+
target_include_directories(
9391
${target_name}
94-
"${CMAKE_BINARY_DIR}/rust/lib/librustls.${lib_extension}"
92+
PRIVATE ${CMAKE_BINARY_DIR}/rust/include
9593
)
96-
if(CERT_COMPRESSION)
97-
target_link_libraries(${target_name} m)
98-
endif()
99-
if(APPLE)
94+
95+
if(WIN32)
96+
target_compile_options(${target_name} PRIVATE ${sanitizer_flags})
97+
target_link_libraries(
98+
${target_name}
99+
PRIVATE "${CMAKE_BINARY_DIR}/rust/lib/rustls.${lib_extension}"
100+
)
101+
set_property(
102+
TARGET ${target_name}
103+
PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
104+
)
105+
elseif(UNIX)
106+
target_compile_options(${target_name} PRIVATE ${sanitizer_flags})
107+
target_link_options(${target_name} PRIVATE ${sanitizer_flags})
100108
target_link_libraries(
101109
${target_name}
102-
"-framework Foundation"
103-
"-framework Security"
110+
"${CMAKE_BINARY_DIR}/rust/lib/librustls.${lib_extension}"
104111
)
112+
if(CERT_COMPRESSION)
113+
target_link_libraries(${target_name} m)
114+
endif()
115+
if(APPLE)
116+
target_link_libraries(
117+
${target_name}
118+
"-framework Foundation"
119+
"-framework Security"
120+
)
121+
endif()
105122
endif()
106123
endif()
107124
endfunction()

0 commit comments

Comments
 (0)