Skip to content

Commit 73bf3fa

Browse files
committed
Add more comprehensive CI tests for packaging
Fixes #462
1 parent 70c8fe9 commit 73bf3fa

File tree

7 files changed

+143
-36
lines changed

7 files changed

+143
-36
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,34 +303,119 @@ jobs:
303303
cmake --build c/build --target blake3-example
304304
305305
# Currently only on x86.
306-
pkg_config_c_tests:
307-
name: pkg-config C tests TBB=${{ matrix.use_tbb }} BUILD_SHARED_LIBS=${{ matrix.shared_libs }} STDLIB=${{ matrix.stdlib }}
306+
packaging-cmake:
307+
name: CMake packaging tests - tbb=${{ matrix.use_tbb }} shared=${{ matrix.shared_libs }} os=${{ matrix.os }} cc=${{ matrix.toolchain.cc }} stdlib=${{ matrix.stdlib }}
308308
runs-on: ubuntu-latest
309309
strategy:
310310
fail-fast: false
311311
matrix:
312-
use_tbb: ["OFF", "ON"]
313-
shared_libs: ["OFF", "ON"]
314-
stdlib: ["libc++", "libstdc++"]
312+
use_tbb: [OFF, ON]
313+
shared_libs: [OFF, ON]
314+
os: [ubuntu-latest, macOS-latest]
315+
stdlib: [libc++, libstdc++]
316+
toolchain: [
317+
{ cc: clang, cxx: clang++ },
318+
{ cc: gcc, cxx: g++ }
319+
]
320+
exclude:
321+
- toolchain: { cc: gcc, cxx: g++ }
322+
os: macOS-latest
323+
- toolchain: { cc: gcc, cxx: g++ }
324+
stdlib: libc++
325+
env:
326+
CC: ${{ matrix.toolchain.cc }}
327+
CXX: ${{ matrix.toolchain.cxx }}
328+
CXXFLAGS: ${{ matrix.stdlib == 'libc++' && '-stdlib=libc++' || '' }}
315329
steps:
316330
- uses: actions/checkout@v4
317-
- name: update packages
331+
- name: install dependencies
318332
run: |
319333
sudo apt-get update
320334
sudo apt-get install ninja-build libtbb-dev libtbb12
321-
${{ matrix.stdlib != 'libc++' || 'sudo apt-get install libc++-dev libc++abi-dev' }}
322-
- name: configure cmake
335+
- name: install dependencies (libc++)
336+
if: matrix.stdlib == 'libc++'
337+
run: sudo apt-get install libc++-dev libc++abi-dev
338+
- name: configure libblake3
339+
run: cmake --fresh -S c -B c/build -G Ninja -DCMAKE_VERBOSE_MAKEFILE=1 "-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/target" "-DBLAKE3_USE_TBB=${{ matrix.use_tbb }}" "-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}" -DBLAKE3_EXAMPLES=0
340+
- name: build libblake3
341+
run: cmake --build c/build --target install
342+
- name: configure blake3-examples
343+
run: cmake --fresh -S c/examples -B c/examples/build -G Ninja -DCMAKE_VERBOSE_MAKEFILE=1 "-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/examples/target" "-DBLAKE3_DIR=${{ github.workspace }}/target/lib/cmake/blake3"
344+
- name: build blake3 examples
345+
run: cmake --build c/examples/build --target install
346+
- name: configure environment
347+
run: |
348+
echo "LD_LIBRARY_PATH=${{ github.workspace }}/target/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
349+
echo "PKG_CONFIG_PATH=${{ github.workspace }}/target/lib/pkgconfig" >> $GITHUB_ENV
350+
- name: test blake3-example
351+
run: |
352+
[ -f "${{ github.workspace }}/examples/target/bin/blake3-example" ]
353+
[ $(echo -n IETF | "${{ github.workspace }}/examples/target/bin/blake3-example") = "83a2de1ee6f4e6ab686889248f4ec0cf4cc5709446a682ffd1cbb4d6165181e2" ]
354+
- name: test blake3-example-tbb
355+
if: matrix.use_tbb == 'ON'
356+
run: |
357+
[ -f "${{ github.workspace }}/examples/target/bin/blake3-example-tbb" ]
358+
echo -n IETF > example-input
359+
[ $("${{ github.workspace }}/examples/target/bin/blake3-example-tbb" ./example-input) = "83a2de1ee6f4e6ab686889248f4ec0cf4cc5709446a682ffd1cbb4d6165181e2" ]
360+
361+
# Currently only on x86.
362+
packaging-pkg_config:
363+
name: pkg-config packaging tests - tbb=${{ matrix.use_tbb }} shared=${{ matrix.shared_libs }} os=${{ matrix.os }} cc=${{ matrix.toolchain.cc }} stdlib=${{ matrix.stdlib }}
364+
runs-on: ubuntu-latest
365+
strategy:
366+
fail-fast: false
367+
matrix:
368+
use_tbb: [OFF, ON]
369+
shared_libs: [OFF, ON]
370+
os: [ubuntu-latest, macOS-latest]
371+
stdlib: [libc++, libstdc++]
372+
toolchain: [
373+
{ cc: clang, cxx: clang++ },
374+
{ cc: gcc, cxx: g++ }
375+
]
376+
exclude:
377+
- toolchain: { cc: gcc, cxx: g++ }
378+
os: macOS-latest
379+
- toolchain: { cc: gcc, cxx: g++ }
380+
stdlib: libc++
381+
env:
382+
CC: ${{ matrix.toolchain.cc }}
383+
CXX: ${{ matrix.toolchain.cxx }}
384+
CXXFLAGS: ${{ matrix.stdlib == 'libc++' && '-stdlib=libc++' || '' }}
385+
steps:
386+
- uses: actions/checkout@v4
387+
- name: install dependencies
388+
run: |
389+
sudo apt-get update
390+
sudo apt-get install ninja-build libtbb-dev libtbb12
391+
- name: install dependencies (libc++)
392+
if: matrix.stdlib == 'libc++'
393+
run: sudo apt-get install libc++-dev libc++abi-dev
394+
- name: configure libblake3
395+
run: cmake --fresh -S c -B c/build -G Ninja -DCMAKE_VERBOSE_MAKEFILE=1 "-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/target" "-DBLAKE3_USE_TBB=${{ matrix.use_tbb }}" "-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}" -DBLAKE3_EXAMPLES=0
396+
- name: build libblake3
397+
run: cmake --build c/build --target install
398+
- name: configure environment
399+
run: |
400+
echo "LD_LIBRARY_PATH=${{ github.workspace }}/target/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
401+
echo "PKG_CONFIG_PATH=${{ github.workspace }}/target/lib/pkgconfig" >> $GITHUB_ENV
402+
- name: create bin directory
403+
run: mkdir -p ${{ github.workspace }}/target/bin
404+
- name: compile blake3-example
405+
run: gcc -O3 -o ${{ github.workspace }}/target/bin/blake3-example c/examples/example.c $(pkg-config --cflags --libs libblake3)
406+
- name: compile blake3-example-tbb
407+
if: matrix.use_tbb == 'ON'
408+
run: gcc -O3 -o ${{ github.workspace }}/target/bin/blake3-example-tbb c/examples/example_tbb.c $(pkg-config --cflags --libs libblake3)
409+
- name: test blake3-example
410+
run: |
411+
[ -f "${{ github.workspace }}/target/bin/blake3-example" ]
412+
[ $(echo -n IETF | "${{ github.workspace }}/target/bin/blake3-example") = "83a2de1ee6f4e6ab686889248f4ec0cf4cc5709446a682ffd1cbb4d6165181e2" ]
413+
- name: test blake3-example-tbb
414+
if: matrix.use_tbb == 'ON'
323415
run: |
324-
export CXXFLAGS=${{ matrix.stdlib == 'libc++' && '-stdlib=libc++' || '' }}
325-
export CC=${{ matrix.stdlib == 'libc++' && 'clang' || 'gcc' }}
326-
export CXX=${{ matrix.stdlib == 'libc++' && 'clang++' || 'g++' }}
327-
cmake --fresh -S c -B c/build -G Ninja -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/target "-DBLAKE3_USE_TBB=${{ matrix.use_tbb }}" "-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }}" -DCMAKE_VERBOSE_MAKEFILE=1
328-
- run: cmake --build c/build --target install
329-
- run: mkdir -p ${{ github.workspace }}/target/bin
330-
- run: echo "PKG_CONFIG_PATH=${{ github.workspace }}/target/lib/pkgconfig" >> $GITHUB_ENV
331-
- run: gcc -O3 -o ${{ github.workspace }}/target/bin/blake3-example c/example.c $(pkg-config --cflags --libs libblake3)
332-
- if: matrix.use_tbb == 'ON'
333-
run: gcc -O3 -o ${{ github.workspace }}/target/bin/blake3-example-tbb c/example_tbb.c $(pkg-config --cflags --libs libblake3)
416+
[ -f "${{ github.workspace }}/target/bin/blake3-example-tbb" ]
417+
echo -n IETF > example-input
418+
[ $("${{ github.workspace }}/target/bin/blake3-example-tbb" ./example-input) = "83a2de1ee6f4e6ab686889248f4ec0cf4cc5709446a682ffd1cbb4d6165181e2" ]
334419
335420
# Note that this jobs builds AArch64 binaries from an x86_64 host.
336421
build_apple_silicon:

c/Makefile.testing

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test_asm: CFLAGS += -DBLAKE3_TESTING -fsanitize=address,undefined
7575
test_asm: asm
7676
./test.py
7777

78-
example: example.c blake3.c blake3_dispatch.c blake3_portable.c $(ASM_TARGETS)
78+
example: examples/example.c blake3.c blake3_dispatch.c blake3_portable.c $(ASM_TARGETS)
7979
$(CC) $(CFLAGS) $(EXTRAFLAGS) $^ -o $@ $(LDFLAGS)
8080

8181
clean:

c/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ int main(void) {
4444
}
4545
```
4646
47-
The code above is included in this directory as `example.c`. If you're
47+
The code above is included in this directory as `examples/example.c`. If you're
4848
on x86\_64 with a Unix-like OS, you can compile a working binary like
4949
this:
5050
5151
```bash
52-
gcc -O3 -o example example.c blake3.c blake3_dispatch.c blake3_portable.c \
52+
gcc -O3 -o example examples/example.c blake3.c blake3_dispatch.c blake3_portable.c \
5353
blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S blake3_avx2_x86-64_unix.S \
5454
blake3_avx512_x86-64_unix.S
5555
```
@@ -388,11 +388,11 @@ Multithreading is available using [oneTBB], by compiling the optional C++
388388
support file [`blake3_tbb.cpp`](./blake3_tbb.cpp). For an example of using
389389
`mmap` (non-Windows) and `blake3_hasher_update_tbb` to get large-file
390390
performance on par with [`b3sum`](../b3sum), see
391-
[`example_tbb.c`](./example_tbb.c). You can build it like this:
391+
[`example_tbb.c`](./examples/example_tbb.c). You can build it like this:
392392

393393
```bash
394394
g++ -c -O3 -fno-exceptions -fno-rtti -DBLAKE3_USE_TBB -o blake3_tbb.o blake3_tbb.cpp
395-
gcc -O3 -o example_tbb -lstdc++ -ltbb -DBLAKE3_USE_TBB blake3_tbb.o example_tbb.c blake3.c \
395+
gcc -O3 -o example_tbb -lstdc++ -ltbb -DBLAKE3_USE_TBB blake3_tbb.o examples/example_tbb.c blake3.c \
396396
blake3_dispatch.c blake3_portable.c blake3_sse2_x86-64_unix.S blake3_sse41_x86-64_unix.S \
397397
blake3_avx2_x86-64_unix.S blake3_avx512_x86-64_unix.S
398398
```

c/cmake/BLAKE3/Examples.cmake

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
if(NOT WIN32)
2-
add_executable(blake3-example
3-
example.c)
4-
target_link_libraries(blake3-example PRIVATE blake3)
5-
install(TARGETS blake3-example)
6-
7-
if(BLAKE3_USE_TBB)
8-
add_executable(blake3-example-tbb
9-
example_tbb.c)
10-
target_link_libraries(blake3-example-tbb PRIVATE blake3)
11-
install(TARGETS blake3-example-tbb)
12-
endif()
13-
endif()
1+
add_subdirectory(${CMAKE_SOURCE_DIR}/examples)

c/examples/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
2+
3+
# respect C_EXTENSIONS OFF without explicitly setting C_STANDARD
4+
if (POLICY CMP0128)
5+
cmake_policy(SET CMP0128 NEW)
6+
endif()
7+
# mark_as_advanced does not implicitly create UNINITIALIZED cache entries
8+
if (POLICY CMP0102)
9+
cmake_policy(SET CMP0102 NEW)
10+
endif()
11+
12+
project(blake3-examples
13+
VERSION 1.8.1
14+
DESCRIPTION "BLAKE3 C examples"
15+
LANGUAGES C CXX ASM
16+
)
17+
18+
find_package(BLAKE3)
19+
20+
if(TARGET BLAKE3::blake3)
21+
if(NOT WIN32)
22+
add_executable(blake3-example
23+
example.c)
24+
target_link_libraries(blake3-example PUBLIC BLAKE3::blake3)
25+
install(TARGETS blake3-example)
26+
27+
if(BLAKE3_USE_TBB)
28+
add_executable(blake3-example-tbb
29+
example_tbb.c)
30+
target_link_libraries(blake3-example-tbb PUBLIC BLAKE3::blake3)
31+
install(TARGETS blake3-example-tbb)
32+
endif()
33+
endif()
34+
endif()
File renamed without changes.

0 commit comments

Comments
 (0)