{% set version = "17.0.6" %}
{% set major_ver = version.split(".")[0] %}

package:
  name: llvm-package
  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/0002-restore-macos-10.9-support.patch
    # These two patches remove expected test failures.
    - patches/0004-remove-unsupported-intrinsic-test.patch
    - patches/0005-remove-permission-based-unit-tests.patch
    # This patches cmake code which isn't hit in the current configuration, however it's kept in case we want to build
    # libllvm-c in the future
    - patches/osx_ver.patch
    # A different approach to this fix: https://github.com/conda-forge/llvmdev-feedstock/commit/1da42e54b055d26bc58da77bd1f88ad460ac90f4
    - patches/MSVC_DIA_SDK_path_fix.diff  # [win]

build:
  number: 0
  merge_build_host: false

requirements:
  build:
    - {{ compiler('cxx') }}
    - cmake
    - ninja
    - python >=3
    - libcxx {{ cxx_compiler_version }}  # [osx]
    - patch       # [not win]
    - m2-patch    # [win]
    - git         # [(linux and x86_64)]
  host:
    - libcxx {{ cxx_compiler_version }}  # [osx]
    - libffi {{ libffi }}   # [unix]
    # libxml2 supports a windows-only feature, see https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/llvm/include/llvm/WindowsManifest/WindowsManifestMerger.h
    - libxml2 {{ libxml2 }}  # [win]
    - zlib {{ zlib }}
    - zstd {{ zstd }}

outputs:
  # Contains everything
  - name: llvmdev
    script: install_llvm.sh  # [not win]
    script: install_llvm.bat  # [win]
    build:
      skip: true  # [(win and vc<14)]
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
        - python >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libxml2 {{ libxml2 }}  # [win]
        - zlib {{ zlib }}
        - zstd {{ zstd }}
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libcxx >={{ cxx_compiler_version }}  # [osx]
    test:
      commands:
        - $PREFIX/bin/llvm-config --libs                                 # [not win]
        - test -f $PREFIX/include/llvm/Pass.h                           # [not win]
        - test -f $PREFIX/lib/libLLVMCore.a                             # [not win]
        - $PREFIX/libexec/llvm/not false                                # [not win]
        - $PREFIX/bin/llvm-nm --help                                    # [not win]
        - if not exist %LIBRARY_INC%\\llvm\\Pass.h exit 1               # [win]
        - if not exist "%LIBRARY_PREFIX%"\\libexec\llvm\not.exe exit 1  # [win]
        - if not exist "%LIBRARY_BIN%"\\llvm-nm.exe exit 1              # [win]
        - llvm-nm.exe --help                                            # [win]

  # Contains the shared libraries. To make different LLVM libraries co-installable
  # soversion is appended to the package name.
  - name: libllvm{{ major_ver }}
    script: install_llvm.sh  # [not win]
    build:
      skip: true  # [win and vc<14]
      run_exports:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, max_pin="x.x") }}  # [not win]
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - ninja                  # [not win]
        - cmake                  # [not win]
        - python >=3             # [not win]
      host:
        - libcxx {{ cxx_compiler_version }}  # [osx]
        - libffi {{ libffi }}  # [unix]
        - libxml2 {{ libxml2 }}  # [win]
        - zlib {{ zlib }}
        - zstd {{ zstd }}
      run:
        - libcxx >={{ cxx_compiler_version }}  # [osx]
        - {{ pin_compatible('libffi', max_pin='x.x') }}  # [unix]
        - zlib    # [osx]
    test:
      commands:
        - test -f $PREFIX/lib/libLLVM-{{ major_ver }}${SHLIB_EXT}  # [not win]

  # This is a meta package so that people can use the latest libllvm and also
  # for run_exports
  - name: llvm
    build:
      skip: true  # [(win and vc<14)]
      run_exports:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, max_pin="x.x") }}  # [not win]
    requirements:
      build:
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}  # [not win]
        - libxml2 {{ libxml2 }}  # [win]
        - zlib {{ zlib }}
        - zstd {{ zstd }}
      run:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}  # [not win]
      run_constrained:             # [not win]
        - llvmdev   {{ version }}  # [not win]
    test:
      commands:
        - echo "Hello World!"

  # Contains LLVM tools
  - name: llvm-tools
    script: install_llvm.sh   # [not win]
    script: install_llvm.bat  # [win]
    build:
      skip: true  # [(win and vc<14)]
      missing_dso_whitelist:  # [s390x]
        - $RPATH/ld64.so.1    # [s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
        - python >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libxml2 {{ libxml2 }}  # [win]
        - zlib {{ zlib }}
        - zstd {{ zstd }}
        - libcxx {{ cxx_compiler_version }}  # [osx]
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libcxx >={{ cxx_compiler_version }}  # [osx]
      run_constrained:
        - llvmdev   {{ version }}
    test:
      commands:
        - $PREFIX/bin/llc -version                               # [not win]
        - if not exist "%LIBRARY_BIN%"\\llc.exe exit 1           # [win]
        - llc -version                                           # [win]

  - name: lit
    build:
      script: python -m pip install llvm/utils/lit --no-deps --no-build-isolation -vv
      skip: true  # [py<30]
      entry_points:
        # upstream LLVM is inconsistent; there's one way specified in lit's setup.py...
        - lit = lit.main:main
        # ... and then the CMake files we install here (e.g. AddLLVM.cmake) look for another
        - llvm-lit = lit.main:main
    requirements:
      host:
        - python
        - pip
        - setuptools
        - wheel
      run:
        - python
    test:
      imports:
        - lit
      requires:
        - pip
      commands:
        - pip check
        - lit -h
        - llvm-lit -h

about:
  home: https://llvm.org/
  dev_url: https://github.com/llvm/llvm-project
  doc_url: https://llvm.org/docs/
  license: Apache-2.0 WITH LLVM-exception
  license_file: llvm/LICENSE.TXT
  license_family: Apache
  summary: Development headers and libraries for LLVM
  description: |
    A toolkit for the construction of highly optimized compilers,
    optimizers, and run-time environments.

extra:
  skip-lints:
    # there are false positives for these checks,
    # for some of the individual outputs.
    - output_missing_script
    - missing_tests
    - wrong_output_script_key
  recipe-maintainers:
    - inducer
    - jakirkham
    - mingwandroid
    - SylvainCorlay
    - isuruf
    - timsnyder
    - xhochy
    - h-vetinari
    - danpetry
