# keep this without major version to let the bot pick it up
{% set version = "25.3" %}
# protobuf doesn't add the major version in the tag, it's defined per language in
# https://github.com/protocolbuffers/protobuf/blob/main/version.json
{% set major = "4" %}
# libprotobuf can have a different major version than protobuf
{% set lib_major = "4" %}

package:
  name: protobuf
  version: {{ major ~ "." ~ version }}

source:
  url: https://github.com/protocolbuffers/protobuf/archive/refs/tags/v{{ version }}.tar.gz
  sha256: d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e
  patches:
    - patches/0001-do-not-link-msvc-runtime-statically.patch
    - patches/0002-fix-paths-for-include-lib-directories.patch
    - patches/0003-correctly-link-to-protobuf-abseil.patch
    - patches/0004-use-C-17-everywhere.patch
    - patches/0005-set-PROTOBUF_USE_DLLS-on-windows.patch

build:
  number: 1
  script:
    - cd python
    - export PROTOC=$PREFIX/bin/protoc        # [unix and (build_platform == target_platform)]
    - export PROTOC=$BUILD_PREFIX/bin/protoc  # [unix and (build_platform != target_platform)]
    - set PROTOC=%LIBRARY_BIN%\protoc         # [win]
    - python setup.py bdist_wheel --cpp_implementation
    - {{ PYTHON }} -m pip install --no-deps --no-build-isolation -f dist protobuf=={{ major ~ "." ~ version }}

requirements:
  build:
    - python                                 # [build_platform != target_platform]
    - cross-python_{{ target_platform }}     # [build_platform != target_platform]
    - libprotobuf {{ lib_major ~ "." ~ version }}  # [build_platform != target_platform]
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - patch # [unix]
    - m2-patch # [win]
  host:
    - python
    - pip
    - setuptools
    - wheel
    - libabseil 20240116.2
    - libprotobuf {{ lib_major ~ "." ~ version }}
  run:
    - python
    # bounds through run_exports
    - libabseil
    - libprotobuf
    - __osx >={{ MACOSX_DEPLOYMENT_TARGET }}  # [osx and x86_64]

test:
  imports:
    - google
    - google.protobuf
    - google.protobuf.descriptor
    - google.protobuf.internal
    - google.protobuf.pyext
    - google.protobuf.pyext._message
    - google.protobuf.util
    - google.protobuf.compiler
  requires:
    - pip
  commands:
    - pip check
    - python -c "from google.protobuf.internal import api_implementation; assert api_implementation.Type() == 'cpp'"     # [python_impl != "pypy"]
    - python -c "from google.protobuf.internal import api_implementation; assert api_implementation.Type() == 'python'"  # [python_impl == "pypy"]

about:
  home: https://developers.google.com/protocol-buffers/
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE
  summary: Protocol Buffers - Google's data interchange format.
  description: |
    Protocol buffers are Google's language-neutral, platform-neutral, extensible
    mechanism for serializing structured data,think XML, but smaller, faster, and simpler.
  dev_url: https://github.com/protocolbuffers/protobuf
  doc_url: https://developers.google.com/protocol-buffers/docs/tutorials

extra:
  recipe-maintainers:
    - jjerphan
    - JohanMabille
    - xylar
    - dopplershift
    - jakirkham
    - ocefpaf
    - hajapy
    - xhochy
    - conda-forge/libprotobuf
