Skip to content

Commit

Permalink
Support clang++ from conda-forge (#81)
Browse files Browse the repository at this point in the history
Support clang++ from conda-forge and backport implementation when libc++<17 is used
  • Loading branch information
jjerphan authored Apr 23, 2024
1 parent 3f996ab commit 28056b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defaults:
jobs:
build:
runs-on: macos-${{ matrix.os }}
name: ${{ matrix.os }}-${{ matrix.config.name }}
name: ${{ matrix.os }}-${{ matrix.config.name }}-${{ matrix.compiler }}
strategy:
fail-fast: false
matrix:
Expand All @@ -22,12 +22,20 @@ jobs:
config:
- { name: Debug }
- { name: Release }
compiler:
- clang
- apple-clang

steps:

- name: Checkout code
uses: actions/checkout@v3

- name: Add specification of clang++ in the conda environment specification
if: matrix.compiler == 'clang'
run: |
echo " - clangxx==17.0.6" >> environment-dev.yml
- name: Set conda environment
uses: mamba-org/setup-micromamba@main
with:
Expand All @@ -36,6 +44,18 @@ jobs:
init-shell: bash
cache-downloads: true

- name: Use clang++ from conda-forge
if: matrix.compiler == 'clang'
run: |
echo "CXX=$CONDA_PREFIX/bin/clang++" >> $GITHUB_ENV
echo "CMAKE_CXX_COMPILER=$CONDA_PREFIX/bin/clang++" >> $GITHUB_ENV
- name: Use Apple Clang (i.e. clang++ from Xcode)
if: matrix.compiler == 'apple-clang'
run: |
echo "CXX=/usr/bin/clang++" >> $GITHUB_ENV
echo "CMAKE_CXX_COMPILER=/usr/bin/clang++" >> $GITHUB_ENV
- name: Configure using CMake
run: cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=${{matrix.config.name}} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DBUILD_TESTS=ON

Expand Down
8 changes: 4 additions & 4 deletions include/sparrow/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace sparrow
{
#if COMPILING_WITH_APPLE_CLANG
#if COMPILING_WITH_APPLE_CLANG || USING_LIBCPP_PRE_17

template <typename T>
concept OrdCategory = std::same_as<T, std::strong_ordering> || std::same_as<T, std::weak_ordering>
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace sparrow
constexpr auto lexicographical_compare_three_way(const R1& range1, const R2& range2, Cmp comp)
-> decltype(comp(*range1.cbegin(), *range2.cbegin()))
{
#if COMPILING_WITH_APPLE_CLANG
#if COMPILING_WITH_APPLE_CLANG || USING_LIBCPP_PRE_17
return lexicographical_compare_three_way_non_std(range1, range2, comp);
#else
return std::lexicographical_compare_three_way(
Expand All @@ -84,7 +84,7 @@ namespace sparrow
#endif
}

#if COMPILING_WITH_APPLE_CLANG
#if COMPILING_WITH_APPLE_CLANG || USING_LIBCPP_PRE_17
struct compare_three_way
{
template <class T, class U>
Expand All @@ -109,7 +109,7 @@ namespace sparrow
return lexicographical_compare_three_way<R1, R2>(
r1,
r2,
#if COMPILING_WITH_APPLE_CLANG
#if COMPILING_WITH_APPLE_CLANG || USING_LIBCPP_PRE_17
compare_three_way {}
#else
std::compare_three_way{}
Expand Down
6 changes: 6 additions & 0 deletions include/sparrow/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#define COMPILING_WITH_APPLE_CLANG 0
#endif

#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
#define USING_LIBCPP_PRE_17 1
#else
#define USING_LIBCPP_PRE_17 0
#endif

consteval bool is_apple_compiler()
{
return static_cast<bool>(COMPILING_WITH_APPLE_CLANG);
Expand Down

0 comments on commit 28056b8

Please sign in to comment.