Tensorflow (MLIR) build fails with local LLVM (Support Library cannot be built, b/c/ llvm_zlib//:zlib and llvm_zstd//:zstd are missing)
Hi @FabianSchuetze ,

I think as per documentation the command is which is slight change wrt target.

```
bazel build --override_repository="llvm-raw=${LLVM_SRC}" \
  -c opt tensorflow/compiler/mlir:tf-opt
```

As per Bazel [documentation](https://bazel.build/run/build#specifying-build-targets), all target patterns starting with `//` are resolved relative to the current workspace.Target patterns that do not begin with `//` are resolved relative to the current working directory. 

Is that making difference here ? Could you try with exact command mentioned in documentation?

 Thanks for your reply, @SuryanarayanaY .

Your proposed solution did not help. In fact, the error is exactly as before:

```
ERROR: /home/fasc6540/.cache/bazel/_bazel_fasc6540/e5cce820cc082410b4fcc604db349066/external/llvm-project/llvm/BUILD.bazel:195:11: no such package '@llvm_zlib//': The repository '@llvm_zlib' could not be resolved: Repository '@llvm_zlib' is not defined and referenced by '@llvm-project//llvm:Support'
```

The problem is that it is not clear how to build @llvm_zlib//:zlib, and @llvm_zstd//:zstd cannot be build but are referenced by the `Support` library.  CC: @learning-to-play  I have been able to build tf-opt by removing the local llvm. bazel build -c opt //tensorflow/compiler/mlir:tf-opt > bazel build -c opt //tensorflow/compiler/mlir:tf-opt

This didn't work for me, I am getting this error.

```bash
ERROR: /tensorflow_src/tensorflow/core/common_runtime/BUILD:3386:11: Compiling tensorflow/core/common_runtime/optimized_function_graph_info.cc failed: (Exit 1): gcc failed: error executing command (from target //tensorflow/core/common_runtime:optimized_function_graph_info)
``` @FabianSchuetze Hi did you solve this problem? This could be a possible workaround?

https://github.com/tensorflow/tensorflow/issues/69367#issuecomment-2155693927
### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

01b930daff1e6437f813a2ceb2ee7bdb174babd3

### Custom code

Yes

### OS platform and distribution

Ubuntu 222.04

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

6.1.0

### GCC/compiler version

11.4.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I am following the [instructions](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/compiler/mlir/README.md) to build `mlir:tf-opt-opt` with a local LLVM copy and get have the following error:

```
➜  tensorflow git:(master) bazel build --override_repository="llvm-raw=${LLVM_SRC}" --config=dbg //tensorflow/compiler/mlir:tf-opt
INFO: Reading 'startup' options from /tmp/tensorflow/.bazelrc: --windows_enable_symlinks
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=104
INFO: Reading rc options for 'build' from /tmp/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /tmp/tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Found applicable config definition build:short_logs in file /tmp/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /tmp/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:dbg in file /tmp/tensorflow/.bazelrc: -c dbg --per_file_copt=+.*,-tensorflow.*,-xla.*@-g0 --per_file_copt=+tensorflow/core/kernels.*@-g0 --cxxopt -DTF_LITE_DISABLE_X86_NEON --copt -DDEBUG_BUILD
INFO: Found applicable config definition build:linux in file /tmp/tensorflow/.bazelrc: --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /tmp/tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
INFO: Repository com_googlesource_code_re2 instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:266:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository gif instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:331:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository stablehlo instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:911:28: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:88:14: in _initialize_third_party
  /tmp/tensorflow/third_party/stablehlo/workspace.bzl:11:20: in repo
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository onednn instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:197:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository riegeli instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:848:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
ERROR: /home/fasc6540/.cache/bazel/_bazel_fasc6540/e5cce820cc082410b4fcc604db349066/external/llvm-project/llvm/BUILD.bazel:195:11: no such package '@llvm_zlib//': The repository '@llvm_zlib' could not be resolved: Repository '@llvm_zlib' is not defined and referenced by '@llvm-project//llvm:Support'
ERROR: Analysis of target '//tensorflow/compiler/mlir:tf-opt' failed; build aborted: 
INFO: Elapsed time: 1.651s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (171 packages loaded, 5167 targets configured)
    currently loading: tensorflow/compiler/mlir/quantization/tensorflow/calibrator ... (3 packages)
    Fetching repository @ml_dtypes; starting
    Fetching repository @double_conversion; starting
    Fetching repository @snappy; starting
    Fetching .../e5cce820cc082410b4fcc604db349066/external/double_conversion; Extracting v3.2.0.tar.gz
    Fetching ...04db349066/external/snappy; Extracting 984b191f0fefdeb17050b42a90b7625999c13b8d.tar.gz
    Fetching repository @zlib; starting
    Fetching repository @jsoncpp_git; starting
    Fetching ...cc082410b4fcc604db349066/external/zlib; Extracting zlib-1.2.13.tar.gz ... (16 fetches)
```

Is there anything I can do to address the issue? 


### Standalone code to reproduce the issue

```shell
The steps I did to reproduce the issue are:


cd /tmp/
git clone https://github.com/tensorflow/tensorflow.git
git clone https://github.com/llvm/llvm-project.git 
export LLVM_SRC=/tmp/llvm-project/
touch ${LLVM_SRC}/BUILD.bazel ${LLVM_SRC}/WORKSPACE
bazel build --override_repository="llvm-raw=${LLVM_SRC}" --config=dbg //tensorflow/compiler/mlir:tf-opt
```
```


### Relevant log output

```shell
➜  tensorflow git:(master) bazel build --override_repository="llvm-raw=${LLVM_SRC}" --config=dbg //tensorflow/compiler/mlir:tf-opt
INFO: Reading 'startup' options from /tmp/tensorflow/.bazelrc: --windows_enable_symlinks
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=104
INFO: Reading rc options for 'build' from /tmp/tensorflow/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /tmp/tensorflow/.bazelrc:
  'build' options: --define framework_shared_object=true --define tsl_protobuf_header_only=true --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --features=-force_no_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --experimental_link_static_libraries_once=false --incompatible_enforce_config_setting_visibility
INFO: Found applicable config definition build:short_logs in file /tmp/tensorflow/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /tmp/tensorflow/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:dbg in file /tmp/tensorflow/.bazelrc: -c dbg --per_file_copt=+.*,-tensorflow.*,-xla.*@-g0 --per_file_copt=+tensorflow/core/kernels.*@-g0 --cxxopt -DTF_LITE_DISABLE_X86_NEON --copt -DDEBUG_BUILD
INFO: Found applicable config definition build:linux in file /tmp/tensorflow/.bazelrc: --host_copt=-w --copt=-Wno-all --copt=-Wno-extra --copt=-Wno-deprecated --copt=-Wno-deprecated-declarations --copt=-Wno-ignored-attributes --copt=-Wno-array-bounds --copt=-Wunused-result --copt=-Werror=unused-result --copt=-Wswitch --copt=-Werror=switch --copt=-Wno-error=unused-but-set-variable --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --config=dynamic_kernels --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /tmp/tensorflow/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
INFO: Repository com_googlesource_code_re2 instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:266:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository gif instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:331:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository stablehlo instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:911:28: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:88:14: in _initialize_third_party
  /tmp/tensorflow/third_party/stablehlo/workspace.bzl:11:20: in repo
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository onednn instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:197:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
INFO: Repository riegeli instantiated at:
  /tmp/tensorflow/WORKSPACE:84:14: in <toplevel>
  /tmp/tensorflow/tensorflow/workspace2.bzl:918:21: in workspace
  /tmp/tensorflow/tensorflow/workspace2.bzl:848:20: in _tf_repositories
  /tmp/tensorflow/third_party/repo.bzl:136:21: in tf_http_archive
Repository rule _tf_http_archive defined at:
  /tmp/tensorflow/third_party/repo.bzl:89:35: in <toplevel>
ERROR: /home/fasc6540/.cache/bazel/_bazel_fasc6540/e5cce820cc082410b4fcc604db349066/external/llvm-project/llvm/BUILD.bazel:195:11: no such package '@llvm_zlib//': The repository '@llvm_zlib' could not be resolved: Repository '@llvm_zlib' is not defined and referenced by '@llvm-project//llvm:Support'
ERROR: Analysis of target '//tensorflow/compiler/mlir:tf-opt' failed; build aborted: 
INFO: Elapsed time: 1.651s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (171 packages loaded, 5167 targets configured)
    currently loading: tensorflow/compiler/mlir/quantization/tensorflow/calibrator ... (3 packages)
    Fetching repository @ml_dtypes; starting
    Fetching repository @double_conversion; starting
    Fetching repository @snappy; starting
    Fetching .../e5cce820cc082410b4fcc604db349066/external/double_conversion; Extracting v3.2.0.tar.gz
    Fetching ...04db349066/external/snappy; Extracting 984b191f0fefdeb17050b42a90b7625999c13b8d.tar.gz
    Fetching repository @zlib; starting
    Fetching repository @jsoncpp_git; starting
    Fetching ...cc082410b4fcc604db349066/external/zlib; Extracting zlib-1.2.13.tar.gz ... (16 fetches)
```
