Skip to content

Commit 7276428

Browse files
authored
c++11 building support (#100)
1 parent 4fb190a commit 7276428

34 files changed

+174
-154
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
build --enable_platform_specific_config
22
build --features=-supports_dynamic_linker
3-
build --cxxopt=-std=c++17
4-
build:windows --cxxopt=-std:c++17
3+
build --copt="-Wall"
4+
build --copt="-Werror"
55
build:windows --copt=/wd4716
66

77
try-import %workspace%/user.bazelrc

.github/workflows/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ jobs:
1717
run: |
1818
sudo wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
1919
sudo chmod +x /usr/local/bin/bazel
20-
- name: Run bazel test
20+
- name: Run bazel test with c++11
2121
run: |
22-
bazel test //...
22+
bazel test --cxxopt=-std=c++0x //...
23+
- name: Run bazel test with c++17
24+
run: |
25+
bazel test --cxxopt=-std=c++17 //...
2326
2427
format:
2528
runs-on: ubuntu-latest

README.md

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

33
![cpp2sky test](https://github.com/SkyAPM/cpp2sky/workflows/cpp2sky%20test/badge.svg)
44

5-
Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM
5+
Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM. This SDK is compatible with C++ 17, C++ 14, and C++ 11.
66

77
## Build
88

@@ -152,7 +152,7 @@ configurations:
152152
ignore_suffix: '/ignore, /hoge'
153153
```
154154
155-
After setup configurations, try to put values with
155+
After setup configurations, try to put values with
156156
157157
```
158158
curl --request PUT --data-binary "@./config.yaml" http://localhost:8500/v1/kv/configuration-discovery.default.agentConfigurations

cpp2sky/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ cc_library(
4444
],
4545
deps = [
4646
":config_cc_proto",
47+
"@com_google_absl//absl/memory:memory",
48+
"@com_google_absl//absl/strings:strings",
49+
"@com_google_absl//absl/types:optional",
4750
],
4851
visibility = ["//visibility:public"],
4952
)

cpp2sky/assert.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
namespace cpp2sky {
1818

1919
template <class T>
20-
static constexpr bool false_v = false;
20+
class FalseValue {
21+
static constexpr bool value = false;
22+
};
2123

22-
#define CPP2SKY_STATIC_ASSERT(T, m) static_assert(false_v<T>, m)
24+
#define CPP2SKY_STATIC_ASSERT(T, m) static_assert(FalseValue<T>::value, m)
2325

2426
} // namespace cpp2sky

cpp2sky/internal/matcher.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#pragma once
1616

1717
#include <memory>
18-
#include <string_view>
18+
19+
#include "absl/strings/string_view.h"
1920

2021
namespace cpp2sky {
2122

@@ -26,7 +27,7 @@ class Matcher {
2627
/**
2728
* Check whether to match rule.
2829
*/
29-
virtual bool match(std::string_view target) = 0;
30+
virtual bool match(absl::string_view target) = 0;
3031
};
3132

3233
using MatcherPtr = std::unique_ptr<Matcher>;

cpp2sky/propagation.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#pragma once
1616

1717
#include <memory>
18-
#include <string_view>
18+
19+
#include "absl/strings/string_view.h"
1920

2021
namespace cpp2sky {
2122

@@ -86,8 +87,8 @@ class SpanContextExtension {
8687

8788
using SpanContextExtensionPtr = std::shared_ptr<SpanContextExtension>;
8889

89-
SpanContextPtr createSpanContext(std::string_view ctx);
90+
SpanContextPtr createSpanContext(absl::string_view ctx);
9091

91-
SpanContextExtensionPtr createSpanContextExtension(std::string_view ctx);
92+
SpanContextExtensionPtr createSpanContextExtension(absl::string_view ctx);
9293

9394
} // namespace cpp2sky

cpp2sky/trace_log.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@
1616

1717
#include <spdlog/logger.h>
1818

19-
#include <string_view>
2019
#include <type_traits>
2120

22-
#include "cpp2sky/assert.h"
21+
#include "absl/strings/string_view.h"
2322

2423
namespace cpp2sky {
2524

26-
static constexpr std::string_view SPDLOG_LOG_FORMAT =
25+
static constexpr absl::string_view SPDLOG_LOG_FORMAT =
2726
"{\"level\": \"%^%l%$\", \"msg\": \"%v";
2827

2928
template <class T>
3029
std::string logFormat() {
31-
if constexpr (std::is_same_v<T, spdlog::logger>) {
32-
return SPDLOG_LOG_FORMAT.data();
33-
} else {
34-
CPP2SKY_STATIC_ASSERT(T, "non-supported logger type");
35-
}
30+
static_assert(std::is_same<T, spdlog::logger>::value,
31+
"non-supported logger type");
32+
return SPDLOG_LOG_FORMAT.data();
3633
}
3734

3835
} // namespace cpp2sky

cpp2sky/tracing_context.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
#include <list>
1818
#include <memory>
19-
#include <optional>
20-
#include <string_view>
2119

20+
#include "absl/memory/memory.h"
21+
#include "absl/strings/string_view.h"
22+
#include "absl/types/optional.h"
2223
#include "cpp2sky/config.pb.h"
2324
#include "cpp2sky/propagation.h"
2425
#include "cpp2sky/time.h"
@@ -58,7 +59,7 @@ class TracingSpan {
5859
/**
5960
* Get peer address.
6061
*/
61-
virtual std::string_view peer() const = 0;
62+
virtual absl::string_view peer() const = 0;
6263

6364
/**
6465
* Get span type.
@@ -88,7 +89,7 @@ class TracingSpan {
8889
/**
8990
* Get operation name.
9091
*/
91-
virtual std::string_view operationName() const = 0;
92+
virtual absl::string_view operationName() const = 0;
9293

9394
/**
9495
* Set parent span ID of this span.
@@ -98,10 +99,10 @@ class TracingSpan {
9899
/**
99100
* Set start time to calculate execution time.
100101
*/
101-
virtual void startSpan(std::string_view operation_name) = 0;
102-
virtual void startSpan(std::string_view operation_name,
102+
virtual void startSpan(absl::string_view operation_name) = 0;
103+
virtual void startSpan(absl::string_view operation_name,
103104
TimePoint<SystemTime> current_time) = 0;
104-
virtual void startSpan(std::string_view operation_name,
105+
virtual void startSpan(absl::string_view operation_name,
105106
TimePoint<SteadyTime> current_time) = 0;
106107

107108
/**
@@ -114,7 +115,7 @@ class TracingSpan {
114115
/**
115116
* Set peer address for this span (lvalue)
116117
*/
117-
virtual void setPeer(std::string_view remote_address) = 0;
118+
virtual void setPeer(absl::string_view remote_address) = 0;
118119

119120
/**
120121
* Set span type. Entry or Exit. Entry span means origin span which doesn't
@@ -142,15 +143,15 @@ class TracingSpan {
142143
/**
143144
* Set tag to current span.
144145
*/
145-
virtual void addTag(std::string_view key, std::string_view value) = 0;
146+
virtual void addTag(absl::string_view key, absl::string_view value) = 0;
146147

147148
/**
148149
* Add log related with current span.
149150
*/
150-
virtual void addLog(std::string_view key, std::string_view value) = 0;
151-
virtual void addLog(std::string_view key, std::string_view value,
151+
virtual void addLog(absl::string_view key, absl::string_view value) = 0;
152+
virtual void addLog(absl::string_view key, absl::string_view value,
152153
TimePoint<SystemTime> current_time) = 0;
153-
virtual void addLog(std::string_view key, std::string_view value,
154+
virtual void addLog(absl::string_view key, absl::string_view value,
154155
TimePoint<SteadyTime> current_time) = 0;
155156

156157
/**
@@ -161,7 +162,7 @@ class TracingSpan {
161162
/**
162163
* Set operation name.
163164
*/
164-
virtual void setOperationName(std::string_view operation_name) = 0;
165+
virtual void setOperationName(absl::string_view operation_name) = 0;
165166

166167
/**
167168
* Add parent segment reference to current span.
@@ -231,8 +232,8 @@ class TracingContext {
231232
* @param target_address Target address to send request. For more detail:
232233
* https://github.com/apache/skywalking-data-collect-protocol/blob/master/language-agent/Tracing.proto#L97-L101
233234
*/
234-
virtual std::optional<std::string> createSW8HeaderValue(
235-
const std::string_view target_address) = 0;
235+
virtual absl::optional<std::string> createSW8HeaderValue(
236+
const absl::string_view target_address) = 0;
236237

237238
/**
238239
* Generate Apache SkyWalking native segment object. This method **SHOULD**
@@ -260,7 +261,7 @@ class TracingContext {
260261
* logging format following with any format extracted with
261262
* cpp2sky::logFormat().
262263
*/
263-
virtual std::string logMessage(std::string_view message) const = 0;
264+
virtual std::string logMessage(absl::string_view message) const = 0;
264265
};
265266

266267
using TracingContextPtr = std::shared_ptr<TracingContext>;
@@ -272,7 +273,7 @@ using TracingContextPtr = std::shared_ptr<TracingContext>;
272273
class StartEntrySpan {
273274
public:
274275
StartEntrySpan(TracingContextPtr tracing_context,
275-
std::string_view operation_name)
276+
absl::string_view operation_name)
276277
: span_(tracing_context->createEntrySpan()) {
277278
span_->startSpan(operation_name.data());
278279
}
@@ -291,7 +292,7 @@ class StartEntrySpan {
291292
class StartExitSpan {
292293
public:
293294
StartExitSpan(TracingContextPtr tracing_context, TracingSpanPtr parent_span,
294-
std::string_view operation_name)
295+
absl::string_view operation_name)
295296
: span_(tracing_context->createExitSpan(parent_span)) {
296297
span_->startSpan(operation_name.data());
297298
}

cpp2sky/well_known_names.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
#pragma once
1616

17-
#include <string_view>
17+
#include "absl/strings/string_view.h"
1818

1919
namespace cpp2sky {
2020

21-
static constexpr std::string_view kPropagationHeader = "sw8";
22-
static constexpr std::string_view kPropagationExtensionHeader = "sw8-x";
21+
static constexpr absl::string_view kPropagationHeader = "sw8";
22+
static constexpr absl::string_view kPropagationExtensionHeader = "sw8-x";
2323

2424
} // namespace cpp2sky

0 commit comments

Comments
 (0)