{% set name = "cuda-cupti" %}
{% set version = "12.4.127" %}
{% set lib_version = "2024.1.1" %}
{% set cuda_version = "12.4" %}
{% set platform = "linux-x86_64" %}  # [linux64]
{% set platform = "linux-ppc64le" %}  # [ppc64le]
{% set platform = "linux-sbsa" %}  # [aarch64]
{% set platform = "windows-x86_64" %}  # [win]
{% set target_name = "x86_64-linux" %}  # [linux64]
{% set target_name = "ppc64le-linux" %}  # [ppc64le]
{% set target_name = "sbsa-linux" %}  # [aarch64]
{% set target_name = "x64" %}  # [win]
{% set extension = "tar.xz" %}  # [not win]
{% set extension = "zip" %}  # [win]

package:
  name: {{ name|lower }}
  version: {{ version }}

source:
  url: https://developer.download.nvidia.com/compute/cuda/redist/cuda_cupti/{{ platform }}/cuda_cupti-{{ platform }}-{{ version }}-archive.{{ extension }}
  sha256: 232f4677a30335f4bafcd4a42b61d4cb65060680067e0dce32966d663f4224ac  # [linux64]
  sha256: 6e86197149b0c0bd131ad925c165251fff1c054ae477c10b5c45e052789e1a2d  # [ppc64le]
  sha256: 62f3a245ade16dfb17c56eaaad4df5f339acaa34d2e05ddc15f49fc30e78663c  # [aarch64]
  sha256: 6ad8df634d60e4bc96cf6914af71a5708f6460a25a39d0183780c6bdebfa60c7  # [win]

build:
  number: 1
  binary_relocation: false
  skip: true  # [osx or (linux and s390x)]

test:
  requires:
    - patchelf  # [linux]
  files:
    - test-rpath.sh
  commands:
    - test -L $PREFIX/lib/libcupti.so.{{ version.split(".")[0] }}                            # [linux]
    - test -L $PREFIX/lib/libcupti.so.{{ lib_version }}                                      # [linux]
    - test -L $PREFIX/targets/{{ target_name }}/lib/libcupti.so.{{ version.split(".")[0] }}  # [linux]
    - test -f $PREFIX/targets/{{ target_name }}/lib/libcupti.so.{{ lib_version }}            # [linux]
    - bash test-rpath.sh                                                                     # [linux]
    - if not exist %LIBRARY_BIN%\checkpoint.dll exit 1                 # [win]
    - if not exist %LIBRARY_BIN%\cupti64_{{ lib_version }}.dll exit 1  # [win]
    - if not exist %LIBRARY_BIN%\nvperf_host.dll exit 1                # [win]
    - if not exist %LIBRARY_BIN%\nvperf_target.dll exit 1              # [win]
    - if not exist %LIBRARY_BIN%\pcsamplingutil.dll exit 1             # [win]

outputs:
  - name: cuda-cupti
    files:
      - lib/libcupti*.so.*                    # [linux]
      - targets/{{ target_name }}/lib/*.so.*  # [linux]
      - Library\bin\checkpoint.dll            # [win]
      - Library\bin\cupti*.dll                # [win]
      - Library\bin\nvperf*.dll               # [win]
      - Library\bin\pcsamplingutil.dll        # [win]
    requirements:
      build:
        - {{ compiler("c") }}
        - {{ compiler("cxx") }}
        #- arm-variant * {{ arm_variant_type }}  # [aarch64]
        - patchelf <0.18.0                      # [linux]
      host:
        - cuda-version {{ cuda_version }}
      run:
        - {{ pin_compatible("cuda-version", max_pin="x.x") }}
      run_constrained:
        - arm-variant * {{ arm_variant_type }}  # [aarch64]
    # Tests are defined at the top level, due to package/output name conflicts.
    about:
      home: https://developer.nvidia.com/cuda-toolkit
      license_file: LICENSE
      license: LicenseRef-NVIDIA-End-User-License-Agreement
      license_url: https://docs.nvidia.com/cuda/eula/index.html
      summary: Provides libraries to enable third party tools using GPU profiling APIs.
      description: |
        Provides libraries to enable third party tools using GPU profiling APIs.
      doc_url: https://docs.nvidia.com/cuda/cupti/index.html

  - name: cuda-cupti-dev
    build:
      run_exports:
        - {{ pin_subpackage("cuda-cupti", max_pin="x") }}
    files:
      - lib/checkpoint.so                         # [linux]
      - lib/libcupti.so                           # [linux]
      - lib/libnv*.so                             # [linux]
      - lib/libpcsamplingutil.so                  # [linux]
      - targets/{{ target_name }}/lib/*.so        # [linux]
      - targets/{{ target_name }}/include         # [linux]
      - Library\include                           # [win]
      - Library\lib\*.lib                         # [win]
    requirements:
      build:
        - {{ compiler("c") }}
        - {{ compiler("cxx") }}
        #- arm-variant * {{ arm_variant_type }}  # [aarch64]
      host:
        - cuda-version {{ cuda_version }}
      run:
        - {{ pin_compatible("cuda-version", max_pin="x.x") }}
        - {{ pin_subpackage("cuda-cupti", exact=True) }}
      run_constrained:
        - arm-variant * {{ arm_variant_type }}  # [aarch64]
        - cuda-cupti-static >={{ version }}
    test:
      commands:
        - test -L $PREFIX/lib/libcupti.so                                    # [linux]
        - test -L $PREFIX/lib/libnvperf_host.so                              # [linux]
        - test -L $PREFIX/lib/libnvperf_target.so                            # [linux]
        - test -f $PREFIX/targets/{{ target_name }}/include/cupti.h          # [linux]
        - test -L $PREFIX/targets/{{ target_name }}/lib/libcupti.so          # [linux]
        - test -f $PREFIX/targets/{{ target_name }}/lib/libnvperf_host.so    # [linux]
        - test -f $PREFIX/targets/{{ target_name }}/lib/libnvperf_target.so  # [linux]
        - if not exist %LIBRARY_LIB%\cupti.lib exit 1                        # [win]
        - if not exist %LIBRARY_INC%\cupti.h exit 1                          # [win]
    about:
      home: https://developer.nvidia.com/cuda-toolkit
      license_file: LICENSE
      license: LicenseRef-NVIDIA-End-User-License-Agreement
      license_url: https://docs.nvidia.com/cuda/eula/index.html
      summary: Provides libraries to enable third party tools using GPU profiling APIs.
      description: |
        Provides libraries to enable third party tools using GPU profiling APIs.
      doc_url: https://docs.nvidia.com/cuda/cupti/index.html

  - name: cuda-cupti-static
    build:
      skip: True  # [not linux64]
    files:
      - targets/{{ target_name }}/lib/*static.a
    requirements:
      build:
        #- arm-variant * {{ arm_variant_type }}  # [aarch64]
      host:
        - cuda-version {{ cuda_version }}
      run:
        - {{ pin_compatible("cuda-version", max_pin="x.x") }}
      run_constrained:
        - arm-variant * {{ arm_variant_type }}  # [aarch64]
    test:
      commands:
        - test -f $PREFIX/targets/{{ target_name }}/lib/libcupti_static.a  # [linux]
    about:
      home: https://developer.nvidia.com/cuda-toolkit
      license_file: LICENSE
      license: LicenseRef-NVIDIA-End-User-License-Agreement
      license_url: https://docs.nvidia.com/cuda/eula/index.html
      summary: Provides libraries to enable third party tools using GPU profiling APIs.
      description: |
        Provides libraries to enable third party tools using GPU profiling APIs.
      doc_url: https://docs.nvidia.com/cuda/cupti/index.html

  - name: cuda-cupti-doc
    files:
      - targets/{{ target_name }}/{{ name }}/samples
      - targets/{{ target_name }}/{{ name }}/doc
    requirements:
      build:
        #- arm-variant * {{ arm_variant_type }}  # [aarch64]
      host:
        - cuda-version {{ cuda_version }}
      run:
        - {{ pin_compatible("cuda-version", max_pin="x.x") }}
      run_constrained:
        - arm-variant * {{ arm_variant_type }}  # [aarch64]
    test:
      commands:
        - test -d $PREFIX/targets/{{ target_name }}/{{ name }}/samples  # [linux]
        - test -d $PREFIX/targets/{{ target_name }}/{{ name }}/doc      # [linux]
    about:
      home: https://developer.nvidia.com/cuda-toolkit
      license_file: LICENSE
      license: LicenseRef-NVIDIA-End-User-License-Agreement
      license_url: https://docs.nvidia.com/cuda/eula/index.html
      summary: Provides libraries to enable third party tools using GPU profiling APIs.
      description: |
        Provides libraries to enable third party tools using GPU profiling APIs.
      doc_url: https://docs.nvidia.com/cuda/cupti/index.html

about:
  home: https://developer.nvidia.com/cuda-toolkit
  license_file: LICENSE
  license: LicenseRef-NVIDIA-End-User-License-Agreement
  license_url: https://docs.nvidia.com/cuda/eula/index.html
  summary: Provides libraries to enable third party tools using GPU profiling APIs.
  description: |
    Provides libraries to enable third party tools using GPU profiling APIs.
  doc_url: https://docs.nvidia.com/cuda/cupti/index.html

extra:
  recipe-maintainers:
    - conda-forge/cuda
