Skip to content

Commit 89e79f2

Browse files
committed
build: revert back to C++11
There seem to be many poor souls stuck to C++11. Because we don't really depend on C++14 features let's wait for a reason to bump up the standard to C++17 or later. Close: #619 Fix: #618 Fix: #615
1 parent b1b5523 commit 89e79f2

File tree

17 files changed

+56
-40
lines changed

17 files changed

+56
-40
lines changed

.github/workflows/bazel-ci.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ jobs:
88
strategy:
99
matrix:
1010
os: [macos-latest, ubuntu-latest, windows-latest]
11-
include:
12-
- os: macOS-latest
13-
bazel_args: "--cxxopt=-std=c++14"
14-
- os: ubuntu-latest
15-
bazel_args: "--cxxopt=-std=c++14"
16-
- os: windows-latest
17-
bazel_args: "--cxxopt=/std:c++14"
18-
1911
steps:
2012
- name: Checkout source
2113
uses: actions/checkout@v3
@@ -48,14 +40,14 @@ jobs:
4840
run: bazel test --config=ssl ${{ matrix.bazel_args }} --test_output=all //...
4941

5042
- name: Build
51-
run: bazel build ${{ matrix.bazel_args }} //...
43+
run: bazel build //...
5244

5345
- name: Test
5446
run: bazel test ${{ matrix.bazel_args }} --test_output=all //...
5547

5648
- name: Scraping Test
5749
if: runner.os != 'Windows'
58-
run: bazel test ${{ matrix.bazel_args }} --test_output=all //pull/tests/integration:scrape-test
50+
run: bazel test --test_output=all //pull/tests/integration:scrape-test
5951

6052
- name: Benchmark
61-
run: bazel run ${{ matrix.bazel_args }} -c opt //core/benchmarks
53+
run: bazel run -c opt //core/benchmarks

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ option(ENABLE_COMPRESSION "Enable gzip compression" ON)
2323
option(ENABLE_TESTING "Build tests" ON)
2424
option(USE_THIRDPARTY_LIBRARIES "Use 3rdParty submodules" ON)
2525
option(THIRDPARTY_CIVETWEB_WITH_SSL "Enable SSL support for embedded civetweb source code")
26-
option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++14 even if the CXXFLAGS are configured differently" ON)
26+
option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXFLAGS are configured differently" ON)
2727
option(GENERATE_PKGCONFIG "Generate and install pkg-config files" ${UNIX})
2828
option(RUN_IWYU "Run include-what-you-use" OFF)
2929

3030
if(OVERRIDE_CXX_STANDARD_FLAGS)
31-
set(CMAKE_CXX_STANDARD 14)
31+
set(CMAKE_CXX_STANDARD 11)
3232
set(CMAKE_CXX_EXTENSIONS Off)
3333
endif()
3434

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int main() {
9292

9393
## Requirements
9494

95-
Using `prometheus-cpp` requires a C++14 compliant compiler. It has been successfully tested with GNU GCC 7.4 on Ubuntu Bionic (18.04) and Visual Studio 2017.
95+
Using `prometheus-cpp` requires a C++11 compliant compiler. It has been successfully tested with GNU GCC 7.4 on Ubuntu Bionic (18.04) and Visual Studio 2017.
9696

9797
## Building
9898

@@ -247,19 +247,19 @@ guidelines](https://chris.beams.io/posts/git-commit/).
247247

248248
You can check out this repo and build the library using
249249
``` bash
250-
bazel build --cxxopt=-std=c++14 //...
250+
bazel build //...
251251
```
252252

253253
Run the unit tests using
254254
```
255-
bazel test --cxxopt=-std=c++14 //...
255+
bazel test //...
256256
```
257257

258258
There is also an integration test that
259259
uses [telegraf](https://github.com/influxdata/telegraf) to scrape a
260260
sample server. With telegraf installed, it can be run using
261261
```
262-
bazel test --cxxopt=-std=c++14 //pull/tests/integration:scrape-test
262+
bazel test //pull/tests/integration:scrape-test
263263
```
264264

265265
## Benchmarks

cmake/project-import-pkgconfig/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
22

33
project(prometheus-cpp-import)
44

5-
set(CMAKE_CXX_STANDARD 14)
5+
set(CMAKE_CXX_STANDARD 11)
66

77
find_package(PkgConfig REQUIRED)
88

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ add_library(${PROJECT_NAME}::core ALIAS core)
2020

2121
target_compile_features(core
2222
PUBLIC
23-
cxx_std_14
23+
cxx_std_11
2424
)
2525

2626
target_link_libraries(core
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <utility>
5+
6+
namespace prometheus {
7+
namespace detail {
8+
9+
// Remove as soon C++14 can be used.
10+
template <typename T, typename... Args>
11+
std::unique_ptr<T> make_unique(Args&&... args) {
12+
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
13+
}
14+
15+
} // namespace detail
16+
} // namespace prometheus

core/include/prometheus/family.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "prometheus/client_metric.h"
1010
#include "prometheus/collectable.h"
1111
#include "prometheus/detail/core_export.h"
12+
#include "prometheus/detail/future_std.h"
1213
#include "prometheus/detail/utils.h"
1314
#include "prometheus/labels.h"
1415
#include "prometheus/metric_family.h"
@@ -110,7 +111,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
110111
/// \throw std::runtime_exception on invalid label names.
111112
template <typename... Args>
112113
T& Add(const Labels& labels, Args&&... args) {
113-
return Add(labels, std::make_unique<T>(args...));
114+
return Add(labels, detail::make_unique<T>(args...));
114115
}
115116

116117
/// \brief Remove the given dimensional data.

core/src/family.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <cassert>
55
#include <map>
66
#include <stdexcept>
7-
#include <type_traits>
87
#include <utility>
98

109
#include "prometheus/check_names.h"

core/src/registry.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#include <algorithm>
44
#include <iterator>
5-
#include <memory>
65
#include <stdexcept>
76
#include <tuple>
87

98
#include "prometheus/counter.h"
9+
#include "prometheus/detail/future_std.h"
1010
#include "prometheus/gauge.h"
1111
#include "prometheus/histogram.h"
1212
#include "prometheus/info.h"
@@ -141,7 +141,7 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
141141
throw std::invalid_argument("Family name already exists");
142142
}
143143

144-
auto family = std::make_unique<Family<T>>(name, help, labels);
144+
auto family = detail::make_unique<Family<T>>(name, help, labels);
145145
auto& ref = *family;
146146
families.push_back(std::move(family));
147147
return ref;

core/tests/family_test.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "prometheus/client_metric.h"
99
#include "prometheus/counter.h"
10+
#include "prometheus/detail/future_std.h"
1011
#include "prometheus/histogram.h"
1112
#include "prometheus/labels.h"
1213
#include "prometheus/summary.h"
@@ -81,16 +82,16 @@ TEST(FamilyTest, add_twice) {
8182

8283
TEST(FamilyTest, throw_on_invalid_metric_name) {
8384
auto create_family_with_invalid_name = []() {
84-
return std::make_unique<Family<Counter>>("", "empty name", Labels{});
85+
return detail::make_unique<Family<Counter>>("", "empty name", Labels{});
8586
};
8687
EXPECT_ANY_THROW(create_family_with_invalid_name());
8788
}
8889

8990
TEST(FamilyTest, throw_on_invalid_constant_label_name) {
9091
auto create_family_with_invalid_labels = []() {
91-
return std::make_unique<Family<Counter>>("total_requests",
92-
"Counts all requests",
93-
Labels{{"__invalid", "counter1"}});
92+
return detail::make_unique<Family<Counter>>(
93+
"total_requests", "Counts all requests",
94+
Labels{{"__inavlid", "counter1"}});
9495
};
9596
EXPECT_ANY_THROW(create_family_with_invalid_labels());
9697
}
@@ -118,7 +119,8 @@ TEST(FamilyTest, query_family_if_metric_already_exists) {
118119

119120
TEST(FamilyTest, reject_histogram_with_constant_le_label) {
120121
auto labels = Labels{{"le", "test"}};
121-
EXPECT_ANY_THROW(std::make_unique<Family<Histogram>>("name", "help", labels));
122+
EXPECT_ANY_THROW(
123+
detail::make_unique<Family<Histogram>>("name", "help", labels));
122124
}
123125

124126
TEST(FamilyTest, reject_histogram_with_le_label) {
@@ -129,7 +131,8 @@ TEST(FamilyTest, reject_histogram_with_le_label) {
129131

130132
TEST(FamilyTest, reject_summary_with_constant_quantile_label) {
131133
auto labels = Labels{{"quantile", "test"}};
132-
EXPECT_ANY_THROW(std::make_unique<Family<Summary>>("name", "help", labels));
134+
EXPECT_ANY_THROW(
135+
detail::make_unique<Family<Summary>>("name", "help", labels));
133136
}
134137

135138
TEST(FamilyTest, reject_summary_with_quantile_label) {

0 commit comments

Comments
 (0)