{% set name = "cuda-sanitizer-api" %}
{% set version = "12.4.127" %}
{% 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 extension = "tar.xz" %}  # [not win]
{% set extension = "zip" %}  # [win]
{% set exists = "which" %}  # [not win]
{% set exists = "where" %}  # [win]

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

source:
  url: https://developer.download.nvidia.com/compute/cuda/redist/cuda_sanitizer_api/{{ platform }}/cuda_sanitizer_api-{{ platform }}-{{ version }}-archive.{{ extension }}
  sha256: b719c6b2a8cd330ab0e4361e41dda5493946fb7fa0c4b04c8dbd776fadc3b11b  # [linux64]
  sha256: 5ceae6170471d7a9e4540796760642747d10d7d4f609dacede90f84927e59618  # [ppc64le]
  sha256: 0e5ff35535ecb1ed0b482a2ac5e3a20e94722736f023fc802cbfd4900e590746  # [aarch64]
  sha256: f15613b7c3088299659356456abfe2c3a98eed7eea9d8292fe0ec46726f5ec73  # [win]

build:
  number: 1
  binary_relocation: false
  skip: true  # [osx or (linux and s390x)]
  missing_dso_whitelist:
    - '$RPATH/libInterceptorInjectionTarget.so'  # [linux]
    - '$RPATH/InterceptorInjectionTarget.dll'    # [win]

requirements:
  build:
    - {{ compiler("c") }}
    - {{ compiler("cxx") }}
    - sysroot_{{ target_platform }} {{ conda_glibc_ver }}.*    # [linux]
    #- 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]

test:
  commands:
    - test -f $PREFIX/bin/compute-sanitizer                                         # [linux]
    - test -f $PREFIX/compute-sanitizer/compute-sanitizer                           # [linux]
    - if not exist %LIBRARY_PREFIX%\compute-sanitizer\compute-sanitizer.exe exit 1  # [win]
    - if not exist %PREFIX%\Scripts\compute-sanitizer.bat exit 1                    # [win]
    # This test fails on aarch64. Using `strace which compute-sanitizer` confirms the file is found, but
    # which still writes "no compute-sanitizer" to stderr. Maybe the `which` in our docker container isn't working correctly, because
    # `compute-sanitizer --version` executes correctly, and there's no system CUDA installation in the container.
    # renaming compute-sanitizer to 14 characters or less also seems to fix it.
    - {{ exists }} compute-sanitizer                                                # [not (linux and aarch64)]
    - compute-sanitizer --version                                                   # [build_platform == target_platform]

about:
  home: https://docs.nvidia.com/compute-sanitizer/SanitizerApiGuide/index.html
  license_file: LICENSE
  license: LicenseRef-NVIDIA-End-User-License-Agreement
  license_url: https://docs.nvidia.com/cuda/eula/index.html
  summary: Provides a set of APIs to enable third party tools to write GPU sanitizing tools
  description: |
    Provides a set of APIs to enable third-party tools to write GPU sanitizing
    tools, such as memory and race checkers.
  doc_url: https://docs.nvidia.com/compute-sanitizer/SanitizerApiGuide/index.html

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