Skip to content

Commit

Permalink
build: require C++14
Browse files Browse the repository at this point in the history
  • Loading branch information
gjasny committed Apr 3, 2022
1 parent 9859f09 commit 79d0965
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 47 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/bazel-ci.yml
Expand Up @@ -8,6 +8,14 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: macOS-latest
bazel_args: "--cxxopt=-std=c++14"
- os: ubuntu-latest
bazel_args: "--cxxopt=-std=c++14"
- os: windows-latest
bazel_args: "--cxxopt=/std:c++14"

steps:
- name: Checkout source
uses: actions/checkout@v2
Expand All @@ -34,14 +42,14 @@ jobs:
run: brew install telegraf

- name: Build
run: bazel build //...
run: bazel build ${{ matrix.bazel_args }} //...

- name: Test
run: bazel test --test_output=all //core/... //pull/...
run: bazel test ${{ matrix.bazel_args }} --test_output=all //core/... //pull/...

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

- name: Benchmark
run: bazel run -c opt //core/benchmarks
run: bazel run ${{ matrix.bazel_args }} -c opt //core/benchmarks
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -28,7 +28,7 @@ option(GENERATE_PKGCONFIG "Generate and install pkg-config files" ${UNIX})
option(RUN_IWYU "Run include-what-you-use" OFF)

if(OVERRIDE_CXX_STANDARD_FLAGS)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS Off)
endif()

Expand Down
2 changes: 0 additions & 2 deletions cmake/project-import-cmake/CMakeLists.txt
Expand Up @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(prometheus-cpp-import)

set(CMAKE_CXX_STANDARD 11)

find_package(prometheus-cpp CONFIG REQUIRED)

if(PROMETHEUS_CPP_ENABLE_PUSH)
Expand Down
2 changes: 1 addition & 1 deletion cmake/project-import-pkgconfig/CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(prometheus-cpp-import)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

find_package(PkgConfig REQUIRED)

Expand Down
5 changes: 5 additions & 0 deletions core/CMakeLists.txt
Expand Up @@ -17,6 +17,11 @@ add_library(core

add_library(${PROJECT_NAME}::core ALIAS core)

target_compile_features(core
PUBLIC
cxx_std_14
)

target_link_libraries(core
PRIVATE
Threads::Threads
Expand Down
16 changes: 0 additions & 16 deletions core/include/prometheus/detail/future_std.h

This file was deleted.

3 changes: 1 addition & 2 deletions core/include/prometheus/family.h
Expand Up @@ -9,7 +9,6 @@
#include "prometheus/client_metric.h"
#include "prometheus/collectable.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/detail/utils.h"
#include "prometheus/labels.h"
#include "prometheus/metric_family.h"
Expand Down Expand Up @@ -110,7 +109,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
/// \throw std::runtime_exception on invalid label names.
template <typename... Args>
T& Add(const Labels& labels, Args&&... args) {
return Add(labels, detail::make_unique<T>(args...));
return Add(labels, std::make_unique<T>(args...));
}

/// \brief Remove the given dimensional data.
Expand Down
4 changes: 2 additions & 2 deletions core/src/registry.cc
Expand Up @@ -2,11 +2,11 @@

#include <algorithm>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <tuple>

#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/gauge.h"
#include "prometheus/histogram.h"
#include "prometheus/summary.h"
Expand Down Expand Up @@ -129,7 +129,7 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
throw std::invalid_argument("Family name already exists");
}

auto family = detail::make_unique<Family<T>>(name, help, labels);
auto family = std::make_unique<Family<T>>(name, help, labels);
auto& ref = *family;
families.push_back(std::move(family));
return ref;
Expand Down
9 changes: 4 additions & 5 deletions core/tests/family_test.cc
Expand Up @@ -7,7 +7,6 @@

#include "prometheus/client_metric.h"
#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/histogram.h"
#include "prometheus/labels.h"

Expand Down Expand Up @@ -81,16 +80,16 @@ TEST(FamilyTest, add_twice) {

TEST(FamilyTest, throw_on_invalid_metric_name) {
auto create_family_with_invalid_name = []() {
return detail::make_unique<Family<Counter>>("", "empty name", Labels{});
return std::make_unique<Family<Counter>>("", "empty name", Labels{});
};
EXPECT_ANY_THROW(create_family_with_invalid_name());
}

TEST(FamilyTest, throw_on_invalid_constant_label_name) {
auto create_family_with_invalid_labels = []() {
return detail::make_unique<Family<Counter>>(
"total_requests", "Counts all requests",
Labels{{"__inavlid", "counter1"}});
return std::make_unique<Family<Counter>>("total_requests",
"Counts all requests",
Labels{{"__inavlid", "counter1"}});
};
EXPECT_ANY_THROW(create_family_with_invalid_labels());
}
Expand Down
3 changes: 1 addition & 2 deletions core/tests/serializer_test.cc
Expand Up @@ -7,7 +7,6 @@
#include <vector>

#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/family.h"
#include "prometheus/metric_family.h"
#include "prometheus/text_serializer.h"
Expand Down Expand Up @@ -41,7 +40,7 @@ TEST_F(SerializerTest, shouldSerializeLocaleIndependent) {
// ignore missing locale and skip test if setup fails
try {
localeWithCommaDecimalSeparator =
detail::make_unique<RAIILocale>("de_DE.UTF-8");
std::make_unique<RAIILocale>("de_DE.UTF-8");
} catch (std::runtime_error&) {
GTEST_SKIP();
}
Expand Down
5 changes: 5 additions & 0 deletions pull/CMakeLists.txt
Expand Up @@ -37,6 +37,11 @@ add_library(pull

add_library(${PROJECT_NAME}::pull ALIAS pull)

target_compile_features(pull
PUBLIC
cxx_std_14
)

target_link_libraries(pull
PUBLIC
${PROJECT_NAME}::core
Expand Down
7 changes: 3 additions & 4 deletions pull/src/endpoint.cc
@@ -1,10 +1,10 @@
#include "endpoint.h"

#include <memory>
#include <utility>

#include "basic_auth.h"
#include "handler.h"
#include "prometheus/detail/future_std.h"

namespace prometheus {
namespace detail {
Expand All @@ -21,8 +21,7 @@ Endpoint::Endpoint(CivetServer& server, std::string uri)
: server_(server),
uri_(std::move(uri)),
endpoint_registry_(std::make_shared<Registry>()),
metrics_handler_(
detail::make_unique<MetricsHandler>(*endpoint_registry_)) {
metrics_handler_(std::make_unique<MetricsHandler>(*endpoint_registry_)) {
RegisterCollectable(endpoint_registry_);
server_.addHandler(uri_, metrics_handler_.get());
}
Expand All @@ -47,7 +46,7 @@ void Endpoint::RegisterAuth(
// split creating, assigning, and storing to avoid a race-condition when
// being called the second time and the handler is replaced
auto new_handler =
detail::make_unique<BasicAuthHandler>(std::move(authCB), realm);
std::make_unique<BasicAuthHandler>(std::move(authCB), realm);
server_.addAuthHandler(uri_, new_handler.get());
auth_handler_ = std::move(new_handler);
}
Expand Down
7 changes: 3 additions & 4 deletions pull/src/exposer.cc
Expand Up @@ -2,12 +2,12 @@

#include <algorithm>
#include <iterator>
#include <memory>
#include <string>
#include <utility>

#include "CivetServer.h"
#include "endpoint.h"
#include "prometheus/detail/future_std.h"

namespace prometheus {

Expand All @@ -20,8 +20,7 @@ Exposer::Exposer(const std::string& bind_address, const std::size_t num_threads,

Exposer::Exposer(std::vector<std::string> options,
const CivetCallbacks* callbacks)
: server_(detail::make_unique<CivetServer>(std::move(options), callbacks)) {
}
: server_(std::make_unique<CivetServer>(std::move(options), callbacks)) {}

Exposer::~Exposer() = default;

Expand Down Expand Up @@ -60,7 +59,7 @@ detail::Endpoint& Exposer::GetEndpointForUri(const std::string& uri) {
return *it->get();
}

endpoints_.emplace_back(detail::make_unique<detail::Endpoint>(*server_, uri));
endpoints_.emplace_back(std::make_unique<detail::Endpoint>(*server_, uri));
return *endpoints_.back().get();
}

Expand Down
3 changes: 1 addition & 2 deletions pull/tests/integration/integration_test.cc
Expand Up @@ -10,7 +10,6 @@
#include <vector>

#include "prometheus/counter.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/exposer.h"
#include "prometheus/family.h"
#include "prometheus/registry.h"
Expand All @@ -23,7 +22,7 @@ using namespace testing;
class IntegrationTest : public testing::Test {
public:
void SetUp() override {
exposer_ = detail::make_unique<Exposer>("127.0.0.1:0");
exposer_ = std::make_unique<Exposer>("127.0.0.1:0");
auto ports = exposer_->GetListeningPorts();
base_url_ = std::string("http://127.0.0.1:") + std::to_string(ports.at(0));
}
Expand Down
5 changes: 5 additions & 0 deletions push/CMakeLists.txt
Expand Up @@ -9,6 +9,11 @@ add_library(push

add_library(${PROJECT_NAME}::push ALIAS push)

target_compile_features(push
PUBLIC
cxx_std_14
)

target_link_libraries(push
PUBLIC
${PROJECT_NAME}::core
Expand Down
3 changes: 1 addition & 2 deletions push/src/gateway.cc
Expand Up @@ -9,7 +9,6 @@
#include <sstream>

#include "curl_wrapper.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/metric_family.h" // IWYU pragma: keep
#include "prometheus/text_serializer.h"

Expand All @@ -21,7 +20,7 @@ namespace prometheus {
Gateway::Gateway(const std::string& host, const std::string& port,
const std::string& jobname, const Labels& labels,
const std::string& username, const std::string& password) {
curlWrapper_ = detail::make_unique<detail::CurlWrapper>(username, password);
curlWrapper_ = std::make_unique<detail::CurlWrapper>(username, password);

std::stringstream jobUriStream;
jobUriStream << host << ':' << port << "/metrics/job/" << jobname;
Expand Down

0 comments on commit 79d0965

Please sign in to comment.