{% set version = "11.1.0" %}
# Build with old when bootstrapping on macOS
{% set cxx_compiler_version_bootstrap = "4.0.0" %}  # [osx]
{% set sha256 = "ce8508e318a01a63d4e8b3090ab2ded3c598a50258cc49e2625b9120d4c03ea5" %}
{% set ccache_method = 'native' %}  # [unix]
{% set ccache_method = 'symlinks' %}  # [win]

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

{% set posix = 'm2-' if win else '' %}

package:
  name: llvm-package
  version: {{ version }}

source:
  url: https://github.com/llvm/llvm-project/releases/download/llvmorg-{{ version.replace(".rc", "-rc") }}/llvm-{{ version.replace(".rc", "rc") }}.src.tar.xz
  sha256: {{ sha256 }}
  patches:
    - patches/intel-D47188-svml-VF.patch    # Fixes vectorizer and extends SVML support
    - patches/expect-fastmath-entrypoints-in-add-TLI-mappings.ll.patch # adjusts test added in 10.0.0 for intel-D47188-svml-VF.patch effects
    # Revert an upstream change for Numba
    # ref: https://github.com/numba/llvmlite/blob/v0.29.0/conda-recipes/0001-Revert-Limit-size-of-non-GlobalValue-name.patch
    - patches/numba-0001-Revert-Limit-size-of-non-GlobalValue-name.patch
    #- patches/amd-roc-2.7.0.diff
    - patches/pass-through-qemu-ld-prefix.diff
    # Don't link libLLVM.dylib to llvm-config. Makes it easier for cross compiling
    # - patches/llvm-config-no-libLLVM.diff
    - patches/xfail-permission-test-on-linux.patch  # [unix]
    - patches/skip-osx-getMacOSHostVersion.patch  # [osx]
    - patches/MSVC_DIA_SDK_path_fix.diff  # [win]
    - patches/benchmark_register_include_fix.diff

build:
  number: {{ build_number }}
  skip: True  # [win and vc<14]
  # we do not yet provide llvm on linux-s390x
  skip: true    # [s390x]
  merge_build_host: false

requirements:
  build:
    - {{ compiler('cxx') }}
    - {{ ccache(ccache_method) }}
    - cmake
    - ninja     # [win]
    - python >=3
    - make      # [not win]
    - m2-coreutils  # [win]
    - m2-grep  # [win]
    - m2-sed  # [win]
    - {{posix}}make
    - {{posix}}patch
    - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
  host:
    - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
    - zlib
    - libxml2   # [win]

outputs:
  # Contains everything
  - name: llvmdev
    script: install_llvm.sh  # [not win]
    script: install_llvm.bat  # [win]
    build:
      skip: true  # [win and vc<14]
      activate_in_script: true
      ignore_run_exports:
        - zlib  # [not linux]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - {{ ccache(ccache_method) }}
        - cmake
        - make                             # [not win]
        - m2-coreutils  # [win]
        - m2-grep  # [win]
        - m2-sed  # [win]
        - ninja     # [win]
        - python    >=3
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
        - zlib  # [not linux]
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - {{ pin_subpackage("llvm-tools", exact=True) }}
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
        - zlib  # [not linux]
    test:
      commands:
        - $PREFIX/bin/llvm-config --libs                         # [not win]
        - if not exist %LIBRARY_INC%\\llvm\\Pass.h exit 1        # [win]
        - test -f $PREFIX/include/llvm/Pass.h                    # [unix]
        - test -f $PREFIX/lib/libLLVMCore.a                      # [not win]
        - $PREFIX/libexec/llvm/not false                               # [not win]
        - if not exist "%LIBRARY_PREFIX%"\\libexec\llvm\not.exe exit 1        # [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]
      activate_in_script: true
      ignore_run_exports:
        - zlib
      run_exports:   # [not win]
        - {{ pin_subpackage("libllvm" + major_ver, max_pin="x.x") }}  # [not win]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - {{ ccache(ccache_method) }}
        - cmake                    # [not win]
        - make                     # [not win]
        - m2-coreutils  # [win]
        - m2-grep  # [win]
        - python    >=3            # [not win]
      host:
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
        - zlib
      run:
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
        - zlib
    test:                                                          # [unix]
      commands:                                                    # [unix]
        - test -f $PREFIX/lib/libLLVM-{{ major_ver }}${SHLIB_EXT}  # [unix]

  # 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]
      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]
      activate_in_script: true
    requirements:
      build:
        - {{ compiler('cxx') }}
        - {{ ccache(ccache_method) }}
        - cmake
        - make                             # [not win]
        - m2-coreutils  # [win]
        - m2-grep  # [win]
        - m2-sed  # [win]
        - ninja     # [win]
        - python    >=3
        - {{posix}}make
        - {{posix}}patch
      host:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [osx]
        - zlib
      run:
        - {{ pin_subpackage("libllvm" + major_ver, exact=True) }}
        - libcxx >={{ cxx_compiler_version_bootstrap }}  # [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 utils/lit --no-deps -vv
      activate_in_script: true
      skip: true  # [py<30]
      entry_points:
        - lit = lit:main
    requirements:
      host:
        - python
        - pip
        - setuptools
        - wheel
      run:
        - python
    test:
      imports:
        - lit

about:
  home: https://llvm.org/
  doc_url: https://llvm.org/docs/
  dev_url: https://github.com/llvm/llvm-project/
  license: Apache-2.0 WITH LLVM-exception
  license_file: LICENSE.TXT
  license_family: Apache
  summary: Development headers and libraries for LLVM

extra:
  recipe-maintainers:
    - inducer
    - jakirkham
    - mingwandroid
    - SylvainCorlay
    - isuruf
    - timsnyder
