Skip to content

Commit fad4e8d

Browse files
authored
feat: add windows support (#119)
- refactor: the codebase to use `substr` instead of `range`. - refactor: CMake targets. - refactor: add bazelrc to build using either abseil or std::string STD. - ci: build and run on windows using CMake and bazel. - update: add platform support section and update building instructions.
1 parent f8cacf4 commit fad4e8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+907
-432
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.bazelrc.absl

.bazelrc.absl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# In order to support both Unixen and Windows, different styles of compiler
2+
# flags must be used.
3+
#
4+
# This .bazelrc file specifies different compiler flags for Linux/Darwin versus
5+
# Windows.
6+
#
7+
# This bazelrc defines the `DD_USE_ABSEIL_FOR_ENVOY` preprocessor macro, and so
8+
# the resulting library will use `absl::string_view` and `absl::optional`
9+
# instead of their standard (`std`) equivalents.
10+
11+
build --enable_platform_specific_config
12+
13+
build:linux --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic' --cxxopt='-DDD_USE_ABSEIL_FOR_ENVOY'
14+
build:macos --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic' --cxxopt='-DDD_USE_ABSEIL_FOR_ENVOY'
15+
build:windows --cxxopt='/std:c++17' --cxxopt='/DDD_USE_ABSEIL_FOR_ENVOY' --linkopt='ws2_32.lib'

.bazelrc.std

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# In order to support both Unixen and Windows, different styles of compiler
2+
# flags must be used.
3+
#
4+
# This .bazelrc file specifies different compiler flags for Linux/Darwin versus
5+
# Windows.
6+
#
7+
# This bazelrc does _not_ define the `DD_USE_ABSEIL_FOR_ENVOY` preprocessor
8+
# macro, and so the resulting library will use `std::string_view` and
9+
# `std::optional` instead of their Abseil equivalents.
10+
11+
build --enable_platform_specific_config
12+
13+
build:linux --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic'
14+
build:macos --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic'
15+
build:windows --cxxopt='/std:c++17' --linkopt='ws2_32.lib'

.circleci/config.yml

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,65 @@ jobs:
3333
type: string
3434
arch:
3535
type: string
36+
bazelrc:
37+
type: string
3638
executor: docker-<< parameters.arch >>
3739
environment:
3840
MAKE_JOB_COUNT: 8
3941
steps:
4042
- checkout
41-
- run: bin/with-toolchain << parameters.toolchain >> bazelisk build --jobs $MAKE_JOB_COUNT dd_trace_cpp
43+
- run: bin/with-toolchain << parameters.toolchain >> bazelisk --bazelrc=<< parameters.bazelrc >> build --jobs $MAKE_JOB_COUNT dd_trace_cpp
4244

43-
test-cmake:
45+
build-and-test-windows-bazel:
4446
parameters:
45-
toolchain:
47+
# `bazelrc` is the path to the .bazelrc file to use in the build/test.
48+
# The repository has two flavors: one that uses Abseil types (for use with
49+
# Envoy), and one that uses std types.
50+
bazelrc:
51+
type: string
52+
machine:
53+
image: "windows-server-2022-gui:current"
54+
resource_class: windows.medium
55+
shell: powershell.exe -ExecutionPolicy Bypass
56+
environment:
57+
MAKE_JOB_COUNT: 4
58+
steps:
59+
- checkout
60+
- run: choco install -y bazelisk
61+
- run: bazelisk.exe --bazelrc=<< parameters.bazelrc >> build --jobs $env:MAKE_JOB_COUNT dd_trace_cpp
62+
63+
build-and-test-windows-cmake:
64+
parameters:
65+
arch:
4666
type: string
47-
sanitize:
67+
machine:
68+
image: "windows-server-2022-gui:current"
69+
shell: powershell.exe -ExecutionPolicy Bypass
70+
resource_class: "windows.large"
71+
environment:
72+
MAKE_JOB_COUNT: 8
73+
steps:
74+
- checkout
75+
- run:
76+
name: Install dependencies
77+
command: |
78+
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
79+
choco install -y ninja
80+
- run:
81+
name: Building
82+
command: |
83+
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch << parameters.arch >>
84+
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DDD_TRACE_BUILD_TESTING=1 -G Ninja .
85+
cmake --build build -j $env:MAKE_JOB_COUNT -v
86+
- run:
87+
name: Testing
88+
command: |
89+
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch << parameters.arch >>
90+
.\build\test\tests.exe
91+
92+
build-and-test-cmake:
93+
parameters:
94+
toolchain:
4895
type: string
4996
arch:
5097
type: string
@@ -55,7 +102,7 @@ jobs:
55102
ASAN_OPTIONS: alloc_dealloc_mismatch=0
56103
steps:
57104
- checkout
58-
- run: bin/with-toolchain << parameters.toolchain >> cmake . -B .build -DBUILD_TESTING=1 -DSANITIZE=<< parameters.sanitize >>
105+
- run: bin/with-toolchain << parameters.toolchain >> cmake . -B .build -DCMAKE_BUILD_TYPE=Debug -DDD_TRACE_BUILD_TESTING=1
59106
- run: cmake --build .build -j ${MAKE_JOB_COUNT} -v
60107
- run: cd .build && test/tests
61108

@@ -127,19 +174,34 @@ workflows:
127174
jobs:
128175
- format
129176
- shellcheck
130-
- test-cmake:
177+
- build-and-test-cmake:
131178
matrix:
132179
parameters:
133180
toolchain: ["gnu", "llvm"]
134-
sanitize: ["on", "off"]
135181
arch: ["amd64", "arm64"]
136182
- build-bazel:
137183
matrix:
138184
parameters:
139-
arch: ["amd64", "arm64"]
140185
toolchain: ["gnu", "llvm"]
141-
- coverage
186+
arch: ["amd64", "arm64"]
187+
bazelrc: [".bazelrc.absl", ".bazelrc.std"]
188+
- build-and-test-windows-cmake:
189+
matrix:
190+
parameters:
191+
arch: ["amd64"]
192+
- build-and-test-windows-bazel:
193+
matrix:
194+
parameters:
195+
bazelrc: [".bazelrc.absl", ".bazelrc.std"]
196+
- coverage:
197+
requires:
198+
- build-and-test-cmake
142199
- system-tests:
200+
requires:
201+
- build-bazel
202+
- build-and-test-cmake
203+
- build-and-test-windows-bazel
204+
- build-and-test-windows-cmake
143205
filters:
144206
branches:
145207
only:

BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ cc_library(
117117
"src/datadog/version.h",
118118
"src/datadog/w3c_propagation.h",
119119
],
120-
copts = [
121-
"-Wall",
122-
"-Wextra",
123-
"-Werror",
124-
"-pedantic",
125-
"-std=c++17",
126-
"-DDD_USE_ABSEIL_FOR_ENVOY",
127-
],
128120
strip_include_prefix = "src/",
129121
visibility = ["//visibility:public"],
130122
deps = [

0 commit comments

Comments
 (0)