From 4aa9d37f0fb3ef0bd2e69b3db28e7b0c55ce7d8b Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 26 Jul 2024 09:19:05 +0100 Subject: [PATCH] Add google-benchmark --- .devcontainer/Dockerfile | 2 +- .editorconfig | 3 +++ .github/workflows/Linux_x86_64_test.yml | 6 ++++-- .github/workflows/src_dist_release.yml | 4 ++-- 3rdParty/benchmark/CMakeLists.txt | 16 ++++++++++++++++ Brewfile | 1 + CMake/Dependencies.cmake | 7 +++++++ docs/building.md | 4 ++-- tools/make_src_dist.py | 4 ++-- vcpkg.json | 2 +- 10 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 3rdParty/benchmark/CMakeLists.txt diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7478ad9e7f2..22616bc4533 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install tar curl zip unzip bash-completion build-essential ripgrep htop \ ninja-build ccache g++ mold gdb clang-format clang-tidy \ rpm pkg-config cmake git smpq gettext libsdl2-dev libsdl2-image-dev libsodium-dev \ - libpng-dev libbz2-dev libfmt-dev libgtest-dev libgmock-dev libsimpleini-dev zsh \ + libpng-dev libbz2-dev libfmt-dev libgtest-dev libgmock-dev libbenchmark-dev libsimpleini-dev zsh \ qtbase5-dev qt6-base-dev ristretto \ && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* diff --git a/.editorconfig b/.editorconfig index 6bbc235ffb5..6baba88588a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -80,3 +80,6 @@ end_of_line = lf [devilutionx.spec] end_of_line = lf + +[Dockerfile] +end_of_line = lf diff --git a/.github/workflows/Linux_x86_64_test.yml b/.github/workflows/Linux_x86_64_test.yml index 7218c010558..3165868806b 100644 --- a/.github/workflows/Linux_x86_64_test.yml +++ b/.github/workflows/Linux_x86_64_test.yml @@ -30,7 +30,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update -y - sudo apt-get install -y cmake curl g++ git lcov libgtest-dev libgmock-dev libfmt-dev libsdl2-dev libsodium-dev libpng-dev libbz2-dev wget + sudo apt-get install -y cmake curl g++ git lcov libgtest-dev libgmock-dev libbenchmark-dev libfmt-dev libsdl2-dev libsodium-dev libpng-dev libbz2-dev wget - name: Cache CMake build folder uses: actions/cache@v4 with: @@ -38,9 +38,11 @@ jobs: key: ${{ github.workflow }}-v1-${{ github.sha }} restore-keys: ${{ github.workflow }}-v1- + # We specify `-DDEVILUTIONX_SYSTEM_BENCHMARK=OFF` to work around the following error: + # lto1: fatal error: bytecode stream in file ‘/usr/lib/x86_64-linux-gnu/libbenchmark_main.a’ generated with LTO version 11.2 instead of the expected 11.3 - name: Build tests run: | - cmake -S. -Bbuild -DENABLE_CODECOVERAGE=ON + cmake -S. -Bbuild -DENABLE_CODECOVERAGE=ON -DDEVILUTIONX_SYSTEM_BENCHMARK=OFF wget -nc https://github.com/diasurgical/devilutionx-assets/releases/download/v2/spawn.mpq -P build cmake --build build -j $(nproc) diff --git a/.github/workflows/src_dist_release.yml b/.github/workflows/src_dist_release.yml index 5ecad2343ce..274ce10ad85 100644 --- a/.github/workflows/src_dist_release.yml +++ b/.github/workflows/src_dist_release.yml @@ -24,7 +24,7 @@ jobs: - name: Create Build Environment run: > sudo apt-get update && - sudo apt-get install -y cmake curl libsdl2-dev libsdl2-image-dev libfmt-dev libsodium-dev libbz2-dev libgtest-dev libgmock-dev git smpq gettext python-is-python3 + sudo apt-get install -y cmake curl libsdl2-dev libsdl2-image-dev libfmt-dev libsodium-dev libbz2-dev libgtest-dev libgmock-dev libbenchmark-dev git smpq gettext python-is-python3 - name: Build working-directory: ${{github.workspace}} @@ -55,7 +55,7 @@ jobs: - name: Create Build Environment run: > sudo apt-get update && - sudo apt-get install -y cmake curl libsdl2-dev libsdl2-image-dev libfmt-dev libsodium-dev libbz2-dev libgtest-dev libgmock-dev git smpq gettext python-is-python3 + sudo apt-get install -y cmake curl libsdl2-dev libsdl2-image-dev libfmt-dev libsodium-dev libbz2-dev libgtest-dev libgmock-dev libbenchmark-dev git smpq gettext python-is-python3 - name: Build working-directory: ${{github.workspace}} diff --git a/3rdParty/benchmark/CMakeLists.txt b/3rdParty/benchmark/CMakeLists.txt new file mode 100644 index 00000000000..558d571aece --- /dev/null +++ b/3rdParty/benchmark/CMakeLists.txt @@ -0,0 +1,16 @@ +include(functions/FetchContent_MakeAvailableExcludeFromAll) + +FetchContent_Declare( + benchmark + URL https://github.com/google/benchmark/archive/refs/tags/v1.8.5.tar.gz + URL_HASH MD5=708d91ce255e8af4c1d7dfec50dff178 +) + +set(INSTALL_GTEST OFF) + +set(BENCHMARK_ENABLE_TESTING OFF) +set(BENCHMARK_ENABLE_EXCEPTIONS OFF) +set(BENCHMARK_ENABLE_WERROR OFF) +set(BENCHMARK_ENABLE_INSTALL OFF) + +FetchContent_MakeAvailable(benchmark) diff --git a/Brewfile b/Brewfile index a5d2c71b1d0..e83c1a1f3c6 100644 --- a/Brewfile +++ b/Brewfile @@ -4,3 +4,4 @@ brew "sdl2" brew "libsodium" brew "pkg-config" brew "googletest" +brew "google-benchmark" diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 0957c71961a..cd71bd8635f 100644 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -271,6 +271,13 @@ if(BUILD_TESTING) else() add_subdirectory(3rdParty/googletest) endif() + + dependency_options("benchmark" DEVILUTIONX_SYSTEM_BENCHMARK ON DEVILUTIONX_STATIC_BENCHMARK) + if(DEVILUTIONX_SYSTEM_BENCHMARK) + find_package(benchmark REQUIRED) + else() + add_subdirectory(3rdParty/benchmark) + endif() endif() if(GPERF) diff --git a/docs/building.md b/docs/building.md index 5800f1ec25d..34a65aff83f 100644 --- a/docs/building.md +++ b/docs/building.md @@ -12,7 +12,7 @@ Note that ```pkg-config``` is an optional dependency for finding libsodium, alth ### Installing dependencies on Debian and Ubuntu ``` -sudo apt-get install cmake g++ libsdl2-dev libsodium-dev libpng-dev libbz2-dev libgtest-dev libgmock-dev libsdl2-image-dev libfmt-dev +sudo apt-get install cmake g++ libsdl2-dev libsodium-dev libpng-dev libbz2-dev libgtest-dev libgmock-dev libbenchmark-dev libsdl2-image-dev libfmt-dev ``` ### If you want to build the translations (optional) @@ -30,7 +30,7 @@ sudo apt-get install smpq ### Installing dependencies on Fedora ``` -sudo dnf install cmake gcc-c++ glibc-devel libstdc++-static SDL2-devel SDL2_image-devel libsodium-devel libpng-devel bzip2-devel gmock-devel gtest-devel libasan libubsan fmt-devel +sudo dnf install cmake gcc-c++ glibc-devel libstdc++-static SDL2-devel SDL2_image-devel libsodium-devel libpng-devel bzip2-devel gmock-devel gtest-devel google-benchmark-devel libasan libubsan fmt-devel ``` ### Compiling diff --git a/tools/make_src_dist.py b/tools/make_src_dist.py index 4b40b943fcb..f633814d9c0 100755 --- a/tools/make_src_dist.py +++ b/tools/make_src_dist.py @@ -41,7 +41,7 @@ # These dependencies are not vendored by default. # Run with `--fully_vendored` to include them. -_DEPS_NOT_VENDORED_BY_DEFAULT = ['googletest', 'sdl2', 'sdl_image', +_DEPS_NOT_VENDORED_BY_DEFAULT = ['googletest', 'benchmark', 'sdl2', 'sdl_image', 'libpng', 'libfmt', 'bzip2', 'libsodium'] _ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent @@ -101,7 +101,7 @@ def main(): src = src_bytes.decode() dst_path = paths.archive_top_level_dir.joinpath(src) dst_path.parent.mkdir(parents=True, exist_ok=True) - if re.search('(^|/)\.gitkeep$', src): + if re.search(r'(^|/)\.gitkeep$', src): continue shutil.copy2(_ROOT_DIR.joinpath(src), dst_path, follow_symlinks=False) diff --git a/vcpkg.json b/vcpkg.json index ba88ccab676..a8511b1b8e9 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -32,7 +32,7 @@ }, "tests": { "description": "Build tests", - "dependencies": [ "gtest" ] + "dependencies": [ "gtest", "benchmark" ] } } }