
With this commit, users are able to build valkey using `CMake`. ## Example usage: Build `valkey-server` in Release mode with TLS enabled and using `jemalloc` as the allocator: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/tmp/valkey-install \ -DBUILD_MALLOC=jemalloc -DBUILD_TLS=1 make -j$(nproc) install # start valkey /tmp/valkey-install/bin/valkey-server ``` Build `valkey-unit-tests`: ```bash mkdir build-release-ut cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release \ -DBUILD_MALLOC=jemalloc -DBUILD_UNIT_TESTS=1 make -j$(nproc) # Run the tests ./bin/valkey-unit-tests ``` Current features supported by this PR: - Building against different allocators: (`jemalloc`, `tcmalloc`, `tcmalloc_minimal` and `libc`), e.g. to enable `jemalloc` pass `-DBUILD_MALLOC=jemalloc` to `cmake` - OpenSSL builds (to enable TLS, pass `-DBUILD_TLS=1` to `cmake`) - Sanitizier: pass `-DBUILD_SANITIZER=<address|thread|undefined>` to `cmake` - Install target + redis symbolic links - Build `valkey-unit-tests` executable - Standard CMake variables are supported. e.g. to install `valkey` under `/home/you/root` pass `-DCMAKE_INSTALL_PREFIX=/home/you/root` Why using `CMake`? To list *some* of the advantages of using `CMake`: - Superior IDE integrations: cmake generates the file `compile_commands.json` which is required by `clangd` to get a compiler accuracy code completion (in other words: your VScode will thank you) - Out of the source build tree: with the current build system, object files are created all over the place polluting the build source tree, the best practice is to build the project on a separate folder - Multiple build types co-existing: with the current build system, it is often hard to have multiple build configurations. With cmake you can do it easily: - It is the de-facto standard for C/C++ project these days More build examples: ASAN build: ```bash mkdir build-asan cd $_ cmake .. -DBUILD_SANITIZER=address -DBUILD_MALLOC=libc make -j$(nproc) ``` ASAN with jemalloc: ```bash mkdir build-asan-jemalloc cd $_ cmake .. -DBUILD_SANITIZER=address -DBUILD_MALLOC=jemalloc make -j$(nproc) ``` As seen by the previous examples, any combination is allowed and co-exist on the same source tree. ## Valkey installation With this new `CMake`, it is possible to install the binary by running `make install` or creating a package `make package` (currently supported on Debian like distros) ### Example 1: build & install using `make install`: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/valkey-install -DCMAKE_BUILD_TYPE=Release make -j$(nproc) install # valkey is now installed under $HOME/valkey-install ``` ### Example 2: create a `.deb` installer: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) package # ... CPack deb generation output sudo gdebi -n ./valkey_8.1.0_amd64.deb # valkey is now installed under /opt/valkey ``` ### Example 3: create installer for non Debian systems (e.g. FreeBSD or macOS): ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) package mkdir -p /opt/valkey && ./valkey-8.1.0-Darwin.sh --prefix=/opt/valkey --exclude-subdir # valkey-server is now installed under /opt/valkey ``` Signed-off-by: Eran Ifrah <eifrah@amazon.com>
176 lines
5.8 KiB
YAML
176 lines
5.8 KiB
YAML
name: CI
|
|
|
|
on: [push, pull_request]
|
|
|
|
concurrency:
|
|
group: ci-${{ github.head_ref || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
test-ubuntu-latest:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
# Fail build if there are warnings
|
|
# build with TLS just for compilation coverage
|
|
run: make -j4 all-with-unit-tests SERVER_CFLAGS='-Werror' BUILD_TLS=yes
|
|
- name: test
|
|
run: |
|
|
sudo apt-get install tcl8.6 tclx
|
|
./runtest --verbose --tags -slow --dump-logs
|
|
- name: module api test
|
|
run: CFLAGS='-Werror' ./runtest-moduleapi --verbose --dump-logs
|
|
- name: validate commands.def up to date
|
|
run: |
|
|
touch src/commands/ping.json
|
|
make commands.def
|
|
dirty=$(git diff)
|
|
if [[ ! -z $dirty ]]; then echo $dirty; exit 1; fi
|
|
- name: unit tests
|
|
run: |
|
|
./src/valkey-unit-tests
|
|
|
|
test-ubuntu-latest-cmake:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: cmake and make
|
|
run: |
|
|
sudo apt-get install -y cmake libssl-dev
|
|
mkdir -p build-release
|
|
cd build-release
|
|
cmake -DCMAKE_BUILD_TYPE=Release .. -DBUILD_TLS=yes -DBUILD_UNIT_TESTS=yes
|
|
make -j$(nproc)
|
|
- name: test
|
|
run: |
|
|
sudo apt-get install -y tcl8.6 tclx
|
|
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-server
|
|
ln -sf $(pwd)/build-release/bin/valkey-cli $(pwd)/src/valkey-cli
|
|
ln -sf $(pwd)/build-release/bin/valkey-benchmark $(pwd)/src/valkey-benchmark
|
|
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-check-aof
|
|
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-check-rdb
|
|
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-sentinel
|
|
./runtest --verbose --tags -slow --dump-logs
|
|
- name: unit tests
|
|
run: |
|
|
./build-release/bin/valkey-unit-tests
|
|
|
|
test-sanitizer-address:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
# build with TLS module just for compilation coverage
|
|
run: make -j4 SANITIZER=address SERVER_CFLAGS='-Werror' BUILD_TLS=module
|
|
- name: testprep
|
|
run: sudo apt-get install tcl8.6 tclx -y
|
|
- name: test
|
|
run: ./runtest --verbose --tags -slow --dump-logs
|
|
- name: module api test
|
|
run: CFLAGS='-Werror' ./runtest-moduleapi --verbose --dump-logs
|
|
|
|
test-rdma:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
run: |
|
|
sudo apt-get install librdmacm-dev libibverbs-dev
|
|
make -j4 BUILD_RDMA=module
|
|
- name: clone-rxe-kmod
|
|
run: |
|
|
mkdir -p tests/rdma/rxe
|
|
git clone https://github.com/pizhenwei/rxe.git tests/rdma/rxe
|
|
make -C tests/rdma/rxe
|
|
- name: clear-kernel-log
|
|
run: sudo dmesg -c > /dev/null
|
|
- name: test
|
|
run: sudo ./runtest-rdma --install-rxe
|
|
- name: show-kernel-log
|
|
run: sudo dmesg -c
|
|
|
|
build-debian-old:
|
|
runs-on: ubuntu-latest
|
|
container: debian:buster
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
run: |
|
|
apt-get update && apt-get install -y build-essential
|
|
make -j4 SERVER_CFLAGS='-Werror'
|
|
|
|
build-macos-latest:
|
|
runs-on: macos-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
run: make -j3 all-with-unit-tests SERVER_CFLAGS='-Werror'
|
|
|
|
build-32bit:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
run: |
|
|
sudo apt-get update && sudo apt-get install libc6-dev-i386
|
|
make -j4 SERVER_CFLAGS='-Werror' 32bit
|
|
|
|
build-libc-malloc:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
- name: make
|
|
run: make -j4 SERVER_CFLAGS='-Werror' MALLOC=libc
|
|
|
|
build-almalinux8-jemalloc:
|
|
runs-on: ubuntu-latest
|
|
container: almalinux:8
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
|
|
- name: make
|
|
run: |
|
|
dnf -y install epel-release gcc make procps-ng which
|
|
make -j4 SERVER_CFLAGS='-Werror'
|
|
|
|
format-yaml:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
|
|
with:
|
|
go-version: "1.22.4"
|
|
|
|
- name: Setup YAML formatter
|
|
run: |
|
|
go install github.com/google/yamlfmt/cmd/yamlfmt@latest
|
|
|
|
- name: Run yamlfmt
|
|
id: yamlfmt
|
|
run: |
|
|
yamlfmt -lint -conf .config/format.yml .
|
|
# Capture the diff output
|
|
DIFF=$(git diff)
|
|
if [ ! -z "$DIFF" ]; then
|
|
# Encode the diff in Base64 to ensure it's handled as a single line
|
|
ENCODED_DIFF=$(echo "$DIFF" | base64 -w 0)
|
|
echo "diff=$ENCODED_DIFF" >> $GITHUB_OUTPUT
|
|
fi
|
|
shell: bash
|
|
|
|
- name: Check for formatting changes
|
|
if: ${{ steps.yamlfmt.outputs.diff }}
|
|
run: |
|
|
echo "ERROR: YAML file is not formatted properly. Here is the diff: "
|
|
# Decode the Base64 diff to display it
|
|
echo "${{ steps.clang-format.outputs.diff }}" | base64 --decode
|
|
exit 1
|
|
shell: bash
|