{% set version = "17.0.6" %}

package:
  name: libcxx_and_libcxxabi
  version: {{ version }}

source:
  - url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version.replace(".rc", "-rc") }}/llvm-project-{{ version.replace(".rc", "rc") }}.src.tar.xz
    sha256: 58a8818c60e6627064f312dbf46c02d9949956558340938b71cf731ad8bc0813
    patches:
      - patches/0001-Support-legacy-standalone-builds.patch
      # See https://lists.llvm.org/pipermail/libcxx-dev/2021-July/001172.html
      - patches/0002-Fix-ABI-compatibility-with-system.patch
      - patches/0003-custom-error-message-for-old-sdk.patch
      # upstream removed fallbacks in case the underlying libc didn't support C11 in
      # https://github.com/llvm/llvm-project/commit/21f73d5826fb5024a27eaacafadfa316f58949c5;
      # using new libcxx with old clang versions (beyond what upstream supports) relies on
      # having these fallbacks in place. Drop if conflict-resolution becomes too messy.
      - patches/0004-Revert-libc-Remove-workaround-for-C11-features-on-co.patch

build:
  number: 0
  skip: true  # [win]
  skip: true  # [ppc64le or aarch64]
  ignore_run_exports:
    - libstdcxx-ng
  missing_dso_whitelist:
    - /usr/lib/libc++abi.dylib

requirements:
  build:
    - cmake
    - ninja
    - {{ compiler('cxx') }}
    - {{ stdlib('c') }}
    - python >3               # [not osx]
  host:
    - clangdev {{ version }}  # [not osx]
    - llvmdev {{ version }}   # [not osx]

outputs:
  - name: libcxx
    files:
      - include/c++
      - Library/include/c++
      - lib/libc++.*
      - lib/libc++fs.*
      - lib/libc++experimental.*
      - Library/bin/c++*.dll
      - Library/lib/c++*.lib
      - Library/lib/libc++*.lib
    requirements:
      build:
        - {{ compiler('cxx') }}
        - {{ stdlib('c') }}
      host:
      run:
        - {{ pin_subpackage("libcxxabi", exact=True) }}    # [linux]
      run_constrained:
        - sysroot_{{ target_platform }} >={{ c_stdlib_version }}    # [linux]
    test:
      requires:
        - clang                  # [osx]
        - clangxx
        - ld64                   # [osx]
        - cctools                # [osx]
        - llvm-tools             # [osx]
        - {{ compiler('cxx') }}  # [not osx]
      files:
        - test_sources
        - compile_test.sh   # [unix]
        - compile_test.bat  # [win]
      commands:
        # Dummy var for different hashes
        - echo {{ dummy_var }}                                    # [osx]
        - if not exist %LIBRARY_INC%\\c++\\v1\\iterator exit 1    # [win]
        - test -f $PREFIX/include/c++/v1/iterator                 # [unix]
        - bash compile_test.sh                                    # [unix]
        - compile_test.bat                                        # [win]
        # make sure we inserted link to our docs wherever it is necessary;
        # i.e. everywhere there's a string "availability(macos,...,introduced=<ver>)" for osx version >10.13;
        # 'grep -v' inverts the match but returns non-zero exit code if no lines are returned; so we use 'wc -l';
        # we want to have zero lines that don't either: contain our link or are for <=10.13 (lowest occurring in that file is 10.9)
        - if [ 0 -eq $(cat ${PREFIX}/include/c++/v1/__availability | grep "availability(macos" | grep -vE "(conda-forge|10.9|10.1[0-3])" | wc -l) ]; then exit 0; else exit 1; fi  # [osx]
        # !!!!!!!!!!!! README !!!!!!!!!!!!!!!!!!
        # we do not ship libcxxabi on OSX - this breaks exception passing
        - if [ -f $PREFIX/lib/libc++abi.dylib ]; then exit 1; fi  # [osx]
        - test -f $PREFIX/lib/libc++abi.so                        # [linux]

      # Following 2 projects had issues with libc++, so check them
      # before releasing just to be sure.
      downstreams:              # [osx]
        - python-symengine      # [osx]
        - openturns             # [osx]
        # test current libcxx against old clang builds;
        # version correspondence is 0.{{ CLANG_MAJOR }}
        - libcxx-testing 0.18   # [osx]
        - libcxx-testing 0.17   # [osx]
        - libcxx-testing 0.16   # [osx]
        - libcxx-testing 0.15   # [osx]
        - libcxx-testing 0.14   # [osx]
        - libcxx-testing 0.13   # [osx]
        - libcxx-testing 0.12   # [osx]
        - libcxx-testing 0.11   # [osx]

  - name: libcxxabi
    build:
      skip: true  # [not linux]
    files:
      - lib/libc++abi.*
    requirements:
      run_constrained:
        - libcxx {{ version }}.*
    test:
      commands:
        - test -f $PREFIX/lib/libc++abi.so  # [linux]

about:
  home: http://libcxx.llvm.org/
  license: Apache-2.0 WITH LLVM-exception
  license_file: libcxx/LICENSE.TXT
  license_family: Apache
  summary: LLVM C++ standard library
  dev_url: https://github.com/llvm/llvm-project

extra:
  recipe-maintainers:
    - SylvainCorlay
    - inducer
    - jakirkham
    - isuruf
    - beckermr
    - timsnyder
    - h-vetinari
  feedstock-name: libcxx
