Skip to content

Commit 8736fcd

Browse files
committed
ci: add Linux pkg-config/.so test coverage
A new `Makefile.pkg-config` is added that can be used on UNIX machines with `pkg-config`. It is a slimmed down copy of `Makefile` that: * Removes the development targets (`format`, etc). * Removes details specific to static linking. * Uses `cargo cinstall` for the install target. * Adds the correct `CFLAGS`/`LDFLAGS` that `pkg-config` tells us are necessary based on the `.pc` file that `cargo-c` writes. * Runs the integration tests with the dynamically linked client/server examples. A new CI workflow (`pkg-config.yaml`) is added that only runs on ubuntu-latest (with both `clang` and `gcc`) that: * Installs stable rust. * Installs `cargo-c`. * Installs the lib to a tmp dir using `cargo-c`. * Builds the client/server examples using `pkg-config` to dynamically link `rustls`. * Verify the binaries aren't statically linking `rustls`. * Run the client/server integration tests. The existing `cargo-c` coverage is removed from the `test.yaml` workflow since it's now duplicative with this new workflow.
1 parent f935f30 commit 8736fcd

File tree

3 files changed

+102
-8
lines changed

3 files changed

+102
-8
lines changed

.github/workflows/pkg-config.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: pkg-config
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
pull_request:
9+
merge_group:
10+
schedule:
11+
- cron: '15 12 * * 3'
12+
13+
jobs:
14+
build:
15+
name: Build+test
16+
runs-on: ubuntu-latest
17+
env:
18+
PREFIX: /tmp/librustls
19+
strategy:
20+
matrix:
21+
cc: [clang, gcc]
22+
steps:
23+
- name: Checkout sources
24+
uses: actions/checkout@v4
25+
with:
26+
persist-credentials: false
27+
28+
- name: Install stable toolchain
29+
uses: dtolnay/rust-toolchain@stable
30+
31+
- name: Install cargo-c
32+
env:
33+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
34+
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
35+
run: |
36+
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
37+
38+
- name: Install the library
39+
run: make --file=Makefile.pkg-config PREFIX=${PREFIX} install
40+
41+
- name: Build the client/server examples
42+
run: PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig make --file=Makefile.pkg-config
43+
44+
- name: Verify client is dynamically linked
45+
run: LD_LIBRARY_PATH=$PREFIX/lib ldd target/client | grep "rustls"
46+
47+
- name: Verify server is dynamically linked
48+
run: LD_LIBRARY_PATH=$PREFIX/lib ldd target/server | grep "rustls"
49+
50+
- name: Run the integration tests
51+
run: LD_LIBRARY_PATH=$PREFIX/lib make --file=Makefile.pkg-config integration

.github/workflows/test.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,7 @@ jobs:
220220
persist-credentials: false
221221
- name: Install rust toolchain
222222
uses: dtolnay/rust-toolchain@nightly
223-
- name: Install cargo-c
224-
env:
225-
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
226-
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
227-
run: |
228-
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
229-
- name: Build and test with cargo-c
230-
run: cargo capi test
223+
231224

232225
miri:
233226
name: Miri

Makefile.pkg-config

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Makefile for building & testing the client/server examples using pkg-config
2+
# and dynamically linking. For static linking see the default 'Makefile'.
3+
#
4+
# Example usage:
5+
# PREFIX=/tmp/librustls
6+
# make --file Makefile.pkg-config install PREFIX=$PREFIX
7+
# PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/ make --file Makefile.pkg-config
8+
# LD_LIBRARY_PATH=$PREFIX/lib make --file Makefile.pkg-config integration
9+
10+
CARGO ?= cargo
11+
CARGOFLAGS += --locked
12+
13+
CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
14+
PROFILE := release
15+
PREFIX=/usr/local
16+
17+
ifeq ($(CC), clang)
18+
CFLAGS += -fsanitize=address -fsanitize=undefined
19+
LDFLAGS += -fsanitize=address
20+
endif
21+
22+
ifeq ($(PROFILE), release)
23+
CFLAGS += -O3
24+
CARGOFLAGS += --release
25+
endif
26+
27+
all: target/client target/server
28+
29+
integration: all
30+
${CARGO} test --locked --test client_server -- --ignored
31+
32+
target:
33+
mkdir -p $@
34+
35+
install:
36+
cargo cinstall $(CARGOFLAGS) --prefix=$(PREFIX)
37+
38+
target/%.o: tests/%.c tests/common.h | target
39+
$(CC) -o $@ -c $< $(CFLAGS) $(shell pkg-config --cflags rustls)
40+
41+
target/client: target/client.o target/common.o
42+
$(CC) -o $@ $^ $(LDFLAGS) $(shell pkg-config --libs rustls)
43+
44+
target/server: target/server.o target/common.o
45+
$(CC) -o $@ $^ $(LDFLAGS) $(shell pkg-config --libs rustls)
46+
47+
clean:
48+
rm -rf target
49+
50+
.PHONY: all install clean integration

0 commit comments

Comments
 (0)