{% set version = "2.11.0" %}
{% set estimator_version = "2.11.0" %}

package:
  name: tensorflow-split
  version: {{ version }}

source:
  - url: https://github.com/tensorflow/tensorflow/archive/refs/tags/v{{ version.replace(".rc", "-rc") }}.tar.gz
    sha256: 99c732b92b1b37fc243a559e02f9aef5671771e272758aa4aec7f34dc92dac48
    patches:
      - patches/0001-loosen-requirements.patch

  - url: https://github.com/tensorflow/estimator/archive/refs/tags/v{{ estimator_version.replace(".rc", "-rc") }}.tar.gz
    sha256: 922f9187de79e8e7f7d7a5b2d6d3aabc81bbbd6ba5f12a4f52967dd302214a43
    folder: tensorflow-estimator

build:
  number: 0
  skip: true  # [win]
  skip: true  # [python_impl == 'pypy']
  skip: true  # [libabseil != '20220623.0']
  skip: true  # [cuda_compiler_version in ("10.2", "11.0", "11.1")]

requirements:
  build:
    - python                                 # [build_platform != target_platform]
    - cython                                 # [build_platform != target_platform]
    - cross-python_{{ target_platform }}     # [build_platform != target_platform]
    - nsync                                  # [build_platform != target_platform]
    - snappy                                 # [build_platform != target_platform]
    - giflib                                 # [build_platform != target_platform]
    - jpeg                                   # [build_platform != target_platform]
    - icu                                    # [build_platform != target_platform]
    - libpng                                 # [build_platform != target_platform]
    - flatbuffers >=2                        # [build_platform != target_platform]
    - onednn                                 # [build_platform != target_platform]
    - onednn-cpu-threadpool                  # [build_platform != target_platform]
    - pybind11                               # [build_platform != target_platform]
    - numpy                                  # [build_platform != target_platform]
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - {{ compiler('cuda') }}                 # [cuda_compiler_version != "None"]
    - bazel >=5.2.0
    - libgrpc
    - libprotobuf
    - nasm
    - sed
    - rsync
    # realpath is not available from the docker image for cuda <= 10.2
    # so we install coreutils here
    - coreutils  # [cuda_compiler_version != "None"]
  host:
    # GPU requirements for CUDA
    - cudnn      # [cuda_compiler_version != "None"]
    - nccl       # [cuda_compiler_version != "None"]
    # conda build requirements
    - python
    - pip
    - packaging
    - zlib
    - libpng
    - libcurl
    - curl         # [win]
    - unzip        # [not win]
    - zip          # [not win]
    - m2-unzip     # [win]
    - m2-zip       # [win]
    - openjdk >=8
    - nsync
    # TF_SYSTEM_LIBS, see usage in
    # https://github.com/tensorflow/tensorflow/blob/v{{ version }}/third_party/systemlibs/syslibs_configure.bzl
    # their versions are specified in
    # https://github.com/tensorflow/tensorflow/blob/v{{ version }}/tensorflow/workspace2.bzl
    # but so far there have been no problems with leaving these
    # unpinned; though some restrictions come in for packages
    # that are also listed as a requirement for the pip_package.
    - libabseil
    - astor
    - cython
    - dill
    - giflib
    - libgrpc
    # 2022/04/25 hmaarrfk
    # the latest flatbuffers 2.0.6 seems to have removed a sybmol in a patch release...
    # https://github.com/Qengineering/TensorFlow_Lite_Pose_RPi_64-bits/issues/3#issuecomment-1034799822
    - flatbuffers >=2
    - icu
    - jpeg
    - libpng
    - libprotobuf
    - openssl
    - pybind11
    - sqlite
    - snappy
    - zlib
    # requirements specified by the package itself, see
    # github.com/tensorflow/tensorflow/blob/v{{ version }}/tensorflow/tools/pip_package/setup.py
    - absl-py >=1.0.0
    - astunparse >=1.6.0
    - gast >=0.2.1,<=0.4.0
    - google-pasta >=0.1.1
    - h5py >=2.9.0
    - keras-preprocessing >=1.1.1
    - numpy
    - opt_einsum >=2.3.2
    - protobuf >=3.9.2
    - python-flatbuffers >=2
    - six >=1.12
    - termcolor >=1.1.0
    - typing_extensions >=3.6.6
    - wrapt >=1.11.0
    # TF-API needs to move in sync
    - tensorboard >=2.11,<2.12
    - keras >=2.11,<2.12

outputs:
  # 2021/12/29: hmaarrfk
  # as of tensorflow 2.7.0 we need the tensorflow-base package to break
  # circular dependency when buliding tensorflow extra packages This annoying
  # circularity is broken upstream by the fact that they have to bootstrap
  # their builds
  - name: tensorflow-base
    script: build_pkg.sh  # [not win]
    script: build_pkg.bat  # [win]
    build:
      string: cuda{{ cuda_compiler_version | replace('.', '') }}py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None"]
      # weigh down cpu implementation and give cuda preference
      track_features:
        - tensorflow-cpu          # [cuda_compiler_version == "None"]
      entry_points:
        - toco_from_protos = tensorflow.lite.toco.python.toco_from_protos:main
        - tflite_convert = tensorflow.lite.python.tflite_convert:main
        - toco = tensorflow.lite.python.tflite_convert:main
        - saved_model_cli = tensorflow.python.tools.saved_model_cli:main
        # The tensorboard package adds this entry point.
        # - tensorboard = tensorboard.main:run_main
        - tf_upgrade_v2 = tensorflow.tools.compatibility.tf_upgrade_v2_main:main
        - estimator_ckpt_converter = tensorflow_estimator.python.estimator.tools.checkpoint_converter:main
    requirements:
      # build requirements needs to pick up the compiler run_exports
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - {{ compiler('cuda') }}  # [cuda_compiler_version != "None"]
      host:
        # GPU reuqirements
        - cudnn                   # [cuda_compiler_version != "None"]
        - nccl                    # [cuda_compiler_version != "None"]
        # conda build requirements
        - python
        - pip
        - packaging
        - wheel
        # TF_SYSTEM_LIBS
        - libabseil
        - astor
        - cython
        - dill
        - giflib
        - libgrpc
        - flatbuffers >=2
        - icu
        - jpeg
        - libcurl
        - libpng
        - libprotobuf
        - openssl
        - pybind11
        - snappy
        - sqlite
        - zlib
        # requirements specified by the package itself
        - absl-py >=1.0.0
        - astunparse >=1.6.0
        - gast >=0.2.1,<=0.4.0
        - google-pasta >=0.1.1
        - h5py >=2.9.0
        - keras-preprocessing >=1.1.1
        - numpy
        - opt_einsum >=2.3.2
        - protobuf >=3.9.2
        - python-flatbuffers >=2
        - six >=1.12
        - termcolor >=1.1.0
        - typing_extensions >=3.6.6
        - wrapt >=1.11.0
        # TF-API needs to move in sync
        - tensorboard >=2.11,<2.12
        - keras >=2.11,<2.12
      run:
        - python
        - packaging
        - absl-py >=1.0.0
        - astunparse >=1.6.0
        - gast >=0.2.1,<=0.4.0
        - google-pasta >=0.1.1
        - grpcio {{ grpc_cpp }}.*
        - h5py >=2.9.0
        - keras-preprocessing >=1.1.1
        - {{ pin_compatible('numpy') }}
        - opt_einsum >=2.3.2
        - protobuf >=3.9.2
        - python-flatbuffers >=2
        # This can be removed once the dust settles after
        # the run_export is added to the main and 2.x.x branch
        # https://github.com/conda-forge/flatbuffers-feedstock/pull/35
        # https://github.com/conda-forge/flatbuffers-feedstock/pull/36
        # https://github.com/conda-forge/flatbuffers-feedstock/pull/37
        - {{ pin_compatible('flatbuffers', max_pin='x') }}
        - six >=1.12
        - termcolor >=1.1.0
        - typing_extensions >=3.6.6
        - wrapt >=1.11.0
        # TF-API needs to move in sync
        - tensorboard >=2.11,<2.12
        - keras >=2.11,<2.12
        # avoid that people without GPUs needlessly download ~0.5-1GB
        - __cuda  # [cuda_compiler_version != "None"]
        - __osx >={{ MACOSX_DEPLOYMENT_TARGET|default("10.9") }}  # [osx and x86_64]
    # TODO: decide on the name of the package
    # run_constrained:
    #   What is the difference between these two packages?
    #   - tensorflow-io-gcs-filesystem >=0.21.0
    #   - tensorflow-io >=0.21.0

  - name: tensorflow
    build:
      string: cuda{{ cuda_compiler_version | replace('.', '') }}py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None"]
      # weigh down cpu implementation and give cuda preference
      track_features:
        - tensorflow-cpu          # [cuda_compiler_version == "None"]
    requirements:
      host:
        # Require python so that the CONDA_PY gets populated
        - python
      run:
        - python
        - {{ pin_subpackage('tensorflow-base', exact=True) }}
        - {{ pin_subpackage('tensorflow-estimator', exact=True) }}
        # avoid that people without GPUs needlessly download ~0.5-1GB
        # This also helps mamba give preference to the CPU build
        - __cuda  # [cuda_compiler_version != "None"]
    test:
      files:
        - test_tensorflow.py
      requires:
        - pip
      imports:
        - tensorflow
      commands:
        - pip check
        - cat test_tensorflow.py    # [unix]
        - python test_tensorflow.py
        - tf_upgrade_v2 --help
        - saved_model_cli --help
        - tflite_convert --help     # [not win]
        - toco_from_protos --help   # [not win]
        - toco --help               # [not win]

  - name: tensorflow-estimator
    script: build_estimator.sh   # [not win]
    script: build_estimator.bat  # [win]
    build:
      string: cuda{{ cuda_compiler_version | replace('.', '') }}py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None"]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        # Keep the cuda compiler here since it helps package solvers
        # decide on the cuda variant
        # https://github.com/conda-forge/tensorflow-feedstock/issues/162
        - {{ compiler('cuda') }}                 # [cuda_compiler_version != "None"]
        - bazel >=5.2.0
      host:
        - python
        - pip
        - packaging
        - setuptools
        - wheel
        # This ensures that a consistent version of openssl is chosen between
        # all packages.
        # https://github.com/conda-forge/conda-forge.github.io/issues/1528
        - openssl
        - {{ pin_subpackage('tensorflow-base', exact=True) }}
      run:
        - python
        - {{ pin_subpackage('tensorflow-base', exact=True) }}
    test:
      requires:
        - pip
      commands:
        - pip check

  - name: libtensorflow
    script: cp_libtensorflow.sh
    build:
      skip: true  # [win]
      string: cuda{{ cuda_compiler_version | replace('.', '') }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None"]
      run_exports:
        # tensorflow makes no ABI guarantees, need to pin to what we built with
        - libtensorflow {{ version }}
    requirements:
      # build requirements needs to pick up the compiler run_exports
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        # Keep the cuda compiler here since it helps package solvers
        # decide on the cuda variant
        # https://github.com/conda-forge/tensorflow-feedstock/issues/162
        - {{ compiler('cuda') }}  # [cuda_compiler_version != "None"]
      # host requirements to pick up run_exports
      host:
        - libabseil
        - giflib
        - libgrpc
        - icu
        - jpeg
        - libcurl
        - libpng
        - libprotobuf
        - openssl
        - snappy
        - sqlite
        - zlib
      run:
        # avoid that people without GPUs needlessly download ~200-300MB
        - __cuda  # [cuda_compiler_version != "None"]
    test:
      files:
        - test_libtensorflow.sh
        - test_c.c
      requires:
        - {{ compiler('c') }}
      commands:
        - test -f $PREFIX/lib/libtensorflow${SHLIB_EXT}  # [not win and cuda_compiler_version == "None"]
        - ./test_libtensorflow.sh                        # [not win and cuda_compiler_version == "None"]

  - name: libtensorflow_cc
    script: cp_libtensorflow_cc.sh
    build:
      skip: true  # [win]
      string: cuda{{ cuda_compiler_version | replace('.', '') }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version == "None"]
      run_exports:
        # tensorflow makes no ABI guarantees, need to pin to what we built with
        - libtensorflow_cc {{ version }}
    requirements:
      # build requirements needs to pick up the compiler run_exports
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        # Keep the cuda compiler here since it helps package solvers
        # decide on the cuda variant
        # https://github.com/conda-forge/tensorflow-feedstock/issues/162
        - {{ compiler('cuda') }}  # [cuda_compiler_version != "None"]
      # host requirements to pick up run_exports
      host:
        - libabseil
        - giflib
        - libgrpc
        - icu
        - jpeg
        - libcurl
        - libpng
        - libprotobuf
        - openssl
        - snappy
        - sqlite
        - zlib
      run:
        # avoid that people without GPUs needlessly download ~200-300MB
        - __cuda  # [cuda_compiler_version != "None"]
    test:
      files:
        - test_libtensorflow_cc.sh
        - test_cc.cc
      requires:
        - {{ compiler('cxx') }}
      commands:
        - test -f $PREFIX/lib/libtensorflow_cc${SHLIB_EXT}  # [not win and cuda_compiler_version == "None"]
        - ./test_libtensorflow_cc.sh                        # [not win and cuda_compiler_version == "None"]

  # 2021/08/01, hmaarrfk
  # While this seems like a roundabout way of defining the package name
  # It helps the linter avoid errors on a package not having tests.
  {% set tensorflow_cpu_gpu = "tensorflow-cpu" %}   # [cuda_compiler_version == "None" or cuda_compiler_version is undefined]
  {% set tensorflow_cpu_gpu = "tensorflow-gpu" %}   # [cuda_compiler_version != "None"]
  - name: {{ tensorflow_cpu_gpu }}
    build:
      string: cuda{{ cuda_compiler_version | replace('.', '') }}py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}  # [cuda_compiler_version != "None"]
      string: cpu_py{{ CONDA_PY }}h{{ PKG_HASH }}_{{ PKG_BUILDNUM }}                                      # [cuda_compiler_version == "None"]
      detect_binary_files_with_prefix: False
    requirements:
      run:
        - {{ pin_subpackage("tensorflow", exact=True) }}
    test:
      imports:
        - tensorflow

about:
  home: http://tensorflow.org/
  license: Apache-2.0
  license_file: LICENSE
  license_family: Apache
  summary: TensorFlow is an end-to-end open source platform for machine learning.
  description: |
    TensorFlow offers multiple levels of abstraction so you can choose the
    right one for your needs. Build and train models by using the high-level
    Keras API, which makes getting started with TensorFlow and machine learning
    easy.
  dev_url: https://github.com/tensorflow/tensorflow
  doc_url: https://www.tensorflow.org/get_started/get_started
  doc_source_url: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/docs_src

extra:
  feedstock-name: tensorflow
  recipe-maintainers:
    - ngam
    - farhantejani
    - ghego
    - h-vetinari
    - hajapy
    - jschueller
    - njzjz
    - waitingkuo
    - xhochy
    - hmaarrfk
    - wolfv
