Skip to content

Commit

Permalink
feat: add windows support
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Damien MEHALA authored and dmehala committed May 6, 2024
1 parent e576445 commit e98f1b7
Show file tree
Hide file tree
Showing 47 changed files with 800 additions and 401 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.bazelrc.absl
15 changes: 15 additions & 0 deletions .bazelrc.absl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# In order to support both Unixen and Windows, different styles of compiler
# flags must be used.
#
# This .bazelrc file specifies different compiler flags for Linux/Darwin versus
# Windows.
#
# This bazelrc defines the `DD_USE_ABSEIL_FOR_ENVOY` preprocessor macro, and so
# the resulting library will use `absl::string_view` and `absl::optional`
# instead of their standard (`std`) equivalents.

build --enable_platform_specific_config

build:linux --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic' --cxxopt='-DDD_USE_ABSEIL_FOR_ENVOY'
build:macos --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic' --cxxopt='-DDD_USE_ABSEIL_FOR_ENVOY'
build:windows --cxxopt='/std:c++17' --cxxopt='/DDD_USE_ABSEIL_FOR_ENVOY' --linkopt='ws2_32.lib'
15 changes: 15 additions & 0 deletions .bazelrc.std
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# In order to support both Unixen and Windows, different styles of compiler
# flags must be used.
#
# This .bazelrc file specifies different compiler flags for Linux/Darwin versus
# Windows.
#
# This bazelrc does _not_ define the `DD_USE_ABSEIL_FOR_ENVOY` preprocessor
# macro, and so the resulting library will use `std::string_view` and
# `std::optional` instead of their Abseil equivalents.

build --enable_platform_specific_config

build:linux --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic'
build:macos --cxxopt='-std=c++17' --cxxopt='-Wall' --cxxopt='-Wextra' --cxxopt='-pedantic'
build:windows --cxxopt='/std:c++17' --linkopt='ws2_32.lib'
80 changes: 71 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,65 @@ jobs:
type: string
arch:
type: string
bazelrc:
type: string
executor: docker-<< parameters.arch >>
environment:
MAKE_JOB_COUNT: 8
steps:
- checkout
- run: bin/with-toolchain << parameters.toolchain >> bazelisk build --jobs $MAKE_JOB_COUNT dd_trace_cpp
- run: bin/with-toolchain << parameters.toolchain >> bazelisk --bazelrc=<< parameters.bazelrc >> build --jobs $MAKE_JOB_COUNT dd_trace_cpp

test-cmake:
build-and-test-windows-bazel:
parameters:
toolchain:
# `bazelrc` is the path to the .bazelrc file to use in the build/test.
# The repository has two flavors: one that uses Abseil types (for use with
# Envoy), and one that uses std types.
bazelrc:
type: string
machine:
image: "windows-server-2022-gui:current"
resource_class: windows.medium
shell: powershell.exe -ExecutionPolicy Bypass
environment:
MAKE_JOB_COUNT: 4
steps:
- checkout
- run: choco install -y bazelisk
- run: bazelisk.exe --bazelrc=<< parameters.bazelrc >> build --jobs $env:MAKE_JOB_COUNT dd_trace_cpp

build-and-test-windows-cmake:
parameters:
arch:
type: string
sanitize:
machine:
image: "windows-server-2022-gui:current"
shell: powershell.exe -ExecutionPolicy Bypass
resource_class: "windows.large"
environment:
MAKE_JOB_COUNT: 8
steps:
- checkout
- run:
name: Install dependencies
command: |
choco install -y cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install -y ninja
- run:
name: Building
command: |
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch << parameters.arch >>
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DDD_TRACE_BUILD_TESTING=1 -G Ninja .
cmake --build build -j $env:MAKE_JOB_COUNT -v
- run:
name: Testing
command: |
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch << parameters.arch >>
.\build\test\tests.exe
build-and-test-cmake:
parameters:
toolchain:
type: string
arch:
type: string
Expand All @@ -55,7 +102,7 @@ jobs:
ASAN_OPTIONS: alloc_dealloc_mismatch=0
steps:
- checkout
- run: bin/with-toolchain << parameters.toolchain >> cmake . -B .build -DBUILD_TESTING=1 -DSANITIZE=<< parameters.sanitize >>
- run: bin/with-toolchain << parameters.toolchain >> cmake . -B .build -DCMAKE_BUILD_TYPE=Debug -DDD_TRACE_BUILD_TESTING=1
- run: cmake --build .build -j ${MAKE_JOB_COUNT} -v
- run: cd .build && test/tests

Expand Down Expand Up @@ -127,19 +174,34 @@ workflows:
jobs:
- format
- shellcheck
- test-cmake:
- build-and-test-cmake:
matrix:
parameters:
toolchain: ["gnu", "llvm"]
sanitize: ["on", "off"]
arch: ["amd64", "arm64"]
- build-bazel:
matrix:
parameters:
arch: ["amd64", "arm64"]
toolchain: ["gnu", "llvm"]
- coverage
arch: ["amd64", "arm64"]
bazelrc: [".bazelrc.absl", ".bazelrc.std"]
- build-and-test-windows-cmake:
matrix:
parameters:
arch: ["amd64"]
- build-and-test-windows-bazel:
matrix:
parameters:
bazelrc: [".bazelrc.absl", ".bazelrc.std"]
- coverage:
requires:
- build-and-test-cmake
- system-tests:
requires:
- build-bazel
- build-and-test-cmake
- build-and-test-windows-bazel
- build-and-test-windows-cmake
filters:
branches:
only:
Expand Down
8 changes: 0 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ cc_library(
"src/datadog/version.h",
"src/datadog/w3c_propagation.h",
],
copts = [
"-Wall",
"-Wextra",
"-Werror",
"-pedantic",
"-std=c++17",
"-DDD_USE_ABSEIL_FOR_ENVOY",
],
strip_include_prefix = "src/",
visibility = ["//visibility:public"],
deps = [
Expand Down
Loading

0 comments on commit e98f1b7

Please sign in to comment.