diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 173c88d1..01ab6840 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,15 +85,40 @@ jobs: working-directory: build shell: bash run: make stop - - name: Build examples - shell: bash - env: - CC: ${{ matrix.compiler }} + + install: + name: Installation tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 + - name: Prepare + uses: awalsh128/cache-apt-pkgs-action@a6c3917cc929dd0345bfb2d3feaf9101823370ad # v1.4.2 + with: + packages: libevent-dev libuv1-dev libev-dev libglib2.0-dev + version: 1.0 + - name: Install libvalkey using Makefile + run: | + make USE_SSL=1 DESTDIR=${{ github.workspace }}/make-install install + - name: Install libvalkey using CMake + run: | + mkdir build && cd build + cmake -DDISABLE_TESTS=ON -DENABLE_SSL=ON .. + make DESTDIR=${{ github.workspace }}/cmake-install install + - name: Build examples with Makefile using a Makefile-installed libvalkey + run: | + make CFLAGS="-I${{ github.workspace }}/make-install/usr/local/include" \ + STLIBNAME="${{ github.workspace }}/make-install/usr/local/lib/libvalkey.a" \ + -C examples + - name: Build examples with Makefile using a CMake-installed libvalkey + run: | + make CFLAGS="-I${{ github.workspace }}/cmake-install/usr/local/include" \ + STLIBNAME="${{ github.workspace }}/cmake-install/usr/local/lib/libvalkey.a" \ + -C examples + - name: Build examples with CMake using a CMake-installed libvalkey run: | - examples/using_cmake_externalproject/build.sh - examples/using_cmake_separate/build.sh - examples/using_cmake_and_make_mixed/build.sh - examples/using_make/build.sh + cd examples && mkdir build && cd build + cmake -DCMAKE_PREFIX_PATH=${{ github.workspace }}/cmake-install/usr/local -DENABLE_SSL=ON .. + make macos: name: macOS diff --git a/CMakeLists.txt b/CMakeLists.txt index f23d5a84..566d9a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,9 +22,7 @@ OPTION(ENABLE_SSL "Build valkey_ssl for SSL support" OFF) OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF) OPTION(ENABLE_EXAMPLES "Enable building valkey examples" OFF) option(ENABLE_IPV6_TESTS "Enable IPv6 tests requiring special prerequisites" OFF) -# Historically, the NuGet file was always install; default -# to ON for those who rely on that historical behaviour. -OPTION(ENABLE_NUGET "Install NuGET packaging details" ON) +OPTION(ENABLE_NUGET "Install NuGET packaging details" OFF) # valkey requires C99 SET(CMAKE_C_STANDARD 99) @@ -72,7 +70,7 @@ ENDIF() TARGET_INCLUDE_DIRECTORIES(valkey PUBLIC - $ + $ $ ) @@ -122,11 +120,8 @@ if (ENABLE_NUGET) DESTINATION build/native) endif() -INSTALL(FILES valkey.h read.h sds.h async.h alloc.h sockcompat.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/valkey) - -INSTALL(DIRECTORY adapters - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/valkey) +install(DIRECTORY include/valkey + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) @@ -173,7 +168,7 @@ IF(ENABLE_SSL) TARGET_INCLUDE_DIRECTORIES(valkey_ssl PRIVATE - $ + $ $ ) @@ -207,9 +202,6 @@ IF(ENABLE_SSL) CONFIGURATIONS Debug RelWithDebInfo) endif() - INSTALL(FILES valkey_ssl.h valkeycluster_ssl.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/valkey) - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/valkey_ssl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f8c7d849..25d1939f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,8 +1,16 @@ cmake_minimum_required(VERSION 3.0.0) project(examples LANGUAGES C) -# Add path to enable includes -include_directories(${CMAKE_SOURCE_DIR}/include) +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + # This CMakeLists.txt is used standalone to build the examples. + # Find required valkey package to get include paths. + find_package(valkey REQUIRED) + find_package(valkey_ssl QUIET) +else() + # This CMakeLists.txt is included, most likely from libvalkey's project + # CMakeLists.txt. Add path to enable includes. + include_directories(${CMAKE_SOURCE_DIR}/include) +endif() # Check for GLib find_package(PkgConfig QUIET) @@ -11,7 +19,7 @@ if(PkgConfig_FOUND) if(GLIB2_FOUND) add_executable(example-async-glib async-glib.c) target_include_directories(example-async-glib PUBLIC ${GLIB2_INCLUDE_DIRS}) - target_link_libraries(example-async-glib valkey ${GLIB2_LIBRARIES}) + target_link_libraries(example-async-glib valkey::valkey ${GLIB2_LIBRARIES}) endif() endif() @@ -20,72 +28,72 @@ find_path(LIBEV ev.h ENV LIBEV_INCLUDE_DIR) if(LIBEV) add_executable(example-async-libev async-libev.c) - target_link_libraries(example-async-libev valkey ev) + target_link_libraries(example-async-libev valkey::valkey ev) endif() find_path(LIBEVENT event.h) if(LIBEVENT) add_executable(example-async-libevent async-libevent.c) - target_link_libraries(example-async-libevent valkey event) + target_link_libraries(example-async-libevent valkey::valkey event) if(ENABLE_SSL) add_executable(example-async-libevent-ssl async-libevent-ssl.c) - target_link_libraries(example-async-libevent-ssl valkey valkey_ssl event) + target_link_libraries(example-async-libevent-ssl valkey::valkey valkey::valkey_ssl event) endif() endif() find_path(LIBHV hv/hv.h) if(LIBHV) add_executable(example-async-libhv async-libhv.c) - target_link_libraries(example-async-libhv valkey hv) + target_link_libraries(example-async-libhv valkey::valkey hv) endif() find_path(LIBUV uv.h) if(LIBUV) add_executable(example-async-libuv async-libuv.c) - target_link_libraries(example-async-libuv valkey uv) + target_link_libraries(example-async-libuv valkey::valkey uv) endif() find_path(LIBSDEVENT systemd/sd-event.h) if(LIBSDEVENT) add_executable(example-async-libsdevent async-libsdevent.c) - target_link_libraries(example-async-libsdevent valkey systemd) + target_link_libraries(example-async-libsdevent valkey::valkey systemd) endif() if(APPLE) find_library(CF CoreFoundation) add_executable(example-async-macosx async-macosx.c) - target_link_libraries(example-async-macosx valkey ${CF}) + target_link_libraries(example-async-macosx valkey::valkey ${CF}) endif() if(ENABLE_SSL) add_executable(example-blocking-ssl blocking-ssl.c) - target_link_libraries(example-blocking-ssl valkey valkey_ssl) + target_link_libraries(example-blocking-ssl valkey::valkey valkey::valkey_ssl) endif() add_executable(example-blocking blocking.c) -target_link_libraries(example-blocking valkey) +target_link_libraries(example-blocking valkey::valkey) add_executable(example-blocking-push blocking-push.c) -target_link_libraries(example-blocking-push valkey) +target_link_libraries(example-blocking-push valkey::valkey) if(LIBEVENT) add_executable(example-cluster-async cluster-async.c) - target_link_libraries(example-cluster-async valkey event) + target_link_libraries(example-cluster-async valkey::valkey event) if(ENABLE_SSL) add_executable(example-cluster-async-tls cluster-async-tls.c) - target_link_libraries(example-cluster-async-tls valkey valkey_ssl event) + target_link_libraries(example-cluster-async-tls valkey::valkey valkey::valkey_ssl event) endif() add_executable(example-cluster-clientside-caching-async cluster-clientside-caching-async.c) - target_link_libraries(example-cluster-clientside-caching-async valkey event) + target_link_libraries(example-cluster-clientside-caching-async valkey::valkey event) endif() add_executable(example-cluster-simple cluster-simple.c) -target_link_libraries(example-cluster-simple valkey) +target_link_libraries(example-cluster-simple valkey::valkey) if(ENABLE_SSL) add_executable(example-cluster-tls cluster-tls.c) - target_link_libraries(example-cluster-tls valkey valkey_ssl) + target_link_libraries(example-cluster-tls valkey::valkey valkey::valkey_ssl) endif() diff --git a/examples/Makefile b/examples/Makefile index d8dc5baf..8669d316 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,8 +1,8 @@ CC?=gcc CXX?=g++ -CFLAGS=-Wall -Wextra -g -O2 -I../include -STLIBNAME=../lib/libvalkey.a +CFLAGS?=-Wall -Wextra -g -O2 -I../include +STLIBNAME?=../lib/libvalkey.a # Define examples EXAMPLES=example-blocking example-blocking-push example-async-libevent \ diff --git a/libvalkeycluster/examples/using_cmake_and_make_mixed/build.sh b/libvalkeycluster/examples/using_cmake_and_make_mixed/build.sh deleted file mode 100755 index 8b747d11..00000000 --- a/libvalkeycluster/examples/using_cmake_and_make_mixed/build.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -set -e - -# This script builds and installs hiredis using GNU Make and hiredis-cluster using CMake. -# The shared library variants are used when building the examples. - -script_dir=$(realpath "${0%/*}") -repo_dir=$(git rev-parse --show-toplevel) - -# Download hiredis -hiredis_version=1.1.0 -curl -L https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz | tar -xz -C ${script_dir} - -# Build and install downloaded hiredis using GNU Make -make -C ${script_dir}/hiredis-${hiredis_version} \ - USE_SSL=1 \ - DESTDIR=${script_dir}/install \ - all install - - -# Build and install hiredis-cluster from the repo using CMake. -mkdir -p ${script_dir}/hiredis_cluster_build -cd ${script_dir}/hiredis_cluster_build -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDISABLE_TESTS=ON -DENABLE_SSL=ON -DDOWNLOAD_HIREDIS=OFF \ - -DCMAKE_PREFIX_PATH=${script_dir}/install/usr/local \ - ${repo_dir} -make DESTDIR=${script_dir}/install clean install - - -# Build example binaries by providing shared libraries -make -C ${repo_dir} CFLAGS="-I${script_dir}/install/usr/local/include" \ - LDFLAGS="-lhiredis_cluster -lhiredis_cluster_ssl -lhiredis -lhiredis_ssl \ - -L${script_dir}/install/usr/local/lib/ \ - -Wl,-rpath=${script_dir}/install/usr/local/lib/" \ - USE_SSL=1 \ - clean examples diff --git a/libvalkeycluster/examples/using_cmake_externalproject/CMakeLists.txt b/libvalkeycluster/examples/using_cmake_externalproject/CMakeLists.txt deleted file mode 100644 index ea8b2e49..00000000 --- a/libvalkeycluster/examples/using_cmake_externalproject/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -cmake_minimum_required(VERSION 3.11) -project(hiredis_cluster_externalproject) -include(ExternalProject) - -ExternalProject_Add(hiredis - PREFIX hiredis - GIT_REPOSITORY https://github.com/redis/hiredis - GIT_TAG v1.0.2 - CMAKE_ARGS - "-DCMAKE_C_FLAGS:STRING=-std=c99" - "-DENABLE_SSL:BOOL=ON" - "-DDISABLE_TESTS:BOOL=ON" - "-DCMAKE_BUILD_TYPE:STRING=Debug" - "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/install" -) - -ExternalProject_Add(hiredis_cluster - PREFIX hiredis_cluster - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." - CMAKE_ARGS - "-DENABLE_SSL:BOOL=ON" - "-DDISABLE_TESTS:BOOL=ON" - "-DDOWNLOAD_HIREDIS:BOOL=OFF" - "-DCMAKE_BUILD_TYPE:STRING=Debug" - "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/install" - "-DCMAKE_PREFIX_PATH:PATH=${CMAKE_CURRENT_BINARY_DIR}/install/usr/local" - DEPENDS hiredis -) - -ExternalProject_Add(examples - PREFIX examples - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../src" - INSTALL_COMMAND "" - CMAKE_ARGS - "-DENABLE_SSL:BOOL=ON" - "-DCMAKE_BUILD_TYPE:STRING=Debug" - "-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/install" - "-DCMAKE_PREFIX_PATH:PATH=${CMAKE_CURRENT_BINARY_DIR}/install/usr/local" - DEPENDS hiredis_cluster -) diff --git a/libvalkeycluster/examples/using_cmake_externalproject/build.sh b/libvalkeycluster/examples/using_cmake_externalproject/build.sh deleted file mode 100755 index 0c2e2d20..00000000 --- a/libvalkeycluster/examples/using_cmake_externalproject/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -set -e - -# This script builds and installs hiredis and hiredis-cluster using -# CMakes ExternalProject module. -# The shared library variants are used when building the examples. - -script_dir=$(realpath "${0%/*}") - -# Prepare a build directory -mkdir -p ${script_dir}/build -cd ${script_dir}/build - -# Generate makefiles -cmake .. - -# Build -VERBOSE=1 make diff --git a/libvalkeycluster/examples/using_cmake_separate/build.sh b/libvalkeycluster/examples/using_cmake_separate/build.sh deleted file mode 100755 index dbf254ac..00000000 --- a/libvalkeycluster/examples/using_cmake_separate/build.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -set -e - -# This script builds and installs hiredis and hiredis-cluster as separate -# steps using CMake. -# The shared library variants are used when building the examples. - -script_dir=$(realpath "${0%/*}") -repo_dir=$(git rev-parse --show-toplevel) - -# Download hiredis -hiredis_version=1.1.0 -curl -L https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz | tar -xz -C ${script_dir} - -# Build and install downloaded hiredis using CMake -mkdir -p ${script_dir}/hiredis_build -cd ${script_dir}/hiredis_build -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDISABLE_TESTS=ON -DENABLE_SSL=ON \ - -DCMAKE_C_FLAGS="-std=c99" \ - ${script_dir}/hiredis-${hiredis_version} -make DESTDIR=${script_dir}/install install - - -# Build and install hiredis-cluster from the repo using CMake. -mkdir -p ${script_dir}/hiredis_cluster_build -cd ${script_dir}/hiredis_cluster_build -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDISABLE_TESTS=ON -DENABLE_SSL=ON -DDOWNLOAD_HIREDIS=OFF \ - -DCMAKE_PREFIX_PATH=${script_dir}/install/usr/local \ - ${repo_dir} -make DESTDIR=${script_dir}/install clean install - - -# Build examples using headers and libraries installed in previous steps. -mkdir -p ${script_dir}/example_build -cd ${script_dir}/example_build -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DENABLE_SSL=ON \ - -DCMAKE_PREFIX_PATH=${script_dir}/install/usr/local \ - ${script_dir}/../src -make diff --git a/libvalkeycluster/examples/using_make/build.sh b/libvalkeycluster/examples/using_make/build.sh deleted file mode 100755 index 54e7db13..00000000 --- a/libvalkeycluster/examples/using_make/build.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh -set -e - -# This script builds and installs hiredis and hiredis-cluster using GNU Make directly. -# The static library variants are used when building the examples. - -script_dir=$(realpath "${0%/*}") -repo_dir=$(git rev-parse --show-toplevel) - -# Download hiredis -hiredis_version=1.0.2 -curl -L https://github.com/redis/hiredis/archive/v${hiredis_version}.tar.gz | tar -xz -C ${script_dir} - -# Build and install downloaded hiredis using GNU Make -make -C ${script_dir}/hiredis-${hiredis_version} \ - USE_SSL=1 \ - DESTDIR=${script_dir}/install \ - all install - - -# Build and install hiredis-cluster from the repo using GNU Make -make -C ${repo_dir} \ - CFLAGS="-I${script_dir}/install/usr/local/include" \ - LDFLAGS="-L${script_dir}/install/usr/local/lib" \ - USE_SSL=1 \ - DESTDIR=${script_dir}/install \ - clean install - - -# Build example binaries by providing static libraries -make -C ${repo_dir} CFLAGS="-I${script_dir}/install/usr/local/include" \ - LDFLAGS="${script_dir}/install/usr/local/lib/libhiredis_cluster.a \ - ${script_dir}/install/usr/local/lib/libhiredis_cluster_ssl.a \ - ${script_dir}/install/usr/local/lib/libhiredis.a \ - ${script_dir}/install/usr/local/lib/libhiredis_ssl.a" \ - USE_SSL=1 \ - clean examples - - -# Run simple example: -# ./examples/hiredis-cluster-example -# -# To get a simple Redis Cluster to run towards: -# docker run --name docker-cluster -d -p 7000-7006:7000-7006 "bjosv/redis-cluster:latest" -# - -# Run TLS/SSL example: -# ./examples/hiredis-cluster-example-tls -# -# Prepare a Redis Cluster to run towards: -# openssl genrsa -out ca.key 4096 -# openssl req -x509 -new -nodes -sha256 -key ca.key -days 3650 -subj '/CN=Redis Test CA' -out ca.crt -# openssl genrsa -out redis.key 2048 -# openssl req -new -sha256 -key redis.key -subj '/CN=Redis Server Test Cert' | openssl x509 -req -sha256 -CA ca.crt -CAkey ca.key -CAserial ca.txt -CAcreateserial -days 365 -out redis.crt -# openssl genrsa -out client.key 2048 -# openssl req -new -sha256 -key client.key -subj '/CN=Redis Client Test Cert' | openssl x509 -req -sha256 -CA ca.crt -CAkey ca.key -CAserial ca.txt -CAcreateserial -days 365 -out client.crt -# -# chmod 777 redis.key -# -# docker run --name redis-tls-1 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7301 -# docker run --name redis-tls-2 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7302 -# docker run --name redis-tls-3 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7303 -# docker run --name redis-tls-4 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7304 -# docker run --name redis-tls-5 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7305 -# docker run --name redis-tls-6 -d --net=host -v $PWD:/tls:ro redis:6.0.9 redis-server --cluster-enabled yes --tls-cluster yes --port 0 --tls-ca-cert-file /tls/ca.crt --tls-cert-file /tls/redis.crt --tls-key-file /tls/redis.key --tls-port 7306 -# -# echo 'yes' | docker run --name redis-cli-tls -i --rm --net=host -v $PWD:/tls:ro redis:6.0.9 redis-cli --cluster create --tls --cacert /tls/ca.crt --cert /tls/redis.crt --key /tls/redis.key 127.0.0.1:7301 127.0.0.1:7302 127.0.0.1:7303 127.0.0.1:7304 127.0.0.1:7305 127.0.0.1:7306 --cluster-replicas 1