Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small CMake related tweaks #532

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ jobs:
- os: macos-13
artifact: rustls-ffi-x86_64-macos
steps:
- name: Checkout rustls-ffi-test sources
- name: Checkout sources
uses: actions/checkout@v4
with:
repository: 'cpu/rustls-ffi-test'
persist-credentials: false
- name: Download rustls-ffi artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -176,19 +176,29 @@ jobs:
# the correct location that we extracted the archive. This seems more reliable
# than using `--define-prefix` - it seems to tack an extra 'lib/' subcomponent
# onto the include path that breaks the build.
- name: Fix pkg-config prefix
# We use bash shell explicitly to avoid PowerShell on Windows and to ensure we have 'sed'.
- name: Fix pkg-config prefix (UNIX)
if: runner.os != 'Windows'
shell: bash
# For further fun, sed isn't consistent between macOS and Linux.
run: |
case "${{ runner.os }}" in
"macOS")
sed -i '' "s|prefix=.*|prefix=${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
sed -i '' "s|prefix=.*|prefix=$(pwd)/${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
;;
*)
sed -i "s|prefix=.*|prefix=${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
sed -i "s|prefix=.*|prefix=$(pwd)/${{ matrix.artifact }}|" ${{ matrix.artifact }}/lib/pkgconfig/rustls.pc
;;
esac
- name: Fix pkg-config prefix (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$prefix = (Get-Location).Path + "/${{ matrix.artifact }}"
$prefix = $prefix -replace '\\', '/'

$content = Get-Content "${{ matrix.artifact }}\lib\pkgconfig\rustls.pc"
$content = $content -replace "prefix=.*", "prefix=$prefix"
Set-Content "${{ matrix.artifact }}\lib\pkgconfig\rustls.pc" $content
# Dump out what pkg-config says about the rustls package.
- name: Debug pkg-config
run: |
Expand All @@ -199,39 +209,43 @@ jobs:
# Set up the cmake build, overriding PKG_CONFIG_PATH to
# point to the extracted rustls-ffi archive.
- name: Setup cmake build (UNIX)
if: matrix.os != 'windows-latest'
if: runner.os != 'Windows'
env:
PKG_CONFIG_PATH: ${{ matrix.artifact }}/lib/pkgconfig
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
run: cmake -S librustls -B build -DCMAKE_BUILD_TYPE=Release -DFORCE_SYSTEM_RUSTLS=ON
# Set up the cmake build, overriding PKG_CONFIG_PATH to
# point to the extracted rustls-ffi archive.
#
# For Windows cmake needs some help finding the strawberry perl pkg-config
# that's installed in the runner's PATH.
- name: Setup cmake build (Windows)
if: matrix.os == 'windows-latest'
if: runner.os == 'Windows'
env:
PKG_CONFIG_PATH: ${{ matrix.artifact }}/lib/pkgconfig
run: cmake -DPKG_CONFIG_EXECUTABLE=C:\Strawberry\perl\bin\pkg-config.bat -S . -B build
# Build the rustls-ffi-test binary.
- name: Build rustls-ffi-test (UNIX)
if: matrix.os != 'windows-latest'
run: cmake -DPKG_CONFIG_EXECUTABLE=C:\Strawberry\perl\bin\pkg-config.bat -DFORCE_SYSTEM_RUSTLS=ON -S librustls -B build
# Build the client and server binaries
- name: Build rustls-ffi client/server (UNIX)
if: runner.os != 'Windows'
run: cmake --build build -v
# Build the rustls-ffi-test binary.
# Build the client and server binaries
# On Windows we need to specify a configuration to avoid a warning about using the default
# debug MSCRT runtime with a lib built with the release MSCRT runtime.
- name: Build rustls-ffi-test (Windows)
if: matrix.os == 'windows-latest'
- name: Build rustls-ffi client/server (Windows)
if: runner.os == 'Windows'
run: cmake --build build --config Release -v
# Run the rustls-ffi-test binary.
- name: Run rustls-ffi-test (UNIX)
if: matrix.os != 'windows-latest'
run: ./build/rustls-ffi-test
# Run the rustls-ffi client binary.
- name: Run rustls-ffi client (UNIX)
if: runner.os != 'Windows'
env:
RUSTLS_PLATFORM_VERIFIER: 1
run: ./build/tests/client example.com 443 / 1
# Run the rustls-ffi-test binary.
# On Windows it's in a different output location under build.
- name: Run rustls-ffi-test (Windows)
if: matrix.os == 'windows-latest'
run: ./build/Release/rustls-ffi-test.exe
- name: Run rustls-ffi client (Windows)
if: runner.os == 'Windows'
env:
RUSTLS_PLATFORM_VERIFIER: 1
run: .\build\tests\Release\client.exe example.com 443 / 1

test-deb:
name: "Test Linux Deb (${{ matrix.os }})"
Expand All @@ -241,10 +255,10 @@ jobs:
matrix:
os: [ ubuntu-latest, ubuntu-20.04 ]
steps:
- name: Checkout rustls-ffi-test sources
- name: Checkout sources
uses: actions/checkout@v4
with:
repository: 'cpu/rustls-ffi-test'
persist-credentials: false
- name: Download rustls-ffi deb artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -258,10 +272,12 @@ jobs:
pkg-config --libs rustls
# Set up the cmake build, no pkg-config ENV overrides needed.
- name: Setup cmake build
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
# Build the rustls-ffi-test binary.
- name: Build rustls-ffi-test
run: cmake -S librustls -B build -DCMAKE_BUILD_TYPE=Release -DFORCE_SYSTEM_RUSTLS=ON
# Build the client and server binaries
- name: Build rustls-ffi client/server
run: cmake --build build -v
# Run the rustls-ffi-test binary.
- name: Run rustls-ffi-test
run: ./build/rustls-ffi-test
# Run the rustls-ffi client binary.
- name: Run rustls-ffi client
env:
RUSTLS_PLATFORM_VERIFIER: 1
run: ./build/tests/client example.com 443 / 1
24 changes: 12 additions & 12 deletions .github/workflows/daily-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
uses: dtolnay/rust-toolchain@nightly

- name: Install cargo-c (Ubuntu)
if: matrix.os == 'ubuntu-latest'
if: runner.os == 'Linux'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
run: |
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin

- name: Install cargo-c (macOS)
if: matrix.os == 'macos-latest'
if: runner.os == 'macOS'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-macos.zip
Expand All @@ -46,7 +46,7 @@ jobs:
unzip cargo-c-macos.zip -d ~/.cargo/bin

- name: Install cargo-c (Windows)
if: matrix.os == 'windows-latest'
if: runner.os == 'Windows'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-windows-msvc.zip
Expand All @@ -57,15 +57,15 @@ jobs:
- name: Setup cmake build
run: |
cmake ${{
matrix.os != 'windows-latest' && '-DCMAKE_BUILD_TYPE=Release \' || ''
runner.os != 'Windows' && '-DCMAKE_BUILD_TYPE=Release \' || ''
}} ${{
matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || ''
runner.os == 'macOS' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || ''
}} -S librustls -B build

- name: Run platform-verifier connect test
run: |
cmake --build build --target connect-test ${{
matrix.os == 'windows-latest' && '--config Release' || ''
runner.os == 'Windows' && '--config Release' || ''
}}

ech:
Expand All @@ -85,15 +85,15 @@ jobs:
uses: dtolnay/rust-toolchain@nightly

- name: Install cargo-c (Ubuntu)
if: matrix.os == 'ubuntu-latest'
if: runner.os == 'Linux'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
run: |
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin

- name: Install cargo-c (macOS)
if: matrix.os == 'macos-latest'
if: runner.os == 'macOS'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-macos.zip
Expand All @@ -102,7 +102,7 @@ jobs:
unzip cargo-c-macos.zip -d ~/.cargo/bin

- name: Install cargo-c (Windows)
if: matrix.os == 'windows-latest'
if: runner.os == 'Windows'
env:
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
CARGO_C_FILE: cargo-c-windows-msvc.zip
Expand All @@ -113,17 +113,17 @@ jobs:
- name: Setup cmake build
run: |
cmake ${{
matrix.os != 'windows-latest' && '-DCMAKE_BUILD_TYPE=Release \' || ''
runner.os != 'Windows' && '-DCMAKE_BUILD_TYPE=Release \' || ''
}} ${{
matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || ''
runner.os == 'macOS' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || ''
}} -S librustls -B build

- name: Run ECH test
# NOTE: uses bash as the shell to allow for easy no-powershell tee/grep pipeline.
shell: bash
run: |
cmake --build build --target ech-test ${{
matrix.os == 'windows-latest' && '--config Release' || ''
runner.os == 'Windows' && '--config Release' || ''
}} | tee ech-test.log

- name: Verify ECH status
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
toolchain: ${{ matrix.rust }}

- name: Install cargo-c (Ubuntu)
if: matrix.os == 'ubuntu-latest'
if: runner.os == 'Linux'
env:
# Version picked for MSRV compat.
LINK: https://github.com/lu-zero/cargo-c/releases/download/v0.10.0
Expand All @@ -81,7 +81,7 @@ jobs:
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin

- name: Install cargo-c (macOS)
if: matrix.os == 'macos-latest'
if: runner.os == 'macOS'
env:
# Version picked for MSRV compat.
LINK: https://github.com/lu-zero/cargo-c/releases/download/v0.10.0
Expand All @@ -99,7 +99,7 @@ jobs:
-DCERT_COMPRESSION=${{matrix.cert_compression}} \
-DDYN_LINK=${{matrix.dyn_link}} \
-DCMAKE_BUILD_TYPE=Debug \
${{ matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || '' }} \
${{ runner.os == 'macOS' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || '' }} \
-S librustls -B build

- name: Build
Expand Down
19 changes: 19 additions & 0 deletions librustls/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# !!!!!! Important !!!!!!
#
# CMake is only used for building the **C client/server examples** and for other misc.
# developer tasks.
#
# If you want to build/install librustls, use `cargo capi install` instead.
# See the README[0] for more information.
#
# [0]: https://github.com/rustls/rustls-ffi?tab=readme-ov-file#build-rustls-ffi
#
# !!!!!! Important !!!!!!

cmake_minimum_required(VERSION 3.15)

project(rustls-ffi)

install(
CODE
"message(FATAL_ERROR
\"librustls installation via CMake is not supported. Use 'cargo capi install' instead.\n\"
\"See: https://github.com/rustls/rustls-ffi?tab=readme-ov-file#build-rustls-ffi\")"
)

# Use `cmake -LH $BUILD_DIR` to see all options/help.
# Use `cmake --build $BUILD_DIR --target help` to see all targets.

Expand Down
7 changes: 7 additions & 0 deletions librustls/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
FORCE
)
endif()

# Useful for testing the client/server examples with a pre-built rustls-ffi.
option(
FORCE_SYSTEM_RUSTLS
"Require system-installed rustls-ffi, never build"
OFF
)
56 changes: 35 additions & 21 deletions librustls/cmake/rust.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
include(ExternalProject)
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/rust)

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
)
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
Expand Down
Loading