Repository: tensorflow
Issue: Build: Protobuf fails with "File already exists in database"
Labels: stat:awaiting tensorflower,type:bug,type:build/install,TF 2.13

### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.13.0

### Custom code

No

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

3.10

### Bazel version

5.1.1

### GCC/compiler version

11.3

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Using the TF_SYSTEMLIBS version of protobuf (i.e. a preinstalled protobuf) when building TensorFlow from source results in

```
[libprotobuf ERROR /build/protobuf/3.19.4/GCCcore-11.3.0/protobuf-3.19.4/src/google/protobuf/descriptor_database.cc:641] File already exists in database: tensorflow/dtensor/proto/layout.proto
[libprotobuf FATAL /build/protobuf/3.19.4/GCCcore-11.3.0/protobuf-3.19.4/src/google/protobuf/descriptor.cc:2021] CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size): 
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size): 
```

I can't make much sense out of that failure and Google yielded results related to having the protobuf file in loaded in shared libraries multiple times.

All I could do is indeed trace it to `from tensorflow.dtensor.proto import layout_pb2` in tensorflow/dtensor/python/layout.py

### Standalone code to reproduce the issue

```shell
The failing build step invokes `/bin/bash -c 'bazel-out/ppc-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/ppc-opt/bin/tensorflow/_api/v2/ --apiname=tensorflow --apiversion=2  --compat_apiversion=1 --compat_apiversion=2  --compat_init_template=tensorflow/compat_template_v1.__init__.py --compat_init_template=tensorflow/compat_template.__init__.py --packages=tensorflow.python,tensorflow.dtensor.python.accelerator_util,tensorflow.dtensor.python.api,tensorflow.dtensor.python.config,tensorflow.dtensor.python.d_checkpoint,tensorflow.dtensor.python.d_variable,tensorflow.dtensor.python.input_util,tensorflow.dtensor.python.layout,tensorflow.dtensor.python.mesh_util,tensorflow.dtensor.python.tpu_util,tensorflow.dtensor.python.save_restore,tensorflow.lite.python.analyzer,tensorflow.lite.python.lite,tensorflow.lite.python.authoring.authoring,tensorflow.python.modules_with_exports --output_package=tensorflow._api.v2 --use_relative_imports=True --loading=default bazel-out/ppc-opt/bin/tensorflow/tf_python_api_gen_v2.params'`
```


### Relevant log output

```shell
# Configuration: 020ca55738349851eb8a5a672fc7b8d08dc15ebd99b324f52fddbad2f32820b8
# Execution platform: @local_execution_config_platform//:platform
ERROR: /build/TensorFlow/tensorflow-2.13.0/tensorflow/BUILD:1646:19: Action tensorflow/_api/v2/v2.py failed: (Aborted): bash failed: error executing command 
  (cd /build/TensorFlow/bazel-root/663b1bf019e1a9ec9827eae691fce071/execroot/org_tensorflow && \
  exec env - \
    CPATH=/sw/installed/cURL/7.83.0-GCCcore-11.3.0/include:/software/double-conversion/3.2.0-GCCcore-11.3.0/include:/software/flatbuffers/2.0.7-GCCcore-11.3.0/include:/sw/installed/giflib/5.2.1-GCCcore-11.3.0/include:/sw/installed/hwloc/2.7.1-GCCcore-11.3.0/include:/sw/installed/ICU/71.1-GCCcore-11.3.0/include:/software/JsonCpp/1.9.5-GCCcore-11.3.0/include:/sw/installed/libjpeg-turbo/2.1.3-GCCcore-11.3.0/include:/sw/installed/libpng/1.6.37-GCCcore-11.3.0/include:/software/nsync/1.25.0-GCCcore-11.3.0/include:/software/protobuf/3.19.4-GCCcore-11.3.0/include:/sw/installed/pybind11/2.9.2-GCCcore-11.3.0/include:/software/snappy/1.1.9-GCCcore-11.3.0/include:/sw/installed/SQLite/3.38.3-GCCcore-11.3.0/include:/sw/installed/zlib/1.2.12-GCCcore-11.3.0/include:/sw/installed/OpenSSL/1.1/include \
    LD_LIBRARY_PATH=/software/RE2/2022-06-01-GCCcore-11.3.0/lib:/software/snappy/1.1.9-GCCcore-11.3.0/lib:/sw/installed/libpng/1.6.37-GCCcore-11.3.0/lib:/software/nsync/1.25.0-GCCcore-11.3.0/lib:/sw/installed/libjpeg-turbo/2.1.3-GCCcore-11.3.0/lib:/software/JsonCpp/1.9.5-GCCcore-11.3.0/lib:/sw/installed/ICU/71.1-GCCcore-11.3.0/lib:/sw/installed/giflib/5.2.1-GCCcore-11.3.0/lib:/software/flatbuffers/2.0.7-GCCcore-11.3.0/lib:/software/double-conversion/3.2.0-GCCcore-11.3.0/lib:/sw/installed/HDF5/1.12.2-gompi-2022a/lib:/sw/installed/Szip/2.1.1-GCCcore-11.3.0/lib:/sw/installed/SciPy-bundle/2022.05-foss-2022a/lib/python3.10/site-packages/numpy/core/lib:/sw/installed/ScaLAPACK/2.2.0-gompi-2022a-fb/lib:/sw/installed/FFTW.MPI/3.3.10-gompi-2022a/lib:/sw/installed/FFTW/3.3.10-GCC-11.3.0/lib:/sw/installed/FlexiBLAS/3.2.0-GCC-11.3.0/lib:/sw/installed/OpenBLAS/0.3.20-GCC-11.3.0/lib:/sw/installed/OpenMPI/4.1.4-GCC-11.3.0/lib:/sw/installed/UCC/1.0.0-GCCcore-11.3.0/lib:/sw/installed/PMIx/4.1.2-GCCcore-11.3.0/lib:/sw/installed/libfabric/1.15.1-GCCcore-11.3.0/lib:/sw/installed/UCX/1.12.1-GCCcore-11.3.0/lib:/sw/installed/libevent/2.1.12-GCCcore-11.3.0/lib:/sw/installed/hwloc/2.7.1-GCCcore-11.3.0/lib:/sw/installed/libpciaccess/0.16-GCCcore-11.3.0/lib:/sw/installed/numactl/2.0.14-GCCcore-11.3.0/lib:/sw/installed/Python/3.10.4-GCCcore-11.3.0/lib:/sw/installed/libffi/3.4.2-GCCcore-11.3.0/lib64:/sw/installed/GMP/6.2.1-GCCcore-11.3.0/lib:/sw/installed/SQLite/3.38.3-GCCcore-11.3.0/lib:/sw/installed/Tcl/8.6.12-GCCcore-11.3.0/lib:/sw/installed/bzip2/1.0.8-GCCcore-11.3.0/lib:/sw/installed/binutils/2.38-GCCcore-11.3.0/lib:/sw/installed/DB/18.1.40-GCCcore-11.3.0/lib:/sw/installed/libreadline/8.1.2-GCCcore-11.3.0/lib:/sw/installed/gettext/0.21-GCCcore-11.3.0/lib:/sw/installed/ncurses/6.3-GCCcore-11.3.0/lib:/sw/installed/libxml2/2.9.13-GCCcore-11.3.0/lib:/sw/installed/XZ/5.2.5-GCCcore-11.3.0/lib:/sw/installed/expat/2.4.8-GCCcore-11.3.0/lib:/sw/installed/cURL/7.83.0-GCCcore-11.3.0/lib:/sw/installed/OpenSSL/1.1/lib:/sw/installed/zlib/1.2.12-GCCcore-11.3.0/lib:/software/protobuf/3.19.4-GCCcore-11.3.0/lib:/sw/installed/Java/11.0.6-ppc64le/lib:/sw/installed/GCCcore/11.3.0/lib64:/usr/local/cuda/lib64 \
    LIBRARY_PATH=/sw/installed/cURL/7.83.0-GCCcore-11.3.0/lib:/software/double-conversion/3.2.0-GCCcore-11.3.0/lib:/software/flatbuffers/2.0.7-GCCcore-11.3.0/lib:/sw/installed/giflib/5.2.1-GCCcore-11.3.0/lib:/sw/installed/hwloc/2.7.1-GCCcore-11.3.0/lib:/sw/installed/ICU/71.1-GCCcore-11.3.0/lib:/software/JsonCpp/1.9.5-GCCcore-11.3.0/lib:/sw/installed/libjpeg-turbo/2.1.3-GCCcore-11.3.0/lib:/sw/installed/libpng/1.6.37-GCCcore-11.3.0/lib:/software/nsync/1.25.0-GCCcore-11.3.0/lib:/software/protobuf/3.19.4-GCCcore-11.3.0/lib:/sw/installed/pybind11/2.9.2-GCCcore-11.3.0/lib:/software/snappy/1.1.9-GCCcore-11.3.0/lib:/sw/installed/SQLite/3.38.3-GCCcore-11.3.0/lib:/sw/installed/zlib/1.2.12-GCCcore-11.3.0/lib:/sw/installed/OpenSSL/1.1/lib \
    PATH=/sw/installed/libpng/1.6.37-GCCcore-11.3.0/bin:/sw/installed/libjpeg-turbo/2.1.3-GCCcore-11.3.0/bin:/sw/installed/NASM/2.15.05-GCCcore-11.3.0/bin:/sw/installed/ICU/71.1-GCCcore-11.3.0/sbin:/sw/installed/ICU/71.1-GCCcore-11.3.0/bin:/sw/installed/giflib/5.2.1-GCCcore-11.3.0/bin:/software/flatbuffers/2.0.7-GCCcore-11.3.0/bin:/software/dill/0.3.6-GCCcore-11.3.0/bin:/sw/installed/HDF5/1.12.2-gompi-2022a/bin:/sw/installed/SciPy-bundle/2022.05-foss-2022a/bin:/sw/installed/FFTW/3.3.10-GCC-11.3.0/bin:/sw/installed/FlexiBLAS/3.2.0-GCC-11.3.0/bin:/sw/installed/OpenMPI/4.1.4-GCC-11.3.0/bin:/sw/installed/UCC/1.0.0-GCCcore-11.3.0/bin:/sw/installed/PMIx/4.1.2-GCCcore-11.3.0/bin:/sw/installed/libfabric/1.15.1-GCCcore-11.3.0/bin:/sw/installed/UCX/1.12.1-GCCcore-11.3.0/bin:/sw/installed/libevent/2.1.12-GCCcore-11.3.0/bin:/sw/installed/hwloc/2.7.1-GCCcore-11.3.0/bin:/sw/installed/numactl/2.0.14-GCCcore-11.3.0/bin:/sw/installed/UnZip/6.0-GCCcore-11.3.0/bin:/sw/installed/pybind11/2.9.2-GCCcore-11.3.0/bin:/sw/installed/Python/3.10.4-GCCcore-11.3.0/bin:/sw/installed/SQLite/3.38.3-GCCcore-11.3.0/bin:/sw/installed/Tcl/8.6.12-GCCcore-11.3.0/bin:/sw/installed/bzip2/1.0.8-GCCcore-11.3.0/bin:/sw/installed/binutils/2.38-GCCcore-11.3.0/bin:/sw/installed/git/2.36.0-GCCcore-11.3.0-nodocs/bin:/sw/installed/Perl/5.34.1-GCCcore-11.3.0/bin:/sw/installed/DB/18.1.40-GCCcore-11.3.0/bin:/sw/installed/gettext/0.21-GCCcore-11.3.0/bin:/sw/installed/ncurses/6.3-GCCcore-11.3.0/bin:/sw/installed/libxml2/2.9.13-GCCcore-11.3.0/bin:/sw/installed/XZ/5.2.5-GCCcore-11.3.0/bin:/sw/installed/expat/2.4.8-GCCcore-11.3.0/bin:/sw/installed/cURL/7.83.0-GCCcore-11.3.0/bin:/sw/installed/OpenSSL/1.1/bin:/software/protobuf/3.19.4-GCCcore-11.3.0/bin:/software/Bazel/5.1.1-GCCcore-11.3.0/bin:/sw/installed/Java/11.0.6-ppc64le:/sw/installed/Java/11.0.6-ppc64le/bin:/sw/installed/GCCcore/11.3.0/bin:/home/s3248973/.local/EasyBuildDev/easybuild-framework:/home/s3248973/.yarn/bin:/home/s3248973/.config/yarn/global/node_modules/.bin:/home/s3248973/.local/bin:/usr/local/cuda/bin:/usr/lib64/qt-3.3/bin:/sw/taurus/tools/slurmtools/default/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/ibutils/bin:/opt/puppetlabs/bin \
    PYTHONNOUSERSITE=1 \
    PYTHONPATH=/software/TensorFlow/2.13.0-foss-2022a/lib/python3.10/site-packages:/software/TensorFlow/2.13.0-foss-2022a/lib/python3.10/site-packages:/software/protobuf-python/3.19.4-GCCcore-11.3.0/lib/python3.10/site-packages:/software/flatbuffers/2.0.7-GCCcore-11.3.0/lib/python3.10/site-packages:/software/dill/0.3.6-GCCcore-11.3.0/lib/python3.10/site-packages:/software/h5py/3.7.0-foss-2022a/lib/python3.10/site-packages:/sw/installed/SciPy-bundle/2022.05-foss-2022a/lib/python3.10/site-packages:/sw/installed/pybind11/2.9.2-GCCcore-11.3.0/lib/python3.10/site-packages:/sw/installed/Python/3.10.4-GCCcore-11.3.0/easybuild/python \
    PYTHON_BIN_PATH=/sw/installed/Python/3.10.4-GCCcore-11.3.0/bin/python \
    PYTHON_LIB_PATH=/software/TensorFlow/2.13.0-foss-2022a/lib/python3.10/site-packages \
    TF2_BEHAVIOR=1 \
    TF_SYSTEM_LIBS=absl_py,astor_archive,astunparse_archive,boringssl,com_google_protobuf,curl,cython,dill_archive,double_conversion,flatbuffers,functools32_archive,gast_archive,gif,hwloc,icu,jsoncpp_git,libjpeg_turbo,nasm,nsync,opt_einsum_archive,org_sqlite,pasta,png,pybind11,six_archive,snappy,tblib_archive,termcolor_archive,typing_extensions_archive,wrapt,zlib \
  /bin/bash -c 'bazel-out/ppc-opt/bin/tensorflow/create_tensorflow.python_api_tf_python_api_gen_v2 --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/ppc-opt/bin/tensorflow/_api/v2/ --apiname=tensorflow --apiversion=2  --compat_apiversion=1 --compat_apiversion=2  --compat_init_template=tensorflow/compat_template_v1.__init__.py --compat_init_template=tensorflow/compat_template.__init__.py --packages=tensorflow.python,tensorflow.dtensor.python.accelerator_util,tensorflow.dtensor.python.api,tensorflow.dtensor.python.config,tensorflow.dtensor.python.d_checkpoint,tensorflow.dtensor.python.d_variable,tensorflow.dtensor.python.input_util,tensorflow.dtensor.python.layout,tensorflow.dtensor.python.mesh_util,tensorflow.dtensor.python.tpu_util,tensorflow.dtensor.python.save_restore,tensorflow.lite.python.analyzer,tensorflow.lite.python.lite,tensorflow.lite.python.authoring.authoring,tensorflow.python.modules_with_exports --output_package=tensorflow._api.v2 --use_relative_imports=True --loading=default bazel-out/ppc-opt/bin/tensorflow/tf_python_api_gen_v2.params')
```