git: 56dc0e449f2a - main - science/py-tensorflow: Update 1.15.5 -> 2.9.1

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Tue, 13 Sep 2022 20:32:38 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=56dc0e449f2a0fdf190cfc1de367b148cbb5e467

commit 56dc0e449f2a0fdf190cfc1de367b148cbb5e467
Author:     Anthony Donnelly <amzo1337@gmail.com>
AuthorDate: 2022-09-13 20:21:29 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2022-09-13 20:32:36 +0000

    science/py-tensorflow: Update 1.15.5 -> 2.9.1
    
    Big thank you to Anthony Donnelly for updating this difficult port.
    
    PR:             266303
---
 science/py-tensorflow/Makefile                     | 182 +++--
 science/py-tensorflow/Makefile.MASTER_SITES        |  94 ++-
 science/py-tensorflow/distinfo                     |  98 ++-
 .../files/bazel/add-default-option.patch           |  37 +
 .../py-tensorflow/files/bazel/fix-environ.patch    |  42 +
 .../py-tensorflow/files/bazel/fix_cpuinfo.patch    |  80 ++
 .../files/bazel/freebsd_python_fix.patch           |  11 +
 science/py-tensorflow/files/bazel/set-c++17.patch  |  11 +
 science/py-tensorflow/files/bazelrc                |  24 +-
 ...-patch-absl_base_internal_unscaledcycleclock.cc |  47 --
 science/py-tensorflow/files/freebsd/BUILD          |  88 ++
 .../files/freebsd/cc_toolchain_config.bzl          | 287 +++++++
 science/py-tensorflow/files/patch-.bazelrc         |  22 +
 science/py-tensorflow/files/patch-WORKSPACE        |  61 +-
 science/py-tensorflow/files/patch-bazelrc          |  11 -
 science/py-tensorflow/files/patch-configure        |  11 +
 science/py-tensorflow/files/patch-protobuf         |  22 -
 science/py-tensorflow/files/patch-tensorflow_BUILD |  22 +
 .../patch-tensorflow_compiler_mlir_hlo_WORKSPACE   |  11 +
 .../patch-tensorflow_compiler_mlir_lite_BUILD      |  10 -
 ...ensorflow_compiler_mlir_lite_quantization_BUILD |   8 -
 ...low_compiler_mlir_quantization_tensorflow_BUILD |  11 +
 ...patch-tensorflow_compiler_mlir_tensorflow_BUILD |  10 -
 .../files/patch-tensorflow_contrib_bigtable_BUILD  |  20 -
 .../patch-tensorflow_contrib_boosted__trees_BUILD  |  24 -
 .../patch-tensorflow_contrib_ffmpeg_default_BUILD  |  10 -
 ...e_kernels_client_ignite__plain__client__unix.cc |  13 -
 .../patch-tensorflow_contrib_makefile_Makefile     |  49 --
 .../files/patch-tensorflow_core_BUILD              |  44 +-
 ...-tensorflow_core_distributed__runtime_rpc_BUILD |  10 -
 ...e_distributed__runtime_rpc_grpc__server__lib.cc |  15 -
 .../files/patch-tensorflow_core_lib_png_BUILD      |  10 +
 .../files/patch-tensorflow_core_platform_BUILD     |  10 +
 .../patch-tensorflow_core_platform_cloud_BUILD     |  10 -
 ...nsorflow_core_platform_cloud_gcs__dns__cache.cc |  14 -
 .../patch-tensorflow_core_profiler_internal_BUILD  |  10 -
 ...patch-tensorflow_core_profiler_rpc_client_BUILD |  19 -
 ...patch-tensorflow_core_protobuf_autotuning.proto |  21 -
 ..._micro_tools_make_targets_freebsd__makefile.inc |  13 -
 .../patch-tensorflow_lite_kernels_internal_BUILD   |  11 -
 ...nsorflow_lite_python_interpreter__wrapper_BUILD |  10 -
 .../files/patch-tensorflow_lite_tools_BUILD        |  10 -
 .../patch-tensorflow_lite_tools_make_Makefile      |  19 -
 ...w_lite_tools_make_targets_freebsd__makefile.inc |  19 -
 .../patch-tensorflow_lite_tools_optimize_BUILD     |  20 -
 ...ensorflow_lite_tools_optimize_calibration_BUILD |  34 -
 ...tch-tensorflow_python_eager_pywrap__tfe__src.cc |  20 -
 .../patch-tensorflow_python_lib_core_bfloat16.cc   |  11 -
 ...flow_python_lib_core_ndarray__tensor__bridge.cc |  11 -
 ...flow_stream__executor_stream__executor__pimpl.h |  10 -
 .../files/patch-tensorflow_tensorflow.bzl          |  65 --
 .../patch-tensorflow_tools_lib__package_BUILD      |  18 -
 .../patch-tensorflow_tools_pip__package_setup.py   |  34 +
 .../files/patch-tensorflow_tools_proto__text_BUILD |  10 +
 .../files/patch-tensorflow_workspace.bzl           |  18 -
 .../files/patch-tensorflow_workspace2.bzl          |  10 +
 ...tch-third__party_absl_system.absl.strings.BUILD |  26 +
 .../files/patch-third__party_aws_BUILD.bazel       |  13 -
 .../patch-third__party_com__google__absl.BUILD     |  13 -
 .../files/patch-third__party_cpuinfo_cpuinfo.BUILD |  51 ++
 .../files/patch-third__party_cpuinfo_workspace.bzl |   9 +
 .../patch-third__party_flatbuffers_BUILD.system    |  18 -
 ...patch-third__party_llvm_macos__build__fix.patch |  11 +
 .../files/patch-third__party_llvm_workspace.bzl    |  10 +
 .../files/patch-third__party_mlir_BUILD            |  10 -
 .../files/patch-third__party_py_BUILD.tpl          |  17 +
 ..._remote__config_remote__platform__configure.bzl |  19 +
 ...patch-third__party_systemlibs_functools32.BUILD |  18 -
 .../files/patch-third__party_systemlibs_grpc.BUILD |  11 -
 .../patch-third__party_systemlibs_jsoncpp.BUILD    |  21 -
 .../patch-third__party_systemlibs_protobuf.BUILD   |  25 +
 .../patch-third__party_systemlibs_protobuf.bzl     |  11 -
 ...-third__party_systemlibs_syslibs__configure.bzl |  10 -
 science/py-tensorflow/files/tensorflow.pc          |  11 +
 science/py-tensorflow/files/tensorflow_cc.pc       |  11 +
 science/py-tensorflow/pkg-plist                    | 908 +++++++++++++++++++++
 76 files changed, 2090 insertions(+), 955 deletions(-)

diff --git a/science/py-tensorflow/Makefile b/science/py-tensorflow/Makefile
index 8ebaa584bb03..b7f89a66198d 100644
--- a/science/py-tensorflow/Makefile
+++ b/science/py-tensorflow/Makefile
@@ -1,7 +1,6 @@
 PORTNAME=	tensorflow
 DISTVERSIONPREFIX=	v
-DISTVERSION=	1.15.5
-PORTREVISION=	7
+DISTVERSION=	2.9.1
 CATEGORIES=	science python
 PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
 DIST_SUBDIR=	${PORTNAME}
@@ -14,18 +13,20 @@ WWW=		https://www.tensorflow.org
 LICENSE=	APACHE20
 LICENSE_FILE=	${WRKSRC}/LICENSE
 
-BROKEN=		does not build: candidate function template not viable: requires 3 arguments, but 2 were provided
-
-ONLY_FOR_ARCHS=	amd64 powerpc64 powerpc64le
+ONLY_FOR_ARCHS=	amd64
 
 BUILD_DEPENDS=	${RUN_DEPENDS} \
 		${PYTHON_PKGNAMEPREFIX}grpcio-tools>=1.22.0:devel/py-grpcio-tools@${PY_FLAVOR} \
 		bash:shells/bash \
 		cython:lang/cython \
 		swig:devel/swig \
-		bazel:devel/bazel029 \
-		git:devel/git
-LIB_DEPENDS=	libsnappy.so:archivers/snappy \
+		bazel:devel/bazel \
+		git:devel/git \
+		clang-devel:devel/llvm-devel
+LIB_DEPENDS=	libnsync.so:devel/nsync \
+		libgpr.so:devel/grpc \
+		libpng.so:graphics/png \
+		libsnappy.so:archivers/snappy \
 		liblmdb.so:databases/lmdb \
 		libsqlite3.so:databases/sqlite3 \
 		libicuio.so:devel/icu \
@@ -36,27 +37,31 @@ LIB_DEPENDS=	libsnappy.so:archivers/snappy \
 		libprotobuf-c.so:devel/protobuf-c \
 		libre2.so:devel/re2 \
 		libgif.so:graphics/giflib \
-		libpng.so:graphics/png \
-		libgpr.so:devel/grpc \
 		libcurl.so:ftp/curl \
-		libgoogle_cloud_cpp_common.so:devel/google-cloud-cpp117 \
 		libflatbuffers.so:devel/flatbuffers \
 		libdouble-conversion.so:devel/double-conversion
-RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}absl>=0.7.0:devel/py-absl@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}astor>=0.5:devel/py-astor@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}gast>=0.2.2:devel/py-gast@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}numpy>=1.11.2:math/py-numpy@${PY_FLAVOR} \
+RUN_DEPENDS=	pybind11>=2.6.2:devel/pybind11 \
+		${PYTHON_PKGNAMEPREFIX}absl-py>=1.0.0:devel/py-absl-py \
+		${PYTHON_PKGNAMEPREFIX}astunparse>=1.6.3:devel/py-astunparse@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}typing-extensions>=4.3.0:devel/py-typing-extensions@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}h5py>=2.9.0:science/py-h5py@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}flatbuffers>=2.0:devel/py-flatbuffers@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}gast>=0.5.3:devel/py-gast@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}numpy>=1.20.0:math/py-numpy@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}google-pasta>=0.1.7:devel/py-google-pasta@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}protobuf>=3.7.1:devel/py-protobuf@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}six>=1.10.0:devel/py-six@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}termcolor>=1.1.0:devel/py-termcolor@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}grpcio>=1.22.0:devel/py-grpcio@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}keras>=2.2.4:math/py-keras@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}wrapt>=1.11.2:devel/py-wrapt@${PY_FLAVOR} \
-		${PYTHON_PKGNAMEPREFIX}wheel>=0.30.0:devel/py-wheel@${PY_FLAVOR}
-
-USES=		cpe python:3.7+ shebangfix jpeg ssl compiler:c++17-lang
-CPE_VENDOR=	google
+		${PYTHON_PKGNAMEPREFIX}keras-preprocessing>=1.1.1:math/py-keras-preprocessing@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}wrapt>=1.14.1:devel/py-wrapt@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}wheel>=0.30.0:devel/py-wheel@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}opt-einsum>=3.3.0:math/py-opt-einsum@${PY_FLAVOR} \
+		${PYTHON_PKGNAMEPREFIX}packaging>=21.3:devel/py-packaging@${PY_FLAVOR} \
+		pybind11>=2.6.2:devel/pybind11
+
+USES=		python:3.7+ shebangfix jpeg ssl
+USE_CXXSTD=     c++17
 SHEBANG_GLOB=	*.py
 USE_GITHUB=	yes
 USE_PYTHON=	distutils
@@ -65,11 +70,26 @@ BAZEL_BOOT=	--output_user_root=${WRKDIR}/bazel_out
 
 PLIST_SUB=	TF_PORT_VERSION=${PORTVERSION}
 
-OPTIONS_DEFINE=		CPU_OPTS
+OPTIONS_DEFINE=			CPU_OPTS XLA
+OPTIONS_RADIO=			PARALLEL_JOBS
+OPTIONS_RADIO_PARALLEL_JOBS=	JOBS_1 JOBS_HALF JOBS_ALL
+PARALLEL_JOBS_DESC=		How many jobs to run during build?
+OPTIONS_DEFAULT=		JOBS_1
+
+JOBS_1_DESC=			Run one job
+JOBS_1_VARS=			TF_JOBS_NUMBER=1
+JOBS_HALF_DESC=			Run half jobs
+JOBS_HALF_VARS=			TF_JOBS_NUMBER="`expr \( ${MAKE_JOBS_NUMBER} + 1 \) / 2`"
+JOBS_ALL_DESC=			Run all jobs
+JOBS_ALL_VARS=			TF_JOBS_NUMBER=${MAKE_JOBS_NUMBER}
+
+CPU_OPTS_DESC=			Enable optimisations using features available on your CPU
+CPU_OPTS_VARS=			CPU_TARGET=native BAZEL_COPT="-c opt --copt=-march=native --copt=-mfpmath=sse"
+CPU_OPTS_VARS_OFF=		CPU_TARGET=x86-64
 
-CPU_OPTS_DESC=		Enable optimisations using features available on your CPU
-CPU_OPTS_VARS=		CPU_TARGET=native BAZEL_COPT="-c opt --copt=-march=native --copt=-mfpmath=sse"
-CPU_OPTS_VARS_OFF=	CPU_TARGET=x86-64
+XLA_DESC=			Accelerated Linear Algebra
+XLA_VARS=			XLA_OPT="1"
+XLA_VARS_OFF=			XLA_OPT="0"
 
 .include "Makefile.MASTER_SITES"
 
@@ -78,46 +98,62 @@ post-patch:
 	# This prevents bazel downloading the files without modifying
 	# the bzl files.
 	@${MKDIR} ${WRKDIR}/bazel-cache
-	@${MKDIR} ${WRKDIR}/bazel-distdir
-	@${CP} ${FILESDIR}/extra-patch-absl_base_internal_unscaledcycleclock.cc ${WRKSRC}/third_party/
+	@${MKDIR} ${WRKDIR}/bazel-dist
+	@${MKDIR} ${WRKDIR}/.bin
 
 .for file in ${DISTFILES:C/\:(.*)//}
-	@${ECHO} "Moving ${file} to ${WRKDIR}/bazel-cache"
-	@${CP} ${DISTDIR}/${DIST_SUBDIR}/${file} ${WRKDIR}/bazel-distdir
+	@${ECHO} "Moving ${file} to ${WRKDIR}/bazel-dist"
+	@${CP} ${DISTDIR}/${DIST_SUBDIR}/${file} ${WRKDIR}/bazel-dist
 .endfor
 
+	@${CP} ${PATCHDIR}/bazelrc ${WRKDIR}/bazelrc
+	@${CP} -R ${PATCHDIR}/bazel/* \
+		${WRKSRC}/third_party/
+
+	@${LN} -s ${PYTHON_CMD} ${WRKDIR}/.bin/python3
+	
 	@cd ${WRKSRC} && \
 		${REINPLACE_CMD} "s#--batch#${BAZEL_BOOT}\', \'--batch#" \
 		configure.py
 
-	@${CP} ${PATCHDIR}/bazelrc ${WRKDIR}/bazelrc
+	${REINPLACE_CMD} "s#%%PYTHON%%#${PYTHON_VERSION}#" ${WRKSRC}/configure \
+		${WRKSRC}/third_party/freebsd_python_fix.patch \
+		${WRKSRC}/tensorflow/compiler/mlir/quantization/tensorflow/BUILD
+
 	@${REINPLACE_CMD} "s#%%BAZEL_DIR%%#${WRKDIR}#" ${WRKDIR}/bazelrc
 	@${REINPLACE_CMD} "s#%%BAZEL_DIST%%#${WRKDIR}#" ${WRKDIR}/bazelrc
+	@${REINPLACE_CMD} "s#%%MLIR_LLVM_PATCH%%#/${WRKSRC}/bazel/bazel_llvm-raw_utils_bazel_configure.bzl#" \
+		${WRKSRC}/tensorflow/compiler/mlir/hlo/WORKSPACE
+
+	# use system pybind11, but use sed to fix includes, too many to maintain with patches
+	@${FIND} ${WRKSRC} -type f -name '*.cc' | ${XARGS} ${REINPLACE_CMD} "s#include\/pybind11#pybind11#"
+
+
+	# copy the toolchain over
+	@${CP} -R ${PATCHDIR}/freebsd \
+		${WRKSRC}/
+
+	@${REINPLACE_CMD} "s#%%PATH%%#${PATH}#" ${WRKDIR}/bazelrc
+
+	@${REINPLACE_CMD} "s#%%PYTHON%%#${PYTHON_CMD}#" ${WRKSRC}/.bazelrc
+
 	@${REINPLACE_CMD} "s#%%LOCALBASE%%#${LOCALBASE}#" ${WRKDIR}/bazelrc \
-		${WRKSRC}/tensorflow/tensorflow.bzl ${WRKSRC}/.bazelrc \
+		${WRKSRC}/third_party/absl/system.absl.strings.BUILD \
+		${WRKSRC}/freebsd/cc_toolchain_config.bzl \
+		${WRKSRC}/.bazelrc \
+		${WRKSRC}/tensorflow/tools/proto_text/BUILD \
+		${WRKSRC}/tensorflow/BUILD \
 		${WRKSRC}/tensorflow/core/BUILD \
-		${WRKSRC}/third_party/systemlibs/protobuf.bzl \
-		${WRKSRC}/tensorflow/core/profiler/rpc/client/BUILD \
-		${WRKSRC}/WORKSPACE \
-		${WRKSRC}/tensorflow/core/profiler/internal/BUILD \
-		${WRKSRC}/tensorflow/contrib/ffmpeg/default/BUILD \
-		${WRKSRC}/third_party/flatbuffers/BUILD.system
+		${WRKSRC}/third_party/systemlibs/protobuf.BUILD
+
 
 do-configure:
 	@cd ${WRKSRC} && ${SETENV} \
-		BAZEL_CXXOPTS="-std=c++1z" \
 		PYTHON_BIN_PATH=${PYTHON_CMD} \
 		PYTHON_LIB_PATH="${PYTHON_SITELIBDIR}" \
-		TF_NEED_JEMALLOC=0 \
-		TF_NEED_KAFKA=0 \
+		KERAS_HOME="${WRKDIR}/.keras" \
 		TF_NEED_OPENCL_SYCL=0 \
-		TF_NEED_AWS=0 \
-		TF_NEED_GCP=0 \
-		TF_NEED_HDFS=0 \
-		TF_NEED_S3=0 \
-		TF_ENABLE_XLA=0 \
-		TF_NEED_GDR=0 \
-		TF_NEED_VERBS=0 \
+		TF_ENABLE_XLA=${XLA_OPT} \
 		TF_NEED_OPENCL=0 \
 		TF_NEED_MPI=0 \
 		TF_NEED_TENSORRT=0 \
@@ -128,39 +164,61 @@ do-configure:
 		TF_SET_ANDROID_WORKSPACE=0 \
 		TF_DOWNLOAD_CLANG=0 \
 		TF_NEED_NCCL=0 \
-		TF_NEED_OPENCL=0 \
 		TF_IGNORE_MAX_BAZEL_VERSION=1 \
 		CC_OPT_FLAGS="-march=${CPU_TARGET} -I${LOCALBASE}/include" \
 		PREFIX="${LOCALBASE}" \
-		TF_SYSTEM_LIBS="absl_py astor_archive boringssl com_github_googleapis_googleapis com_github_googlecloudplatform_google_cloud_cpp com_google_protobuf com_googlesource_code_re2 \
-			curl cython double_conversion enum34_archive flatbuffers functools32_archive gast_archive gif_archive grpc hwloc icu jpeg jsoncpp_git keras_applications_archive \
-			lmdb nasm nsync opt_einsum_archive org_sqlite pasta pcre png_archive six_archive snappy swig termcolor_archive wrapt zlib_archive" \
+		TF_SYSTEM_LIBS="absl_py astor_archive astunparse_archive boringssl com_github_googlecloudplatform_google_cloud_cpp com_github_grpc_grpc \
+				com_google_absl com_google_protobuf curl cython dill_archive double_conversion functools32_archive gast_archive \
+				gif hwloc icu jsoncpp_git libjpeg_turbo lmdb nasm nsync opt_einsum_archive org_sqlite pasta png pybind11 six_archive snappy \
+				tblib_archive termcolor_archive typing_extensions_archive wrapt zlib" \
 		./configure
 
 do-build:
 	@cd ${WRKSRC} && \
-		bazel --bazelrc="${WRKDIR}/bazelrc" ${BAZEL_BOOT} build --jobs 16 ${BAZEL_COPT} --host_copt="-I${LOCALBASE}/include" \
-		--host_linkopt="-L${LOCALBASE}/lib" --linkopt="-L${LOCALBASE}/lib" --config=c++17 --copt="-I${LOCALBASE}/include" \
-		--cxxopt="--std=c++1z" --verbose_failures -s \
-		--distdir=${WORKDIR}/bazel-dist \
+		bazel --bazelrc="${WRKDIR}/bazelrc" ${BAZEL_BOOT} build --jobs ${TF_JOBS_NUMBER} ${BAZEL_COPT} --host_copt="-I${LOCALBASE}/include" \
+		--host_linkopt="-L${LOCALBASE}/lib -lexecinfo" --linkopt="-L${LOCALBASE}/lib -lexecinfo" --copt="-I${LOCALBASE}/include" \
+		--verbose_failures -s \
+		--distdir=${WRKDIR}/bazel-dist \
 		//tensorflow:libtensorflow_framework.so \
 		//tensorflow:libtensorflow.so \
 		//tensorflow:libtensorflow_cc.so \
+		//tensorflow:install_headers \
 		//tensorflow/tools/pip_package:build_pip_package
 
+
 	@cd ${WRKSRC} && ${SETENV} TMPDIR=${WRKDIR} \
 		bazel-bin/tensorflow/tools/pip_package/build_pip_package \
 		${WRKDIR}/whl
 
 do-install:
 	@${MKDIR} ${STAGEDIR}/${PYTHON_SITELIBDIR}
-	@${MKDIR} ${WRKDIR}/tmp
-	@${UNZIP_NATIVE_CMD} -d ${WRKDIR}/tmp ${WRKDIR}/whl/${PORTNAME}-${PORTVERSION}-*.whl
-	@${FIND} ${WRKDIR}/tmp -name "*.so*" | ${XARGS} ${STRIP_CMD}
-	cd ${WRKDIR}/tmp && ${COPYTREE_SHARE} ${PORTNAME}-${PORTVERSION}.dist-info \
-		${STAGEDIR}${PYTHON_SITELIBDIR}
-	cd ${WRKDIR}/tmp/${PORTNAME}-${PORTVERSION}.data/purelib && \
-		${COPYTREE_SHARE} . ${STAGEDIR}${PYTHON_SITELIBDIR}
+	@${MKDIR} ${STAGEDIR}/${LOCALBASE}/include/tensorflow
+
+	@${UNZIP_NATIVE_CMD} -d ${STAGEDIR}/${PYTHON_SITELIBDIR} ${WRKDIR}/whl/${PORTNAME}-${PORTVERSION}-*.whl
+
+	# put headers in the right folder
+	${CP} -R ${WRKSRC}/bazel-bin/tensorflow/include/tensorflow \
+		${STAGEDIR}/${LOCALBASE}/include/
+
+	# pc files and libraries
+	${INSTALL_DATA} ${PATCHDIR}/tensorflow.pc ${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/
+	${INSTALL_DATA} ${PATCHDIR}/tensorflow_cc.pc ${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/
+
+	@${REINPLACE_CMD} "s#%%LOCALBASE%%#${LOCALBASE}#" \
+		${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/tensorflow.pc \
+		${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/tensorflow_cc.pc
+
+	@${REINPLACE_CMD} "s#%%VERSION%%#${PORTVERSION}#" \
+		${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/tensorflow.pc	
+
+	#cleanup
+	${RM} ${STAGEDIR}/${LOCALBASE}/libdata/pkgconfig/*.bak
+
+	# install the libraries and strip
+	@${FIND} ${WRKSRC}/bazel-bin/tensorflow/ -depth 1 -name "*.so*" | ${XARGS} -I{} \
+		${INSTALL_LIB} {} ${STAGEDIR}/${LOCALBASE}/lib/
+
+	@${FIND} ${STAGEDIR}/${LOCALBASE}/lib -name "*.so*" | ${XARGS} ${STRIP_CMD}
 
 post-install: # autoplist: thousands of files, all under ${PYTHON_SITELIBDIR}
 	@cd ${STAGEDIR}${PREFIX} && \
diff --git a/science/py-tensorflow/Makefile.MASTER_SITES b/science/py-tensorflow/Makefile.MASTER_SITES
index 880ca476664f..35742be9ba95 100644
--- a/science/py-tensorflow/Makefile.MASTER_SITES
+++ b/science/py-tensorflow/Makefile.MASTER_SITES
@@ -1,39 +1,75 @@
-DISTFILES+=	fft2d.tgz:oourafft2d \
-		49177915a14a.tar.gz:eigen \
-		43ef2148c0936ebf7cb4be6b19927a9d9d145b8f.tar.gz:abseil \
-		bazel-skylib.0.8.0.tar.gz:skylib \
-		92dd8a7a518a2fb7ba992d47c8b38299fe0be825.tar.gz:toolchain \
+DISTFILES+=	platforms-0.0.2.tar.gz:platforms \
+		apple_support.0.12.1.tar.gz:apple \
+		bazel-skylib-1.0.3.tar.gz:skylib \
+		dfc67056200b674accd08d8f9a21e328098c07e2.tar.gz:toolchain \
+		v0.1.1.zip:buildrules \
+		rules_apple.0.33.0.tar.gz:applerules \
+		081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz:rulescc \
 		308b05b2419edb5c8ee0471b67a40403df940149.tar.gz:closure \
-		0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip:rulescc \
 		rules_docker-v0.10.0.tar.gz:docker \
-		rules_swift.0.11.1.tar.gz:swift \
-		816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz:farmhash \
-		12fed0cd7cfcd9e169bf1925bc3a7a58725fdcc3.zip:gemmlowp \
+		7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip:java \
+		rules_pkg-0.2.5.tar.gz:pkg \
+		11bf7c25e666dd7ddacbcd4d4c4a9de7a25175f8.tar.gz:protolib \
+		rules_python-0.0.1.tar.gz:pythonrules \
+		rules_swift.0.25.0.tar.gz:swift \
+		790d7a083520398268d92d0bd61cf85dfa32ee98.tar.gz:dlpack \
+		0d859a811870d10f53a594927d0d0b97573ad06d.tar.gz:farmhash \
+		e844ffd17118c1e17d94e1ba4354c075a4577b88.zip:gemmlowp \
 		fd3d9af80465e4383162e4a7c5e2f406e82dd968.tar.gz:highwayhash \
-		36dbc057604f00aacfc0288ddad57e3b21cfc1b8.tar.gz:kissfft \
-		94d31935a2c94fe7e7c7379a0f3393e181928ff7.tar.gz:bazel \
-		v2.3.0.tar.gz:pybind \
-		7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz:llvm \
-		1200fe90bb174a6224a525ee60148671a786a71f.tar.gz:neon \
-		license.rst.txt:license \
-		backports.weakref-1.0rc1.tar.gz:weakref 
+		506cfa4bffd060c06ec338ce50ea3468daa6c814.tar.gz:re2 \
+		e6c1b8dc8a8b00ee74e7268aac8b18d7260ab1ce.zip:ruy \
+		835a7d7b1ee3bc83e575e302a985c66ec4b65249.tar.gz:sobol \
+		openmp-10.0.1.src.tar.xz:llvmorg \
+		36dbc057604f00aacfc0288ddad57e3b21cfc1b8.tar.gz:kiss \
+		v2.6.tar.gz:onednn \
+		v1.0.tar.gz:ooura \
+		5916273f79a21551890fd3d56fc5375a78d1598d.zip:cpuinfo \
+		d5e37adf1406cf899d7d9ec1d317c47506ccb970.tar.gz:cpuinfo2 \
+		093ed77f7d50f75b376f40a71ea86e08cedb8b80.tar.gz:runtime \
+		eigen-008ff3483a8c5604639e1c4d204eae30ad737af6.tar.gz:eigen \
+		11b2812d64e49bab9b6c489f79067fc94e69db9f.zip:xnnpack \
+		b8374f80e42010941bda6c85b0e3f1a1bd77a1e0.zip:pthread \
+		4dfe081cf6bcd15db339cf2680b9281b8451eeb3.zip:fp16 \
+		63058eff77e11aa15bf531df5dd34395ec3017c8.zip:fxdiv \
+		1cb299165c859533e22f2ed05eb2abd5071544df.tar.gz:llvm \
+		541b1ded4abadcc38e8178680b0677f65594ea6f.zip:apis \
+		v1.12.0.tar.gz:flatbuffer \
+		1200fe90bb174a6224a525ee60148671a786a71f.tar.gz:neon
 
-MASTER_SITES+=	http://www.kurims.kyoto-u.ac.jp/~ooura/:oourafft2d \
-		https://storage.googleapis.com/mirror.tensorflow.org/bitbucket.org/eigen/eigen/get/:eigen \
-		https://github.com/abseil/abseil-cpp/archive/:abseil \
-		https://github.com/bazelbuild/bazel-skylib/releases/download/0.8.0/:skylib \
+MASTER_SITES+=	https://github.com/bazelbuild/platforms/releases/download/0.0.2/:platforms \
+		https://github.com/bazelbuild/apple_support/releases/download/0.12.1/:apple \
+		https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/:skylib \
 		https://github.com/bazelbuild/bazel-toolchains/archive/:toolchain \
+		https://github.com/bazelbuild/rules_android/archive/:buildrules \
+		https://github.com/bazelbuild/rules_apple/releases/download/0.33.0/:applerules \
+		https://github.com/bazelbuild/rules_cc/archive/:rulescc \
 		https://github.com/bazelbuild/rules_closure/archive/:closure \
 		https://github.com/bazelbuild/rules_docker/releases/download/v0.10.0/:docker \
-		https://github.com/bazelbuild/rules_swift/releases/download/0.11.1/:swift \
+		https://github.com/bazelbuild/rules_java/archive/:java \
+		https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/:pkg \
+		https://github.com/bazelbuild/rules_proto/archive/:protolib \
+		https://github.com/bazelbuild/rules_python/releases/download/0.0.1/:pythonrules \
+		https://github.com/bazelbuild/rules_swift/releases/download/0.25.0/:swift \
+		https://github.com/dmlc/dlpack/archive/:dlpack \
 		https://github.com/google/farmhash/archive/:farmhash \
 		https://github.com/google/gemmlowp/archive/:gemmlowp \
 		https://github.com/google/highwayhash/archive/:highwayhash \
-		https://github.com/mborgerding/kissfft/archive/:kissfft \
-		https://github.com/nlopezgi/bazel-toolchains/archive/:bazel \
-		https://github.com/pybind/pybind11/archive/:pybind \
-		https://github.com/llvm-mirror/llvm/archive/:llvm \
-		https://github.com/intel/ARM_NEON_2_x86_SSE/archive/:neon \
-		https://storage.googleapis.com/mirror.tensorflow.org/docs.python.org/2.7/_sources/:license \
-		https://pypi.python.org/packages/bc/cc/3cdb0a02e7e96f6c70bd971bc8a90b8463fda83e264fa9c5c1c98ceabd81/:weakref \
-		https://github.com/bazelbuild/rules_cc/archive/:rulescc
+		https://github.com/google/re2/archive/:re2 \
+		https://github.com/google/ruy/archive/:ruy \
+		https://github.com/joe-kuo/sobol_data/archive/:sobol \
+		https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/:llvmorg \
+		https://github.com/mborgerding/kissfft/archive/:kiss \
+		https://github.com/oneapi-src/oneDNN/archive/refs/tags/:onednn \
+		https://github.com/petewarden/OouraFFT/archive/:ooura \
+		https://github.com/pytorch/cpuinfo/archive/:cpuinfo \
+		https://github.com/pytorch/cpuinfo/archive/:cpuinfo2 \
+		https://github.com/tensorflow/runtime/archive/:runtime \
+		https://gitlab.com/libeigen/eigen/-/archive/008ff3483a8c5604639e1c4d204eae30ad737af6/:eigen \
+		https://github.com/google/XNNPACK/archive/:xnnpack \
+		https://github.com/Maratyszcza/pthreadpool/archive/:pthread \
+		https://github.com/Maratyszcza/FP16/archive/:fp16 \
+		https://github.com/Maratyszcza/FXdiv/archive/:fxdiv \
+		https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/:llvm \
+		https://github.com/googleapis/googleapis/archive/:apis \
+		https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/flatbuffers/archive/:flatbuffer \
+		https://github.com/intel/ARM_NEON_2_x86_SSE/archive/:neon
diff --git a/science/py-tensorflow/distinfo b/science/py-tensorflow/distinfo
index 82662ad2bd6f..d9d9a2254845 100644
--- a/science/py-tensorflow/distinfo
+++ b/science/py-tensorflow/distinfo
@@ -1,41 +1,77 @@
-TIMESTAMP = 1625741393
-SHA256 (tensorflow/fft2d.tgz) = ada7e99087c4ed477bfdf11413f2ba8db8a840ba9bbf8ac94f4f3972e2a7cec9
-SIZE (tensorflow/fft2d.tgz) = 54434
-SHA256 (tensorflow/49177915a14a.tar.gz) = b3e1c3df05377d22bb960f54acce8d7018bc9477f37e8f39f9d3c784f5aaa87f
-SIZE (tensorflow/49177915a14a.tar.gz) = 2496808
-SHA256 (tensorflow/43ef2148c0936ebf7cb4be6b19927a9d9d145b8f.tar.gz) = acd93f6baaedc4414ebd08b33bebca7c7a46888916101d8c0b8083573526d070
-SIZE (tensorflow/43ef2148c0936ebf7cb4be6b19927a9d9d145b8f.tar.gz) = 1281523
-SHA256 (tensorflow/bazel-skylib.0.8.0.tar.gz) = 2ef429f5d7ce7111263289644d233707dba35e39696377ebab8b0bc701f7818e
-SIZE (tensorflow/bazel-skylib.0.8.0.tar.gz) = 72941
-SHA256 (tensorflow/92dd8a7a518a2fb7ba992d47c8b38299fe0be825.tar.gz) = 88e818f9f03628eef609c8429c210ecf265ffe46c2af095f36c7ef8b1855fef5
-SIZE (tensorflow/92dd8a7a518a2fb7ba992d47c8b38299fe0be825.tar.gz) = 660374
+TIMESTAMP = 1662651809
+SHA256 (tensorflow/platforms-0.0.2.tar.gz) = 48a2d8d343863989c232843e01afc8a986eb8738766bfd8611420a7db8f6f0c3
+SIZE (tensorflow/platforms-0.0.2.tar.gz) = 5278
+SHA256 (tensorflow/apple_support.0.12.1.tar.gz) = c604b75865c07f45828c7fffd5fdbff81415a9e84a68f71a9c1d8e3b2694e547
+SIZE (tensorflow/apple_support.0.12.1.tar.gz) = 26708
+SHA256 (tensorflow/bazel-skylib-1.0.3.tar.gz) = 1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c
+SIZE (tensorflow/bazel-skylib-1.0.3.tar.gz) = 30711
+SHA256 (tensorflow/dfc67056200b674accd08d8f9a21e328098c07e2.tar.gz) = 77c2c3c562907a1114afde7b358bf3d5cc23dc61b3f2fd619bf167af0c9582a3
+SIZE (tensorflow/dfc67056200b674accd08d8f9a21e328098c07e2.tar.gz) = 1056209
+SHA256 (tensorflow/v0.1.1.zip) = cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806
+SIZE (tensorflow/v0.1.1.zip) = 14654
+SHA256 (tensorflow/rules_apple.0.33.0.tar.gz) = a5f00fd89eff67291f6cd3efdc8fad30f4727e6ebb90718f3f05bbf3c3dd5ed7
+SIZE (tensorflow/rules_apple.0.33.0.tar.gz) = 2168079
+SHA256 (tensorflow/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz) = ff7876d80cd3f6b8c7a064bd9aa42a78e02096544cca2b22a9cf390a4397a53e
+SIZE (tensorflow/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e.tar.gz) = 130803
 SHA256 (tensorflow/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz) = 5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9
 SIZE (tensorflow/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz) = 464906
-SHA256 (tensorflow/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip) = 36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89
-SIZE (tensorflow/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip) = 72534
 SHA256 (tensorflow/rules_docker-v0.10.0.tar.gz) = 7d453450e1eb70e238eea6b31f4115607ec1200e91afea01c25f9804f37e39c8
 SIZE (tensorflow/rules_docker-v0.10.0.tar.gz) = 549649
-SHA256 (tensorflow/rules_swift.0.11.1.tar.gz) = 96a86afcbdab215f8363e65a10cf023b752e90b23abf02272c4fc668fcb70311
-SIZE (tensorflow/rules_swift.0.11.1.tar.gz) = 107453
-SHA256 (tensorflow/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz) = 6560547c63e4af82b0f202cb710ceabb3f21347a4b996db565a411da5b17aba0
-SIZE (tensorflow/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz) = 467122
-SHA256 (tensorflow/12fed0cd7cfcd9e169bf1925bc3a7a58725fdcc3.zip) = 6678b484d929f2d0d3229d8ac4e3b815a950c86bb9f17851471d143f6d4f7834
-SIZE (tensorflow/12fed0cd7cfcd9e169bf1925bc3a7a58725fdcc3.zip) = 935628
+SHA256 (tensorflow/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip) = bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598
+SIZE (tensorflow/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip) = 9422
+SHA256 (tensorflow/rules_pkg-0.2.5.tar.gz) = 352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a
+SIZE (tensorflow/rules_pkg-0.2.5.tar.gz) = 29857
+SHA256 (tensorflow/11bf7c25e666dd7ddacbcd4d4c4a9de7a25175f8.tar.gz) = 20b240eba17a36be4b0b22635aca63053913d5c1ee36e16be36499d167a2f533
+SIZE (tensorflow/11bf7c25e666dd7ddacbcd4d4c4a9de7a25175f8.tar.gz) = 14304
+SHA256 (tensorflow/rules_python-0.0.1.tar.gz) = aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161
+SIZE (tensorflow/rules_python-0.0.1.tar.gz) = 2302092
+SHA256 (tensorflow/rules_swift.0.25.0.tar.gz) = 8a49da750560b185804a4bc95c82d3f9cc4c2caf788960b0e21945759155fdd9
+SIZE (tensorflow/rules_swift.0.25.0.tar.gz) = 184783
+SHA256 (tensorflow/790d7a083520398268d92d0bd61cf85dfa32ee98.tar.gz) = 147cc89904375dcd0b0d664a2b72dfadbb02058800ad8cba84516094bc406208
+SIZE (tensorflow/790d7a083520398268d92d0bd61cf85dfa32ee98.tar.gz) = 45837
+SHA256 (tensorflow/0d859a811870d10f53a594927d0d0b97573ad06d.tar.gz) = 18392cf0736e1d62ecbb8d695c31496b6507859e8c75541d7ad0ba092dc52115
+SIZE (tensorflow/0d859a811870d10f53a594927d0d0b97573ad06d.tar.gz) = 467251
+SHA256 (tensorflow/e844ffd17118c1e17d94e1ba4354c075a4577b88.zip) = 522b7a82d920ebd0c4408a5365866a40b81d1c0d60b2369011d315cca03c6476
+SIZE (tensorflow/e844ffd17118c1e17d94e1ba4354c075a4577b88.zip) = 940590
 SHA256 (tensorflow/fd3d9af80465e4383162e4a7c5e2f406e82dd968.tar.gz) = 9c3e0e87d581feeb0c18d814d98f170ff23e62967a2bd6855847f0b2fe598a37
 SIZE (tensorflow/fd3d9af80465e4383162e4a7c5e2f406e82dd968.tar.gz) = 138574
+SHA256 (tensorflow/506cfa4bffd060c06ec338ce50ea3468daa6c814.tar.gz) = d070e2ffc5476c496a6a872a6f246bfddce8e7797d6ba605a7c8d72866743bf9
+SIZE (tensorflow/506cfa4bffd060c06ec338ce50ea3468daa6c814.tar.gz) = 316237
+SHA256 (tensorflow/e6c1b8dc8a8b00ee74e7268aac8b18d7260ab1ce.zip) = fa9a0b9041095817bc3533f7b125c3b4044570c0b3ee6c436d2d29dae001c06b
+SIZE (tensorflow/e6c1b8dc8a8b00ee74e7268aac8b18d7260ab1ce.zip) = 375516
+SHA256 (tensorflow/835a7d7b1ee3bc83e575e302a985c66ec4b65249.tar.gz) = 583d7b975e506c076fc579d9139530596906b9195b203d42361417e9aad79b73
+SIZE (tensorflow/835a7d7b1ee3bc83e575e302a985c66ec4b65249.tar.gz) = 2569603
+SHA256 (tensorflow/openmp-10.0.1.src.tar.xz) = d19f728c8e04fb1e94566c8d76aef50ec926cd2f95ef3bf1e0a5de4909b28b44
+SIZE (tensorflow/openmp-10.0.1.src.tar.xz) = 955492
 SHA256 (tensorflow/36dbc057604f00aacfc0288ddad57e3b21cfc1b8.tar.gz) = 42b7ef406d5aa2d57a7b3b56fc44e8ad3011581692458a69958a911071efdcf2
 SIZE (tensorflow/36dbc057604f00aacfc0288ddad57e3b21cfc1b8.tar.gz) = 44744
-SHA256 (tensorflow/94d31935a2c94fe7e7c7379a0f3393e181928ff7.tar.gz) = 109a99384f9d08f9e75136d218ebaebc68cc810c56897aea2224c57932052d30
-SIZE (tensorflow/94d31935a2c94fe7e7c7379a0f3393e181928ff7.tar.gz) = 505681
-SHA256 (tensorflow/v2.3.0.tar.gz) = 0f34838f2c8024a6765168227ba587b3687729ebf03dc912f88ff75c7aa9cfe8
-SIZE (tensorflow/v2.3.0.tar.gz) = 564520
-SHA256 (tensorflow/7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz) = 599b89411df88b9e2be40b019e7ab0f7c9c10dd5ab1c948cd22e678cc8f8f352
-SIZE (tensorflow/7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz) = 50144723
+SHA256 (tensorflow/v2.6.tar.gz) = 9695640f55acd833ddcef4776af15e03446c4655f9296e5074b1b178dd7a4fb2
+SIZE (tensorflow/v2.6.tar.gz) = 5840464
+SHA256 (tensorflow/v1.0.tar.gz) = 5f4dabc2ae21e1f537425d58a49cdca1c49ea11db0d6271e2a4b27e9697548eb
+SIZE (tensorflow/v1.0.tar.gz) = 110531
+SHA256 (tensorflow/5916273f79a21551890fd3d56fc5375a78d1598d.zip) = 2a160c527d3c58085ce260f34f9e2b161adc009b34186a2baf24e74376e89e6d
+SIZE (tensorflow/5916273f79a21551890fd3d56fc5375a78d1598d.zip) = 3787933
+SHA256 (tensorflow/d5e37adf1406cf899d7d9ec1d317c47506ccb970.tar.gz) = 3f2dc1970f397a0e59db72f9fca6ff144b216895c1d606f6c94a507c1e53a025
+SIZE (tensorflow/d5e37adf1406cf899d7d9ec1d317c47506ccb970.tar.gz) = 3489028
+SHA256 (tensorflow/093ed77f7d50f75b376f40a71ea86e08cedb8b80.tar.gz) = fce593c95eb508092c4a1752130868b6d2eae0fd4a5363b9d96195fd85b7cfec
+SIZE (tensorflow/093ed77f7d50f75b376f40a71ea86e08cedb8b80.tar.gz) = 15323415
+SHA256 (tensorflow/eigen-008ff3483a8c5604639e1c4d204eae30ad737af6.tar.gz) = e1dd31ce174c3d26fbe38388f64b09d2adbd7557a59e90e6f545a288cc1755fc
+SIZE (tensorflow/eigen-008ff3483a8c5604639e1c4d204eae30ad737af6.tar.gz) = 2733792
+SHA256 (tensorflow/11b2812d64e49bab9b6c489f79067fc94e69db9f.zip) = 7e9ad45391e5158fd00e816022bda21d54a6180788af7c455c864a78cee252c6
+SIZE (tensorflow/11b2812d64e49bab9b6c489f79067fc94e69db9f.zip) = 17103217
+SHA256 (tensorflow/b8374f80e42010941bda6c85b0e3f1a1bd77a1e0.zip) = b96413b10dd8edaa4f6c0a60c6cf5ef55eebeef78164d5d69294c8173457f0ec
+SIZE (tensorflow/b8374f80e42010941bda6c85b0e3f1a1bd77a1e0.zip) = 61524
+SHA256 (tensorflow/4dfe081cf6bcd15db339cf2680b9281b8451eeb3.zip) = d973501a40c55126b31accc2d9f08d931ec3cc190c0430309a5e341d3c0ce32a
+SIZE (tensorflow/4dfe081cf6bcd15db339cf2680b9281b8451eeb3.zip) = 91462
+SHA256 (tensorflow/63058eff77e11aa15bf531df5dd34395ec3017c8.zip) = 3d7b0e9c4c658a84376a1086126be02f9b7f753caa95e009d9ac38d11da444db
+SIZE (tensorflow/63058eff77e11aa15bf531df5dd34395ec3017c8.zip) = 16646
+SHA256 (tensorflow/1cb299165c859533e22f2ed05eb2abd5071544df.tar.gz) = 5a19ab6de4b0089fff456c0bc406b37ba5f95c76026e6bec294ec28dc28e4cb9
+SIZE (tensorflow/1cb299165c859533e22f2ed05eb2abd5071544df.tar.gz) = 162307281
+SHA256 (tensorflow/541b1ded4abadcc38e8178680b0677f65594ea6f.zip) = 7ebab01b06c555f4b6514453dc3e1667f810ef91d1d4d2d3aa29bb9fcb40a900
+SIZE (tensorflow/541b1ded4abadcc38e8178680b0677f65594ea6f.zip) = 5498751
+SHA256 (tensorflow/v1.12.0.tar.gz) = 62f2223fb9181d1d6338451375628975775f7522185266cd5296571ac152bc45
+SIZE (tensorflow/v1.12.0.tar.gz) = 1145348
 SHA256 (tensorflow/1200fe90bb174a6224a525ee60148671a786a71f.tar.gz) = 213733991310b904b11b053ac224fee2d4e0179e46b52fe7f8735b8831e04dcc
 SIZE (tensorflow/1200fe90bb174a6224a525ee60148671a786a71f.tar.gz) = 100612
-SHA256 (tensorflow/license.rst.txt) = e76cacdf0bdd265ff074ccca03671c33126f597f39d0ed97bc3e5673d9170cf6
-SIZE (tensorflow/license.rst.txt) = 45132
-SHA256 (tensorflow/backports.weakref-1.0rc1.tar.gz) = 8813bf712a66b3d8b85dc289e1104ed220f1878cf981e2fe756dfaabe9a82892
-SIZE (tensorflow/backports.weakref-1.0rc1.tar.gz) = 7761
-SHA256 (tensorflow/tensorflow-tensorflow-v1.15.5_GH0.tar.gz) = 4c4d23e311093ded2d2e287b18d7c45b07b5984ab88a1d2f91f8f13c886123db
-SIZE (tensorflow/tensorflow-tensorflow-v1.15.5_GH0.tar.gz) = 46212258
+SHA256 (tensorflow/tensorflow-tensorflow-v2.9.1_GH0.tar.gz) = 6eaf86ead73e23988fe192da1db68f4d3828bcdd0f3a9dc195935e339c95dbdc
+SIZE (tensorflow/tensorflow-tensorflow-v2.9.1_GH0.tar.gz) = 66654318
diff --git a/science/py-tensorflow/files/bazel/add-default-option.patch b/science/py-tensorflow/files/bazel/add-default-option.patch
new file mode 100644
index 000000000000..ce5c250608fb
--- /dev/null
+++ b/science/py-tensorflow/files/bazel/add-default-option.patch
@@ -0,0 +1,37 @@
+--- a/build_defs.bzl    2022-08-28 12:18:33.375130000 +0100
++++ b/build_defs.bzl	2022-08-28 12:21:40.701070000 +0100
+@@ -173,7 +173,7 @@
+             ":emscripten_wasm": wasm_srcs,
+             ":emscripten_wasmsimd": wasmsimd_srcs,
+             ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_srcs,
+-            "//conditions:default": [],
++            "//conditions:default": x86_srcs,
+         }),
+         copts = [
+             "-Iinclude",
+@@ -210,7 +210,7 @@
+             ":emscripten_wasm": wasm_copts,
+             ":emscripten_wasmsimd": wasmsimd_copts,
+             ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_copts,
+-            "//conditions:default": [],
++            "//conditions:default": [opt for opt in gcc_x86_copts],
+         }) + select({
+             ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
+             ":windows_x86_64_mingw": gcc_copts,
+@@ -233,7 +233,7 @@
+             ":linux_armv7a": ["-lpthread"],
+             ":linux_arm64": ["-lpthread"],
+             ":android": ["-lm"],
+-            "//conditions:default": [],
++            "//conditions:default": ["-lpthread"],
+         }),
+         textual_hdrs = hdrs,
+         visibility = visibility,
+@@ -304,6 +304,7 @@
+             ":emscripten_wasm": wasm_deps,
+             ":emscripten_wasmsimd": wasmsimd_deps,
+             ":emscripten_wasmrelaxedsimd": wasmrelaxedsimd_deps,
++            "//conditions:default": x86_deps,
+         }),
+     )
+ 
diff --git a/science/py-tensorflow/files/bazel/fix-environ.patch b/science/py-tensorflow/files/bazel/fix-environ.patch
new file mode 100644
index 000000000000..2e38ce60543d
--- /dev/null
+++ b/science/py-tensorflow/files/bazel/fix-environ.patch
@@ -0,0 +1,42 @@
+--- a/llvm/lib/Support/Unix/Program.inc	2022-09-06 21:14:28.808580000 +0100
++++ b/llvm/lib/Support/Unix/Program.inc	2022-09-06 21:16:15.007790000 +0100
+@@ -54,10 +54,8 @@
+ #define USE_NSGETENVIRON 0
+ #endif
+ 
+-#if !USE_NSGETENVIRON
++#if USE_NSGETENVIRON
+   extern char **environ;
+-#else
+-#include <crt_externs.h> // _NSGetEnviron
+ #endif
+ #endif
+ 
+@@ -240,14 +238,6 @@
+       }
+     }
+ 
+-    if (!Envp)
+-#if !USE_NSGETENVIRON
+-      Envp = const_cast<const char **>(environ);
+-#else
+-      // environ is missing in dylibs.
+-      Envp = const_cast<const char **>(*_NSGetEnviron());
+-#endif
+-
+     constexpr int maxRetries = 8;
+     int retries = 0;
+     pid_t PID;
+@@ -308,11 +298,7 @@
+ 
+       // Execute!
+       std::string PathStr = std::string(Program);
+-      if (Envp != nullptr)
+-        execve(PathStr.c_str(), const_cast<char **>(Argv),
+-               const_cast<char **>(Envp));
+-      else
+-        execv(PathStr.c_str(), const_cast<char **>(Argv));
++      execv(PathStr.c_str(), const_cast<char **>(Argv));
+       // If the execve() failed, we should exit. Follow Unix protocol and
+       // return 127 if the executable was not found, and 126 otherwise.
+       // Use _exit rather than exit so that atexit functions and static
diff --git a/science/py-tensorflow/files/bazel/fix_cpuinfo.patch b/science/py-tensorflow/files/bazel/fix_cpuinfo.patch
new file mode 100644
index 000000000000..1041a2319286
--- /dev/null
+++ b/science/py-tensorflow/files/bazel/fix_cpuinfo.patch
@@ -0,0 +1,80 @@
+--- a/src/mach/topology.c	2022-09-01 12:09:36.036365000 +0100
++++ b/src/mach/topology.c	2022-09-01 12:09:07.146529000 +0100
+@@ -1,5 +1,4 @@
+ #include <string.h>
+-#include <alloca.h>
+ #include <errno.h>
+ 
+ #include <sys/types.h>
+@@ -8,38 +7,27 @@
+ #include <cpuinfo/log.h>
+ #include <mach/api.h>
+ 
+-#include <TargetConditionals.h>
+ 
+-
+ struct cpuinfo_mach_topology cpuinfo_mach_detect_topology(void) {
+ 	int cores = 1;
+ 	size_t sizeof_cores = sizeof(cores);
+-	if (sysctlbyname("hw.physicalcpu_max", &cores, &sizeof_cores, NULL, 0) != 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.physicalcpu_max\") failed: %s", strerror(errno));
++	if (sysctlbyname("hw.ncpu", &cores, &sizeof_cores, NULL, 0) != 0) {
++		cpuinfo_log_error("sysctlbyname(\"hw.ncpu\") failed: %s", strerror(errno));
+ 	} else if (cores <= 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.physicalcpu_max\") returned invalid value %d", cores);
++		cpuinfo_log_error("sysctlbyname(\"hw.ncpu\") returned invalid value %d", cores);
+ 		cores = 1;
+ 	}
+ 
+ 	int threads = 1;
+ 	size_t sizeof_threads = sizeof(threads);
+-	if (sysctlbyname("hw.logicalcpu_max", &threads, &sizeof_threads, NULL, 0) != 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.logicalcpu_max\") failed: %s", strerror(errno));
++	if (sysctlbyname("hw.ncpu", &threads, &sizeof_threads, NULL, 0) != 0) {
++		cpuinfo_log_error("sysctlbyname(\"ncpu\") failed: %s", strerror(errno));
+ 	} else if (threads <= 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.logicalcpu_max\") returned invalid value %d", threads);
++		cpuinfo_log_error("sysctlbyname(\"ncpu\") returned invalid value %d", threads);
+ 		threads = cores;
+ 	}
+ 
+ 	int packages = 1;
+-#if !TARGET_OS_IPHONE
+-	size_t sizeof_packages = sizeof(packages);
+-	if (sysctlbyname("hw.packages", &packages, &sizeof_packages, NULL, 0) != 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.packages\") failed: %s", strerror(errno));
+-	} else if (packages <= 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.packages\") returned invalid value %d", packages);
+-		packages = 1;
+-	}
+-#endif
+ 
+ 	cpuinfo_log_debug("mach topology: packages = %d, cores = %d, threads = %d", packages, (int) cores, (int) threads);
+ 	struct cpuinfo_mach_topology topology = {
+@@ -48,26 +36,5 @@
+ 		.threads = (uint32_t) threads
+ 	};
+ 
+-#if !TARGET_OS_IPHONE
+-	size_t cacheconfig_size = 0;
+-	if (sysctlbyname("hw.cacheconfig", NULL, &cacheconfig_size, NULL, 0) != 0) {
+-		cpuinfo_log_error("sysctlbyname(\"hw.cacheconfig\") failed: %s", strerror(errno));
+-	} else {
+-		uint64_t* cacheconfig = alloca(cacheconfig_size);
+-		if (sysctlbyname("hw.cacheconfig", cacheconfig, &cacheconfig_size, NULL, 0) != 0) {
+-			cpuinfo_log_error("sysctlbyname(\"hw.cacheconfig\") failed: %s", strerror(errno));
+-		} else {
+-			size_t cache_configs = cacheconfig_size / sizeof(uint64_t);
+-			cpuinfo_log_debug("mach hw.cacheconfig count: %zu", cache_configs);
+-			if (cache_configs > CPUINFO_MACH_MAX_CACHE_LEVELS) {
+-				cache_configs = CPUINFO_MACH_MAX_CACHE_LEVELS;
+-			}
+-			for (size_t i = 0; i < cache_configs; i++) {
+-				cpuinfo_log_debug("mach hw.cacheconfig[%zu]: %"PRIu64, i, cacheconfig[i]);
+-				topology.threads_per_cache[i] = cacheconfig[i];
+-			}
+-		}
+-	}
+-#endif
+ 	return topology;
+ }
diff --git a/science/py-tensorflow/files/bazel/freebsd_python_fix.patch b/science/py-tensorflow/files/bazel/freebsd_python_fix.patch
new file mode 100644
index 000000000000..e6bcae9950be
--- /dev/null
+++ b/science/py-tensorflow/files/bazel/freebsd_python_fix.patch
@@ -0,0 +1,11 @@
+--- a/utils/bazel/configure.bzl	2022-08-27 19:11:41.138993000 +0100
++++ b/utils/bazel/configure.bzl	2022-08-27 19:12:07.525186000 +0100
+@@ -37,7 +37,7 @@
+     overlay_path = bazel_path.get_child("llvm-project-overlay")
+     script_path = bazel_path.get_child("overlay_directories.py")
+ 
+-    python_bin = repository_ctx.which("python3")
++    python_bin = repository_ctx.which("%%PYTHON%%")
+     if not python_bin:
+         # Windows typically just defines "python" as python3. The script itself
+         # contains a check to ensure python3.
diff --git a/science/py-tensorflow/files/bazel/set-c++17.patch b/science/py-tensorflow/files/bazel/set-c++17.patch
new file mode 100644
index 000000000000..aef1f6c38467
--- /dev/null
+++ b/science/py-tensorflow/files/bazel/set-c++17.patch
@@ -0,0 +1,11 @@
+--- a/cc/private/toolchain/freebsd_cc_toolchain_config.bzl	2022-08-28 16:31:59.271838000 +0100
++++ b/cc/private/toolchain/freebsd_cc_toolchain_config.bzl	2022-08-28 16:32:10.096301000 +0100
+@@ -159,7 +159,7 @@
+             ),
+             flag_set(
+                 actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
+-                flag_groups = [flag_group(flags = ["-std=c++0x"])],
++                flag_groups = [flag_group(flags = ["-std=c++17"])],
+             ),
+         ],
+     )
diff --git a/science/py-tensorflow/files/bazelrc b/science/py-tensorflow/files/bazelrc
index 98a37af78dce..f3a2c1a76cb3 100644
--- a/science/py-tensorflow/files/bazelrc
+++ b/science/py-tensorflow/files/bazelrc
@@ -8,12 +8,28 @@ build --spawn_strategy=local --genrule_strategy=local
 test --spawn_strategy=local --genrule_strategy=local
 
 # make bazel only fetch distfiles from the cache
-fetch --repository_cache="%%BAZEL_DIR%%/bazel-cache/" --distdir="%%BAZEL_DIST%%/bazel-distdir/"
-build --repository_cache="%%BAZEL_DIR%%/bazel-cache/" --distdir="%%BAZEL_DIST%%/bazel-distdir/"
+fetch --repository_cache="%%BAZEL_DIR%%/bazel-cache/" --distdir="%%BAZEL_DIST%%/bazel-dist/"
+build --repository_cache="%%BAZEL_DIR%%/bazel-cache/" --distdir="%%BAZEL_DIST%%/bazel-dist/"
 
 build --define=PREFIX=%%LOCALBASE%%
 build --define=LIBDIR=%%LOCALBASE%%/lib
+build --define=INCLUDEDIR=%%LOCALBASE%%/include
+build --define=PROTOBUF_INCLUDE_PATH=%%LOCALBASE%%/include
 
-build --config=noaws --config=nohdfs --config=noignite --config=nokafka
+build --config=noaws --config=nohdfs
 build --define tensorflow_mkldnn_contraction_kernel=0
-build --incompatible_no_support_tools_in_action_inputs=false
+
+build --action_env=BAZEL_CXXOPTS="-std=c++17"
+build --incompatible_enable_cc_toolchain_resolution
+
+build --extra_toolchains=//freebsd:cc-toolchain-freebsd
+build --linkopt="-lexecinfo" --toolchain_resolution_debug=//freebsd:freebsd_clang
+
+# for python
+build --action_env=PATH=%%PATH%%
+build --host_action_env=PATH=%%PATH%%
+
+build --action_env=KERAS_HOME="%%BAZEL_DIST%%/.keras"
+build --host_action_env=KERAS_HOME="%%BAZEL_DIST%%/.keras"
+
+build --config=freebsd
diff --git a/science/py-tensorflow/files/extra-patch-absl_base_internal_unscaledcycleclock.cc b/science/py-tensorflow/files/extra-patch-absl_base_internal_unscaledcycleclock.cc
deleted file mode 100644
index 43bbada5c4bb..000000000000
--- a/science/py-tensorflow/files/extra-patch-absl_base_internal_unscaledcycleclock.cc
+++ /dev/null
@@ -1,47 +0,0 @@
---- a/absl/base/internal/unscaledcycleclock.cc.orig	2021-10-11 21:53:31.946215000 +0200
-+++ b/absl/base/internal/unscaledcycleclock.cc	2021-10-11 21:57:54.536557000 +0200
-@@ -21,8 +21,15 @@
- #endif
- 
- #if defined(__powerpc__) || defined(__ppc__)
-+#ifdef __linux__
- #include <sys/platform/ppc.h>
-+#else
-+#include "absl/base/call_once.h"
-+#include <sys/types.h>
-+#include <sys/sysctl.h>
-+#include <threads.h>
- #endif
-+#endif
- 
- #include "absl/base/internal/sysinfo.h"
- 
-@@ -56,11 +63,28 @@
- #elif defined(__powerpc__) || defined(__ppc__)
- 
- int64_t UnscaledCycleClock::Now() {
-+#ifdef __linux__
-   return __ppc_get_timebase();
-+#else
-+  int64_t tbr;
-+  asm volatile("mfspr %0, 268" : "=r"(tbr));
-+  return tbr;
-+#endif
- }
- 
- double UnscaledCycleClock::Frequency() {
-+#ifdef __linux__
-   return __ppc_get_timebase_freq();
-+#else
-+  static once_flag init_timebase_frequency_once;
-+  static double timebase_frequency = 0.0;
-+  base_internal::LowLevelCallOnce(&init_timebase_frequency_once, [&]() {
-+    size_t length = sizeof(timebase_frequency);
-+    sysctlbyname("kern.timecounter.tc.timebase.frequency", &timebase_frequency,
-+                 &length, nullptr, 0);
-+  });
-+  return timebase_frequency;
-+#endif
- }
- 
- #elif defined(__aarch64__)
diff --git a/science/py-tensorflow/files/freebsd/BUILD b/science/py-tensorflow/files/freebsd/BUILD
new file mode 100644
index 000000000000..4096b1c74d42
--- /dev/null
+++ b/science/py-tensorflow/files/freebsd/BUILD
@@ -0,0 +1,88 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# This becomes the BUILD file for @local_config_cc// under FreeBSD and OpenBSD.
+load(":cc_toolchain_config.bzl", "cc_toolchain_config")
+load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite")
+load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
+
+package(default_visibility = ["//visibility:public"])
+cc_library(
+    name = "malloc",
+)
+filegroup(
+    name = "empty",
+    srcs = [],
+)
+
+# Hardcoded toolchain, legacy behaviour.
+cc_toolchain_suite(
+    name = "freebsd_clang",
+    toolchains = {
+        "k8": ":cc-compiler-freebsd",
+	"freebsd": ":cc-compiler-freebsd",
+    },
+)
+
+cc_toolchain(
+    name = "cc-compiler-freebsd",
+    all_files = ":empty",
+    ar_files = ":empty",
+    as_files = ":empty",
+    compiler_files = ":empty",
+    dwp_files = ":empty",
+    linker_files = ":empty",
+    objcopy_files = ":empty",
+    strip_files = ":empty",
+    supports_param_files = 0,
+    toolchain_config = ":local_freebsd",
+    toolchain_identifier = "local_freebsd",
+)
+cc_toolchain_config(
+    name = "local_freebsd",
+    cpu = "k8",
+)
+
+toolchain(
+    name = "cc-toolchain-freebsd",
+    exec_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:freebsd",
+    ],
+    target_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:freebsd",
+    ],
+    toolchain = ":cc-compiler-freebsd",
+    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+py_runtime(
+    name = "freebsd_python",
+    interpreter_path = "/usr/local/bin/python3.9",
+    python_version = "PY3",
+    visibility = ["//visibility:public"],
+)
+
+py_runtime_pair(
+    name = "bsd_py_runtime_pair",
+    py2_runtime = None,
+    py3_runtime = ":freebsd_python",
+)
+
+toolchain(
+    name = "freebsd_py_toolchain",
+    toolchain = ":bsd_py_runtime_pair",
+    toolchain_type = "@bazel_tools//tools/python:toolchain_type",
*** 2736 LINES SKIPPED ***