{% set name = "grpc" %}
{% set version = "1.48.2" %}

# It is not currently possible to compile grpc-cpp on Windows in shared mode:
# _h_env\Library\include\google/protobuf/io/coded_stream.h(1250):
#   warning C4251: 'google::protobuf::io::CodedOutputStream::default_serialization_deterministic_': struct 'std::atomic<bool>'
#   needs to have dll-interface to be used by clients of class 'google::protobuf::io::CodedOutputStream'
# LINK : fatal error LNK1181: cannot open input file 'gpr.lib'
{% set static_build = 'yes' %}  # [win]
{% set static_build = 'no' %}  # [not win]

{% if static_build == 'yes' %}
{% set libext = '.lib' %}  # [win]
{% set libext = '.a' %}  # [not win]
{% else %}
{% set libext = '.dll' %}  # [win]
{% set libext = '.so' %}  # [linux]
{% set libext = '.dylib' %}  # [osx]
{% endif %}

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

source:
  url: https://github.com/{{ name }}/{{ name }}/archive/v{{ version }}.tar.gz
  sha256: bdb8e98145469d58c69ab9f2c9e0bd838c2836a99b5760bc0ebf658623768f52
  patches:
    - patches/force-protoc-executable.patch
    - patches/0001-Monkey-patch-distutils.ccompiler.spawn-to-elide-std-.patch
    - patches/0002-windows-ssl-lib-names.patch
    - patches/0001-fix-win-commands.patch
    - patches/0003-Link-against-grpc.patch

build:
  number: 1

outputs:
  - name: {{ name }}-cpp
    script: build-cpp.sh   # [not win]
    script: build-cpp.bat  # [win]
    build:
      missing_dso_whitelist:
        - '$RPATH/ld64.so.1'  # [s390x]
      script_env:
        - STATIC_BUILD={{ static_build }}
        - LIB_EXT={{libext}}
{% if static_build == 'yes' %}
      ignore_run_exports:
        - abseil-cpp
        - c-ares
        - libprotobuf  # libprotobuf pins itself to x.x via run_exports
        - re2
        - openssl
        - zlib
{% endif %}
      run_exports:
        - {{ pin_subpackage('grpc-cpp', max_pin='x.x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - m2-patch  # [win]
        - patch  # [not win]
        - cmake >=3.5.1
        - pkg-config  # [unix]
        # `protoc` is also used for building
        - libprotobuf {{ libprotobuf }}
        - ninja
      host:
        - abseil-cpp 20211102.0
        - c-ares 1.19.0
        - libprotobuf {{ libprotobuf }}
        - re2 2022.04.01
        - openssl {{ openssl }}
        - zlib {{ zlib }}
      run:
        # Need to pin libprotobuf to the same version used when building,
        # otherwise we may get a different SO ABI version.
        # For example 3.6.1 is ABI-incompatible with 3.6.0...
        - {{ pin_compatible("libprotobuf", min_pin="x.x.x", max_pin="x.x.x") }}
        - zlib >=1.2.13,<1.3.0a0
        - re2
        - openssl 3.*
    test:
      script: run_test_cpp.sh   # [not win]
      script: run_test_cpp.bat  # [win]
      requires:
        # protoc needs compiler; cmake also needs one to run package detection, see
        # https://discourse.cmake.org/t/questions-about-find-package-cli-msvc/6194
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - cmake
        - ninja
        - pkg-config
      files:
        - tests/include/*
  - name: {{ name }}io
    script: build-grpcio.sh   # [not win]
    script: build-grpcio.bat  # [win]
    build:
      missing_dso_whitelist:
        - '$RPATH/ld64.so.1'  # [s390x]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - m2-patch  # [win]
        - patch  # [not win]
      host:
        - {{ pin_subpackage('grpc-cpp', exact=True) }}
        - python
        - cython 0.29.33
        - pip
        - pthread-stubs 0.3  # [linux]
        - setuptools
        - wheel >=0.29
{% if static_build == 'yes' %}
        - abseil-cpp 20211102.0
        - c-ares 1.19.0
        - libprotobuf {{ libprotobuf }}
        - re2 2022.04.01
        - openssl {{ openssl }}
        - zlib {{ zlib }}
{% endif %}
      run:
        - python
        - {{ pin_subpackage('grpc-cpp', exact=True) }}
        - six >=1.6.0
        - __osx >={{ MACOSX_DEPLOYMENT_TARGET|default("10.9") }}  # [osx and x86_64]
    test:
      requires:
        - pip
      imports:
        - grpc
        - grpc._cython
        - grpc._cython._cygrpc
        - grpc.beta
        - grpc.framework
        - grpc.framework.common
        - grpc.framework.foundation
        - grpc.framework.interfaces
        - grpc.framework.interfaces.base
        - grpc.framework.interfaces.face
      commands:
        - pip check

about:
  home: https://grpc.io/
  license: Apache-2.0
  license_family: APACHE
  license_file: LICENSE
  summary: gRPC - A high-performance, open-source universal RPC framework
  description: |
    gRPC is a modern, open source, high-performance remote procedure call
    (RPC) framework that can run anywhere. gRPC enables client and server
    applications to communicate transparently, and simplifies the building
    of connected systems.

    This package contains the gRPC C++ libraries and header files, as well
    as the code generation plugins.
  doc_url: https://grpc.io/docs/
  dev_url: https://github.com/grpc/grpc

extra:
  recipe-maintainers:
    - pitrou
    - xhochy
    - wesm
    - mingwandroid
