Skip to content

Commit

Permalink
Add google-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 7, 2024
1 parent e5c628d commit 4aa9d37
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ end_of_line = lf

[devilutionx.spec]
end_of_line = lf

[Dockerfile]
end_of_line = lf
6 changes: 4 additions & 2 deletions .github/workflows/Linux_x86_64_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ 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:
path: build
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)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/src_dist_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down
16 changes: 16 additions & 0 deletions 3rdParty/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ brew "sdl2"
brew "libsodium"
brew "pkg-config"
brew "googletest"
brew "google-benchmark"
7 changes: 7 additions & 0 deletions CMake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/make_src_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"tests": {
"description": "Build tests",
"dependencies": [ "gtest" ]
"dependencies": [ "gtest", "benchmark" ]
}
}
}

0 comments on commit 4aa9d37

Please sign in to comment.