# Copyright (c) 2022, NVIDIA CORPORATION.

# Usage:
#   conda build . -c conda-forge -c nvidia -c rapidsai
{% set version = environ.get('GIT_DESCRIBE_TAG', '0.0.0.dev').lstrip('v') + environ.get('VERSION_SUFFIX', '') %}
{% set minor_version = version.split('.')[0] + '.' + version.split('.')[1] %}
{% set cuda_version = '.'.join(environ['RAPIDS_CUDA_VERSION'].split('.')[:2]) %}
{% set cuda_major = cuda_version.split('.')[0] %}
{% set cuda_spec = ">=" + cuda_major ~ ",<" + (cuda_major | int + 1) ~ ".0a0" %} # i.e. >=11,<12.0a0

package:
  name: libraft-split

source:
  git_url: ../../..

outputs:
  - name: libraft-headers
    version: {{ version }}
    script: build_libraft_headers.sh
    build:
      script_env: &script_env
        - AWS_ACCESS_KEY_ID
        - AWS_SECRET_ACCESS_KEY
        - CMAKE_C_COMPILER_LAUNCHER
        - CMAKE_CUDA_COMPILER_LAUNCHER
        - CMAKE_CXX_COMPILER_LAUNCHER
        - CMAKE_GENERATOR
        - PARALLEL_LEVEL
        - SCCACHE_BUCKET
        - SCCACHE_IDLE_TIMEOUT
        - SCCACHE_REGION
        - SCCACHE_S3_KEY_PREFIX=libraft-aarch64 # [aarch64]
        - SCCACHE_S3_KEY_PREFIX=libraft-linux64 # [linux64]
      number: {{ GIT_DESCRIBE_NUMBER }}
      string: cuda{{ cuda_major }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }}
      ignore_run_exports_from:
        - {{ compiler('cuda') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ compiler('cuda') }} {{ cuda_version }}
        - cmake {{ cmake_version }}
        - ninja
        - sysroot_{{ target_platform }} {{ sysroot_version }}
      host:
        - cuda-profiler-api {{ cuda_profiler_api_host_version }}
        - cudatoolkit ={{ cuda_version }}
        - libcublas {{ libcublas_host_version }}
        - libcublas-dev {{ libcublas_host_version }}
        - libcurand {{ libcurand_host_version }}
        - libcurand-dev {{ libcurand_host_version }}
        - libcusolver {{ libcusolver_host_version }}
        - libcusolver-dev {{ libcusolver_host_version }}
        - libcusparse {{ libcusparse_host_version }}
        - libcusparse-dev {{ libcusparse_host_version }}
        - librmm ={{ minor_version }}
      run:
        - {{ pin_compatible('cudatoolkit', max_pin='x', min_pin='x') }}
        - cuda-profiler-api {{ cuda_profiler_api_run_version }}
        - libcublas {{ libcublas_run_version }}
        - libcublas-dev {{ libcublas_run_version }}
        - libcurand {{ libcurand_run_version }}
        - libcurand-dev {{ libcurand_run_version }}
        - libcusolver {{ libcusolver_run_version }}
        - libcusolver-dev {{ libcusolver_run_version }}
        - libcusparse {{ libcusparse_run_version }}
        - libcusparse-dev {{ libcusparse_run_version }}
        - librmm ={{ minor_version }}
    about:
      home: https://rapids.ai/
      license: Apache-2.0
      summary: libraft-headers library
  - name: libraft-distance
    version: {{ version }}
    script: build_libraft_distance.sh
    build:
      script_env: *script_env
      number: {{ GIT_DESCRIBE_NUMBER }}
      string: cuda{{ cuda_major }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }}
      ignore_run_exports_from:
        - {{ compiler('cuda') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cuda') }} {{ cuda_version }}
        - {{ compiler('cxx') }}
        - cmake {{ cmake_version }}
        - ninja
        - sysroot_{{ target_platform }} {{ sysroot_version }}
      host:
        - {{ pin_subpackage('libraft-headers', exact=True) }}
        - cuda-profiler-api {{ cuda_profiler_api_host_version }}
        - libcublas {{ libcublas_host_version }}
        - libcublas-dev {{ libcublas_host_version }}
        - libcurand {{ libcurand_host_version }}
        - libcurand-dev {{ libcurand_host_version }}
        - libcusolver {{ libcusolver_host_version }}
        - libcusolver-dev {{ libcusolver_host_version }}
        - libcusparse {{ libcusparse_host_version }}
        - libcusparse-dev {{ libcusparse_host_version }}
      run:
        - {{ pin_subpackage('libraft-headers', exact=True) }}
    about:
      home: https://rapids.ai/
      license: Apache-2.0
      summary: libraft-distance library
  - name: libraft-nn
    version: {{ version }}
    script: build_libraft_nn.sh
    build:
      script_env: *script_env
      number: {{ GIT_DESCRIBE_NUMBER }}
      string: cuda{{ cuda_major }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }}
      ignore_run_exports_from:
        - {{ compiler('cuda') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cuda') }} {{ cuda_version }}
        - {{ compiler('cxx') }}
        - cmake {{ cmake_version }}
        - ninja
        - sysroot_{{ target_platform }} {{ sysroot_version }}
      host:
        - {{ pin_subpackage('libraft-headers', exact=True) }}
        - cuda-profiler-api {{ cuda_profiler_api_host_version }}
        - faiss-proc=*=cuda
        - lapack
        - libcublas {{ libcublas_host_version }}
        - libcublas-dev {{ libcublas_host_version }}
        - libcurand {{ libcurand_host_version }}
        - libcurand-dev {{ libcurand_host_version }}
        - libcusolver {{ libcusolver_host_version }}
        - libcusolver-dev {{ libcusolver_host_version }}
        - libcusparse {{ libcusparse_host_version }}
        - libcusparse-dev {{ libcusparse_host_version }}
        - libfaiss {{ libfaiss_version }}
      run:
        - faiss-proc=*=cuda
        - libfaiss {{ libfaiss_version }}
        - {{ pin_subpackage('libraft-headers', exact=True) }}
    about:
      home: https://rapids.ai/
      license: Apache-2.0
      summary: libraft-nn library
  - name: libraft-tests
    version: {{ version }}
    script: build_libraft_tests.sh
    build:
      script_env: *script_env
      number: {{ GIT_DESCRIBE_NUMBER }}
      string: cuda{{ cuda_major }}_{{ GIT_DESCRIBE_HASH }}_{{ GIT_DESCRIBE_NUMBER }}
      ignore_run_exports_from:
        - {{ compiler('cuda') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cuda') }} {{ cuda_version }}
        - {{ compiler('cxx') }}
        - cmake {{ cmake_version }}
        - ninja
        - sysroot_{{ target_platform }} {{ sysroot_version }}
      host:
        - {{ pin_subpackage('libraft-distance', exact=True) }}
        - {{ pin_subpackage('libraft-headers', exact=True) }}
        - {{ pin_subpackage('libraft-nn', exact=True) }}
        - cuda-profiler-api {{ cuda_profiler_api_host_version }}
        - gmock {{ gtest_version }}
        - gtest {{ gtest_version }}
        - libcublas {{ libcublas_host_version }}
        - libcublas-dev {{ libcublas_host_version }}
        - libcurand {{ libcurand_host_version }}
        - libcurand-dev {{ libcurand_host_version }}
        - libcusolver {{ libcusolver_host_version }}
        - libcusolver-dev {{ libcusolver_host_version }}
        - libcusparse {{ libcusparse_host_version }}
        - libcusparse-dev {{ libcusparse_host_version }}
      run:
        - {{ pin_subpackage('libraft-distance', exact=True) }}
        - {{ pin_subpackage('libraft-headers', exact=True) }}
        - {{ pin_subpackage('libraft-nn', exact=True) }}
        - gmock {{ gtest_version }}
        - gtest {{ gtest_version }}
    about:
      home: https://rapids.ai/
      license: Apache-2.0
      summary: libraft tests
