Search code examples
pythonc++cmakegithub-actions

No member named 'replace' in namespace 'std::ranges' message in github actions, even with -std=c++20


I have a python package on github, that runs C++ code with pybind. I figured I'd add github actions to do tests. The build fails on macos-latest (the irony being that it compiles just fine on my local macos machine) with the following message:

FAILED: CMakeFiles/sequence_analysis_cpp.dir/src/sequence.cpp.o
  /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DVERSION_INFO=0.1.0 -Dsequence_analysis_cpp_EXPORTS -isystem /Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -isystem /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pip-build-env-148llo6b/overlay/lib/python3.11/site-packages/pybind11/include -O3 -DNDEBUG -std=gnu++20 -isysroot /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.6 -fPIC -MD -MT CMakeFiles/sequence_analysis_cpp.dir/src/sequence.cpp.o -MF CMakeFiles/sequence_analysis_cpp.dir/src/sequence.cpp.o.d -o CMakeFiles/sequence_analysis_cpp.dir/src/sequence.cpp.o -c /Users/runner/work/sequence_analysis/sequence_analysis/src/sequence.cpp
/Users/runner/work/sequence_analysis/sequence_analysis/src/sequence.cpp:101:18: error: no member named 'replace' in namespace 'std::ranges'
      std::ranges::replace(codon, 'T', 'U');
      ~~~~~~~~~~~~~^
  1 error generated.

It does set -std=gnu++20 as expected. I have #include <algorithm> in sequence.cpp.

CMakeLists.txt has:

set(CMAKE_CXX_STANDARD 20)

pip.yml has:

name: Pip

on:
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - master

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        platform: [windows-latest, macos-latest, ubuntu-latest]
        python-version: ["3.11"]

    runs-on: ${{ matrix.platform }}

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}

    - name: Add requirements
      run: python -m pip install --upgrade wheel setuptools biopython numpy

    - name: Build and install
      run: pip install --verbose .[test]

    - name: Test
      run: python -m pytest

What am I missing? Here's the repo in case I'm missing some critical info. This issue does not arise with ubuntu-latest, and windows-latest fails for other reasons (that I'm working on).


Solution

  • Currently, macos-latest points to macos-12 which has Xcode 14.2 as the default.

    As mentioned in the comments above, according to these compatibility matrices:

    you need Xcode 14.3 or later.

    macos-13 supports Xcode 14.3.1 as the default and it also supports Xcode 15.0 as well.

    So, simply switching from macos-latest (macos-12) to macos-13 should resolve your compiler issue.

    With macos-13 runner, you'll get the Xcode 14.3.1 by default. But, if you want to switch to 15.0, then you can simply set the DEVELOPER_DIR environment variable to specify that:

        - name: Build and install
          env:
            DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer
          run: pip install --verbose .[test]
    

    Alternatively, you can use xcode-select as well before running any compiler related commands:

    sudo xcode-select -s /Applications/Xcode_15.0.app/Contents/Developer
    

    Apart from that, your code currently has multiple issues e.g. missing header guards, invalid int to std::string conversion, undeclared variables, etc. Once your compiler issue is fixed, hopefully you'll be able to fix those easily. Good luck!