Skip to content

Commit 16b5c8d

Browse files
authored
Merge pull request #77 from boostorg/72-cannot-build-on-macos
Adds support for libc++.
2 parents d01a9ac + 8ef4d3c commit 16b5c8d

File tree

4 files changed

+79
-17
lines changed

4 files changed

+79
-17
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@ jobs:
9898
fail-fast: false
9999
matrix:
100100
include:
101-
- { toolset: gcc, compiler: g++-11, install: g++-11, os: ubuntu-22.04, cxxstd: 'c++17' }
102-
- { toolset: gcc, compiler: g++-11, install: g++-11, os: ubuntu-22.04, cxxstd: 'c++20' }
103-
- { toolset: clang, compiler: clang++-11, install: clang-11, os: ubuntu-22.04, cxxstd: 'c++17' }
104-
- { toolset: clang, compiler: clang++-11, install: clang-11, os: ubuntu-22.04, cxxstd: 'c++20' }
105-
- { toolset: clang, compiler: clang++-13, install: clang-13, os: ubuntu-22.04, cxxstd: 'c++17' }
106-
- { toolset: clang, compiler: clang++-13, install: clang-13, os: ubuntu-22.04, cxxstd: 'c++20' }
101+
- { toolset: gcc, compiler: g++-11, install: g++-11, os: ubuntu-22.04, cxxflags: '-std=c++17', ldflags: '' }
102+
- { toolset: gcc, compiler: g++-11, install: g++-11, os: ubuntu-22.04, cxxflags: '-std=c++20', ldflags: '' }
103+
- { toolset: clang, compiler: clang++-11, install: clang-11, os: ubuntu-22.04, cxxflags: '-std=c++17', ldflags: '' }
104+
- { toolset: clang, compiler: clang++-11, install: clang-11, os: ubuntu-22.04, cxxflags: '-std=c++20', ldflags: '' }
105+
- { toolset: clang, compiler: clang++-13, install: clang-13, os: ubuntu-22.04, cxxflags: '-std=c++17', ldflags: '' }
106+
- { toolset: clang, compiler: clang++-13, install: clang-13, os: ubuntu-22.04, cxxflags: '-std=c++20', ldflags: '' }
107+
- { toolset: clang, compiler: clang++-14, install: 'clang-14 libc++-14-dev libc++abi-14-dev', os: ubuntu-22.04, cxxflags: '-std=c++17 -stdlib=libc++', ldflags: '-lc++' }
108+
- { toolset: clang, compiler: clang++-14, install: 'clang-14 libc++-14-dev libc++abi-14-dev', os: ubuntu-22.04, cxxflags: '-std=c++20 -stdlib=libc++', ldflags: '-lc++' }
107109
runs-on: ${{ matrix.os }}
108110
env:
109-
CXXFLAGS: -g -O0 -std=${{matrix.cxxstd}} -Wall -Wextra
111+
CXXFLAGS: -g -O0 ${{matrix.cxxflags}} -Wall -Wextra
112+
LDFLAGS: ${{matrix.ldflags}}
110113
steps:
111114
- name: Checkout
112115
uses: actions/checkout@v3
@@ -124,7 +127,7 @@ jobs:
124127
platform_version: 22.04
125128
- name: Run CMake
126129
run: |
127-
BOOST_ROOT=${{steps.install-boost.outputs.BOOST_ROOT}} cmake -DCMAKE_CXX_COMPILER="${{matrix.compiler}}" -DCMAKE_CXX_FLAGS="${{env.CXXFLAGS}}"
130+
BOOST_ROOT=${{steps.install-boost.outputs.BOOST_ROOT}} cmake -DCMAKE_CXX_COMPILER="${{matrix.compiler}}" -DCMAKE_CXX_FLAGS="${{env.CXXFLAGS}}" -DCMAKE_EXE_LINKER_FLAGS="${{env.LDFLAGS}}"
128131
- name: Build
129132
run: make
130133
- name: Check

CMakePresets.json

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,63 @@
4040
}
4141
},
4242
{
43-
"name": "dev",
43+
"name": "g++-11-cpp17",
4444
"generator": "Unix Makefiles",
4545
"hidden": false,
4646
"inherits": ["cmake-pedantic"],
47-
"binaryDir": "${sourceDir}/build/dev",
47+
"binaryDir": "${sourceDir}/build/g++-11-cpp17",
4848
"cacheVariables": {
4949
"CMAKE_BUILD_TYPE": "Debug",
5050
"CMAKE_CXX_EXTENSIONS": "OFF",
5151
"CMAKE_CXX_FLAGS": "-Wall -Wextra -fsanitize=address",
5252
"CMAKE_CXX_COMPILER": "g++-11",
5353
"CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address",
5454
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
55-
"PROJECT_BINARY_DIR": "${sourceDir}/build/dev",
56-
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/dev/doc/"
55+
"PROJECT_BINARY_DIR": "${sourceDir}/build/g++-11-cpp17",
56+
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/g++-11-cpp17/doc/"
57+
}
58+
},
59+
{
60+
"name": "libc++-14-cpp17",
61+
"generator": "Unix Makefiles",
62+
"hidden": false,
63+
"inherits": ["cmake-pedantic"],
64+
"binaryDir": "${sourceDir}/build/libc++-14-cpp17",
65+
"cacheVariables": {
66+
"CMAKE_BUILD_TYPE": "Debug",
67+
"CMAKE_CXX_EXTENSIONS": "OFF",
68+
"CMAKE_CXX_FLAGS": "-Wall -Wextra -stdlib=libc++ -std=c++17",
69+
"CMAKE_EXE_LINKER_FLAGS": "-lc++",
70+
"CMAKE_CXX_COMPILER": "clang++-14",
71+
"CMAKE_SHARED_LINKER_FLAGS": "",
72+
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
73+
"PROJECT_BINARY_DIR": "${sourceDir}/build/libc++-14-cpp17",
74+
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/libc++-14-cpp17/doc/"
75+
}
76+
},
77+
{
78+
"name": "libc++-14-cpp20",
79+
"generator": "Unix Makefiles",
80+
"hidden": false,
81+
"inherits": ["cmake-pedantic"],
82+
"binaryDir": "${sourceDir}/build/libc++-14-cpp20",
83+
"cacheVariables": {
84+
"CMAKE_BUILD_TYPE": "Debug",
85+
"CMAKE_CXX_EXTENSIONS": "OFF",
86+
"CMAKE_CXX_FLAGS": "-Wall -Wextra -stdlib=libc++ -std=c++17",
87+
"CMAKE_EXE_LINKER_FLAGS": "-lc++",
88+
"CMAKE_CXX_COMPILER": "clang++-14",
89+
"CMAKE_SHARED_LINKER_FLAGS": "",
90+
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
91+
"PROJECT_BINARY_DIR": "${sourceDir}/build/libc++-14-cpp20",
92+
"DOXYGEN_OUTPUT_DIRECTORY": "${sourceDir}/build/libc++-14-cpp20/doc/"
5793
}
5894
},
5995
{
6096
"name": "clang-tidy",
6197
"generator": "Unix Makefiles",
6298
"hidden": false,
63-
"inherits": ["dev"],
99+
"inherits": ["g++-11-cpp17"],
64100
"binaryDir": "${sourceDir}/build/clang-tidy",
65101
"cacheVariables": {
66102
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--header-filter=${sourceDir}/include/*",
@@ -70,7 +106,9 @@
70106
],
71107
"buildPresets": [
72108
{ "name": "coverage", "configurePreset": "coverage" },
73-
{ "name": "dev", "configurePreset": "dev" },
109+
{ "name": "g++-11-cpp17", "configurePreset": "g++-11-cpp17" },
110+
{ "name": "libc++-14-cpp17", "configurePreset": "libc++-14-cpp17" },
111+
{ "name": "libc++-14-cpp20", "configurePreset": "libc++-14-cpp20" },
74112
{ "name": "clang-tidy", "configurePreset": "clang-tidy" }
75113
],
76114
"testPresets": [
@@ -80,8 +118,10 @@
80118
"output": {"outputOnFailure": true},
81119
"execution": {"noTestsAction": "error", "stopOnFailure": true}
82120
},
83-
{ "name": "coverage", "configurePreset": "coverage", "inherits": ["test"] },
84-
{ "name": "dev", "configurePreset": "dev", "inherits": ["test"] },
85-
{ "name": "clang-tidy", "configurePreset": "clang-tidy", "inherits": ["test"] }
121+
{ "name": "coverage", "configurePreset": "coverage", "inherits": ["test"] },
122+
{ "name": "g++-11-cpp17", "configurePreset": "g++-11-cpp17", "inherits": ["test"] },
123+
{ "name": "libc++-14-cpp17", "configurePreset": "libc++-14-cpp17", "inherits": ["test"] },
124+
{ "name": "libc++-14-cpp20", "configurePreset": "libc++-14-cpp20", "inherits": ["test"] },
125+
{ "name": "clang-tidy", "configurePreset": "clang-tidy", "inherits": ["test"] }
86126
]
87127
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ Acknowledgement to people that helped shape Boost.Redis
813813
* Implements full-duplex communication. Before these changes the connection would wait for a response to arrive before sending the next one. Now requests are continuously coalesced and written to the socket. This made the request::coalesce unnecessary and threfore it was removed.
814814
* Adds native json support for Boost.Describe'd classes, see cpp20_json_serialization.cpp for how to use it.
815815
* Upgrades to Boost 1.81.0.
816+
* Fixes build with libc++.
816817

817818
### v1.4.0-1
818819

include/boost/redis/adapter/detail/adapters.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
#include <string_view>
3030
#include <charconv>
3131

32+
// See https://stackoverflow.com/a/31658120/1077832
33+
#include<ciso646>
34+
#ifdef _LIBCPP_VERSION
35+
#else
36+
#include <cstdlib>
37+
#endif
38+
3239
namespace boost::redis::adapter::detail
3340
{
3441

@@ -51,9 +58,20 @@ void boost_redis_from_bulk(bool& t, std::string_view sv, system::error_code&)
5158
inline
5259
void boost_redis_from_bulk(double& d, std::string_view sv, system::error_code& ec)
5360
{
61+
#ifdef _LIBCPP_VERSION
62+
// The string in sv is not null terminated and we also don't know
63+
// if there is enough space at the end for a null char. The easiest
64+
// thing to do is to create a temporary.
65+
std::string const tmp{sv.data(), sv.data() + std::size(sv)};
66+
char* end{};
67+
d = std::strtod(tmp.data(), &end);
68+
if (d == HUGE_VAL || d == 0)
69+
ec = redis::error::not_a_double;
70+
#else
5471
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), d);
5572
if (res.ec != std::errc())
5673
ec = redis::error::not_a_double;
74+
#endif // _LIBCPP_VERSION
5775
}
5876

5977
template <class CharT, class Traits, class Allocator>

0 commit comments

Comments
 (0)