{% set version = "6.0.1" %}
{% set build = 0 %}
{% set posix = 'm2-' if win else '' %}

package:
  name: r-curl
  version: {{ version|replace("-", "_") }}

source:
  url:
    - {{ cran_mirror }}/src/contrib/curl_{{ version }}.tar.gz
    - {{ cran_mirror }}/src/contrib/Archive/curl/curl_{{ version }}.tar.gz
  sha256: 841c90bed7745f972ab524e542b1f5c3632767e3d521c163d483e436f3d42362

build:
  number: {{ build }}
  rpaths:
    - lib/R/lib/
    - lib/
  ignore_run_exports_from:
    # TODO: See below. Remove explicit dependency when workaround is not needed anymore.
    - openssl <3.2.0a0  # [unix and r_base != "4.4"]

requirements:
  build:
    - cross-r-base {{ r_base }}      # [build_platform != target_platform]
    - {{ compiler('c') }}            # [not win]
    - {{ stdlib("c") }}              # [not win]
    - {{ compiler('m2w64_c') }}      # [win]
    - {{ stdlib("m2w64_c") }}        # [win]
    - {{ posix }}filesystem          # [win]
    - {{ posix }}sed                 # [win]
    - {{ posix }}grep                # [win]
    - {{ posix }}autoconf
    - {{ posix }}automake            # [not win]
    - {{ posix }}automake-wrapper    # [win]
    - {{ posix }}pkg-config
    - {{ posix }}make
    - {{ posix }}coreutils           # [win]
    - {{ posix }}zip                 # [win]
  host:
    - r-base
    - libcurl
    - libnghttp2                     # [win]
    # Test below (connecting to rest.kegg.jp) triggers upstream issue described in
    # https://github.com/curl/curl/issues/13389 and https://github.com/openssl/openssl/issues/11378
    # Building against libcurl built against openssl<3.2 allows to circumvent that issue if needed.
    # TODO: Remove explicit dependency when workaround is not needed anymore.
    - openssl <3.2.0a0  # [unix and r_base != "4.4"]
  run:
    - r-base

test:
  requires:
    - r-httpuv
    - r-testthat
    - r-webutils
    # TODO: See above. Remove explicit dependency when is workaround not needed anymore.
    - openssl <3.2.0a0  # [unix and r_base != "4.4"]
  source_files:
    - tests/
    - tests/testthat
  commands:
    - R -e "library('curl');data.frame(curl_options())"
    - R -e "testthat::test_file('tests/testthat.R', stop_on_failure=TRUE)"   # [not win]
    # NB: A couple inconsequential tests failed in the past. Please diligently review logs.
    - R -e "testthat::test_file('tests/testthat.R', stop_on_failure=FALSE)"  # [win]
    # skip for win or r_base == "4.4" because all win and r-base=4.4 build against newer libcurl with openssl>=3.3 dep.
    - R -e "invisible(curl::curl_fetch_memory('http://rest.kegg.jp/conv/ncbi-geneid/dme'))"  # [unix and r_base != "4.4"]
about:
  home: https://github.com/jeroen/curl#readme
  license: MIT
  summary: The curl() and curl_download() functions provide highly configurable drop-in replacements for base url() and download.file() with better performance, support for encryption (https, ftps), gzip compression, authentication, and other 'libcurl' goodies. The core of the package implements a framework for performing
    fully customized requests where data can be processed either in memory, on disk, or streaming via the callback or connection interfaces. Some knowledge of 'libcurl' is recommended; for a more-user-friendly web client see the 'httr' package which builds on this package with http specific tools and logic.
  license_family: MIT
  license_file:
    - {{ environ["PREFIX"] }}/lib/R/share/licenses/MIT
    - LICENSE

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