Skip to content

Commit 25d055d

Browse files
committed
cmake: support dynamic linking
This commit replaces the Makefile.pkg-config script that was testing using our client/server with a dynamically linked librustls on macOS and Linux. Now, the CMake based build script can be used for this purpose by activating `-DDYN_LINK=on` when configuring the cmake build. TODO: * Windows CI coverage for dyn linking (need to debug this)
1 parent 4dcd9e5 commit 25d055d

File tree

6 files changed

+57
-165
lines changed

6 files changed

+57
-165
lines changed

.github/workflows/pkg-config.yaml

-80
This file was deleted.

.github/workflows/test.yaml

+29-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
build:
15-
name: "Build+Test (${{ matrix.os }}, ${{ matrix.cc }}, ${{ matrix.crypto }}, ${{ matrix.rust }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }})"
15+
name: "Build+Test (${{ matrix.os }}, ${{ matrix.cc }}, ${{ matrix.rust }}, ${{ matrix.crypto }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
1616
runs-on: ${{ matrix.os }}
1717
strategy:
1818
matrix:
@@ -30,6 +30,12 @@ jobs:
3030
# Include a few MacOS and cert-compression builds to ensure they're tested without
3131
# bloating the matrix or slowing down CI.
3232
include:
33+
# Linux dyn link build
34+
- os: ubuntu-latest
35+
cc: clang
36+
crypto: aws-lc-rs
37+
rust: stable
38+
dyn_link: on
3339
# Linux cert compression build
3440
- os: ubuntu-latest
3541
cc: clang
@@ -42,6 +48,12 @@ jobs:
4248
crypto: aws-lc-rs
4349
rust: stable
4450
cert_compression: off
51+
# MacOS dyn link build
52+
- os: macos-latest
53+
cc: clang
54+
crypto: aws-lc-rs
55+
rust: stable
56+
dyn_link: on
4557
# MacOS cert compression build
4658
- os: macos-latest
4759
cc: clang
@@ -85,6 +97,7 @@ jobs:
8597
cmake \
8698
-DCRYPTO_PROVIDER=${{matrix.crypto}} \
8799
-DCERT_COMPRESSION=${{matrix.cert_compression}} \
100+
-DDYN_LINK=${{matrix.dyn_link}} \
88101
-DCMAKE_BUILD_TYPE=Debug \
89102
${{ matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || '' }} \
90103
-S . -B build
@@ -173,15 +186,21 @@ jobs:
173186
run: cmake --build build --target integration-test
174187

175188
test-windows:
176-
name: "Windows (${{ matrix.crypto }}, ${{ matrix.config }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }})"
189+
name: "Windows (${{ matrix.crypto }}, ${{ matrix.config }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
177190
runs-on: windows-latest
178191
strategy:
179192
matrix:
180193
crypto: [ aws-lc-rs, ring ]
181194
config: [ Debug, Release ]
182195
cert_compression: [ off ]
196+
dyn_link: [ off ]
183197
include:
184-
# Just one build with cert_compression on to reduce build times.
198+
# One build with dynamic linking.
199+
# TODO(@cpu): debug broken dyn-link build on Windows.
200+
# - crypto: aws-lc-rs
201+
# config: Release
202+
# dyn_link: on
203+
# One build with cert_compression.
185204
- crypto: aws-lc-rs
186205
config: Release
187206
cert_compression: on
@@ -202,12 +221,16 @@ jobs:
202221
with:
203222
arch: x64
204223

205-
# TODO(@cpu): install pre-built cargo-c similar to other platforms. This is slowww.
206224
- name: Install cargo-c
207-
run: cargo install cargo-c
225+
env:
226+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
227+
CARGO_C_FILE: cargo-c-windows-msvc.zip
228+
run: |
229+
curl -L "$env:LINK/$env:CARGO_C_FILE" -o cargo-c-windows-msvc.zip
230+
powershell -Command "Expand-Archive -Path cargo-c-windows-msvc.zip -DestinationPath $env:USERPROFILE\\.cargo\\bin -Force"
208231
209232
- name: Configure CMake
210-
run: cmake -DCRYPTO_PROVIDER="${{ matrix.crypto }}" -DCERT_COMPRESSION="${{ matrix.cert_compression }}" -S . -B build
233+
run: cmake -DCRYPTO_PROVIDER="${{ matrix.crypto }}" -DCERT_COMPRESSION="${{ matrix.cert_compression }}" -DDYN_LINK="${{ matrix.dyn_link }}" -S . -B build
211234

212235
- name: Build
213236
run: cmake --build build --config "${{ matrix.config }}"

Makefile.pkg-config

-71
This file was deleted.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ Use `-DCERT_COMPRESSION=on` to enable certificate compression.
215215

216216
Use `-DFIPS=on` to enable FIPS mode.
217217

218+
Use `-DDYN_LINK=on` to dynamically link Rustls to the test programs instead of
219+
statically linking (the default).
220+
218221
Use `cmake --build build --target integration_test` to build and run the
219222
client/server integration tests.
220223

cmake/options.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ option(
2020

2121
option(FIPS "Whether to enable aws-lc-rs and FIPS support")
2222

23+
option(DYN_LINK "Use dynamic linking for rustls library" OFF)
24+
25+
if(DYN_LINK AND FIPS AND (APPLE OR WIN32))
26+
message(
27+
FATAL_ERROR
28+
"Dynamic linking is not supported with FIPS on MacOS or Windows"
29+
)
30+
endif()
31+
2332
set(CARGO_FEATURES --no-default-features)
2433
if(CRYPTO_PROVIDER STREQUAL "aws-lc-rs")
2534
list(APPEND CARGO_FEATURES --features=aws-lc-rs)

tests/CMakeLists.txt

+16-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ else()
3232
set(sanitizer_flags "$<$<CONFIG:Debug>:-fsanitize=address>")
3333
endif()
3434

35+
set(lib_extension "a") # Static linking (default) for both MacOS and Linux
36+
if(WIN32 AND DYN_LINK)
37+
set(lib_extension "dll") # Dynamic linking for Windows
38+
elseif(WIN32)
39+
set(lib_extension "lib") # Static linking (default) for Windows
40+
elseif(APPLE AND DYN_LINK)
41+
set(lib_extension "dylib") # Dynamic linking for MacOS
42+
elseif(UNIX AND DYN_LINK)
43+
set(lib_extension "so") # Dynamic linking for Linux
44+
endif()
45+
3546
function(test_binary target_name)
3647
add_executable(${target_name})
3748
target_sources(${target_name} PRIVATE ${target_name}.c common.c common.h)
@@ -46,10 +57,10 @@ function(test_binary target_name)
4657
target_compile_options(${target_name} PRIVATE ${sanitizer_flags})
4758
target_link_libraries(
4859
${target_name}
49-
debug
50-
"${CMAKE_BINARY_DIR}/rust/lib/rustls.lib"
51-
optimized
52-
"${CMAKE_BINARY_DIR}/rust/lib/rustls.lib"
60+
"${CMAKE_BINARY_DIR}/rust/lib/rustls.${lib_extension}"
61+
)
62+
target_link_libraries(
63+
${target_name}
5364
advapi32.lib
5465
bcrypt.lib
5566
crypt32.lib
@@ -80,10 +91,7 @@ function(test_binary target_name)
8091
target_link_options(${target_name} PRIVATE ${sanitizer_flags})
8192
target_link_libraries(
8293
${target_name}
83-
debug
84-
"${CMAKE_BINARY_DIR}/rust/lib/librustls.a"
85-
optimized
86-
"${CMAKE_BINARY_DIR}/rust/lib/librustls.a"
94+
"${CMAKE_BINARY_DIR}/rust/lib/librustls.${lib_extension}"
8795
)
8896
if(CERT_COMPRESSION)
8997
target_link_libraries(${target_name} m)

0 commit comments

Comments
 (0)