{% set version = "14.0.6" %}
{% set major_version = version.split(".")[0] %}

package:
  name: mlir-split
  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: 8b3cfd7bc695bd6cea0f37f53f0981f34f87496e79e2529874fd03a2f9dd3a8a
    patches:
      # https://reviews.llvm.org/D99470
      - 0001-Support-cross-compiling-standalone-MLIR.patch
      # https://github.com/llvm/llvm-project/issues/53989
      - 0002-Revert-Disable-the-MLIR-ExecutionEngine-library-when.patch

build:
  number: 0

requirements:
  build:
    - cmake
    - ninja
    - {{ compiler('cxx') }}
    - patch       # [not win]
    - m2-patch    # [win]
  host:
    - llvmdev {{ version }}
    - llvm {{ version }}
    - zlib

outputs:
  - name: mlir
    script: install_mlir.sh  # [unix]
    script: install_mlir.bat  # [win]
    build:
      missing_dso_whitelist:  # [linux and s390x]
        - $RPATH/ld64.so.1    # [linux and s390x]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
      host:
        - {{ pin_subpackage("libmlir", exact=True) }}
        - llvmdev {{ version }}
        - llvm {{ version }}
        - zlib
      run:
        - {{ pin_subpackage("libmlir", exact=True) }}
        - llvmdev {{ version }}
    test:
      commands:
        - test -f "$PREFIX/include/mlir-c/Support.h"               # [unix]
        - test -f "$PREFIX/lib/libMLIRIR.a"                        # [unix]
        - if not exist %LIBRARY_INC%\\mlir-c\\Support.h exit 1     # [win]
        - if not exist %LIBRARY_LIB%\\MLIRIR.lib exit 1            # [win]
        - $PREFIX/bin/mlir-opt -version                            # [not win]
        - if not exist "%LIBRARY_BIN%"\\mlir-opt.exe exit 1        # [win]
        - mlir-opt -version                                        # [win]
        - mlir-tblgen -version

  - name: libmlir{{ major_version }}
    script: install_libmlir.sh   # [unix]
    script: install_libmlir.bat  # [win]
    build:
      run_exports:
        - {{ pin_subpackage("libmlir" + major_version, max_pin="x.x") }}   # [unix]
      skip: true  # [win]
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
      host:
        - llvmdev {{ version }}
        - llvm {{ version }}
        - zlib
    test:
      commands:
        - test ! -f "$PREFIX/lib/libMLIR$SHLIB_EXT"                                # [unix]
        - test ! -f "$PREFIX/lib/libmlir_runner_utils$SHLIB_EXT"                   # [unix]
        - test ! -f "$PREFIX/lib/libmlir_c_runner_utils$SHLIB_EXT"                 # [unix]
        - test ! -f "$PREFIX/lib/libmlir_c_runner_utils_static.a"                  # [unix]
        - test -f "$PREFIX/lib/libMLIR.so.{{ major_version }}"                     # [linux]
        - test -f "$PREFIX/lib/libmlir_runner_utils.so.{{ major_version }}"        # [linux]
        - test -f "$PREFIX/lib/libmlir_c_runner_utils.so.{{ major_version }}"      # [linux]
        - test -f "$PREFIX/lib/libMLIR.{{ major_version }}.dylib"                  # [osx]
        - test -f "$PREFIX/lib/libmlir_runner_utils.{{ major_version }}.dylib"     # [osx]
        - test -f "$PREFIX/lib/libmlir_c_runner_utils.{{ major_version }}.dylib"   # [osx]

  - name: libmlir
    script: install_libmlir.sh   # [unix]
    script: install_libmlir.bat  # [win]
    build:
      {% if not win %}
      run_exports:   # [unix]
        - {{ pin_subpackage("libmlir" + major_version, max_pin="x.x") }}   # [unix]
      {% endif %}
    requirements:
      build:
        - {{ compiler('cxx') }}
        - cmake
        - ninja
      host:
        - llvmdev {{ version }}
        - llvm {{ version }}
        - zlib
        - {{ pin_subpackage("libmlir" + major_version, exact=True) }}  # [unix]
      run:
        - {{ pin_subpackage("libmlir" + major_version, exact=True) }}  # [unix]
    test:
      commands:
        - test -f "$PREFIX/lib/libMLIR${SHLIB_EXT}"            # [unix]
        - if exist %LIBRARY_BIN%\\libmlir.dll exit 1           # [win]

about:
  home: https://llvm.org/
  license: Apache-2.0 WITH LLVM-exception
  license_file: mlir/LICENSE.TXT
  license_family: Apache
  summary: Multi-Level IR Compiler Framework
  dev_url: https://github.com/llvm/llvm-project
  doc_url: https://llvm.org/docs/

extra:
  recipe-maintainers:
    - isuruf
    - kaushikcfd
    - katietz
    - xhochy
  feedstock-name: mlir
