code: def main():
      global _TF_WORKSPACE_ROOT
      global _TF_BAZELRC
      global _TF_CURRENT_BAZEL_VERSION
  
      parser = argparse.ArgumentParser()
      parser.add_argument(
          "--workspace",
          type=str,
          default=os.path.abspath(os.path.dirname(__file__)),
          help="The absolute path to your active Bazel workspace.",
      )
      args = parser.parse_args()
  
      _TF_WORKSPACE_ROOT = args.workspace
      _TF_BAZELRC = os.path.join(
          _TF_WORKSPACE_ROOT, _TF_BAZELRC_FILENAME
      )
  
      # Make a copy of os.environ to be clear when functions and getting and setting
      # environment variables.
      environ_cp = dict(os.environ)
  
      try:
          current_bazel_version = retrieve_bazel_version()
      except subprocess.CalledProcessError as e:
          print(
              "Error retrieving bazel version: ",
              e.output.decode("UTF-8").strip(),
          )
          raise e
  
      _TF_CURRENT_BAZEL_VERSION = convert_version_to_int(
          current_bazel_version
      )
  
      reset_tf_configure_bazelrc()
  
      setup_python(environ_cp)
  
      if is_windows():
          environ_cp["TF_NEED_OPENCL"] = "0"
          environ_cp["TF_CUDA_CLANG"] = "0"
          # TODO(ibiryukov): Investigate using clang as a cpu or cuda compiler on
          # Windows.
          environ_cp["TF_DOWNLOAD_CLANG"] = "0"
          environ_cp["TF_NEED_MPI"] = "0"
  
      if is_ppc64le():
          # Enable MMA Dynamic Dispatch support if 'gcc' and if linker >= 2.35
          gcc_env = get_gcc_compiler(environ_cp)
          if gcc_env is not None:
              # Use gold linker if 'gcc' and if 'ppc64le'
              write_to_bazelrc('build --linkopt="-fuse-ld=gold"')
  
              # Get the linker version
              ld_version = run_shell([gcc_env, "-Wl,-version"]).split()
  
              ld_version_int = convert_version_to_int(ld_version[3])
              if ld_version_int is None:
                  ld_version_int = convert_version_to_int(ld_version[4])
  
              # Enable if 'ld' version >= 2.35
              if ld_version_int >= 2035000:
                  write_to_bazelrc(
                      'build --copt="-DEIGEN_ALTIVEC_ENABLE_MMA_DYNAMIC_DISPATCH=1"'
                  )
  
      set_action_env_var(
          environ_cp,
          "TF_NEED_ROCM",
          "ROCm",
          False,
          bazel_config_name="rocm",
      )
      if (
          environ_cp.get("TF_NEED_ROCM") == "1"
          and "LD_LIBRARY_PATH" in environ_cp
          and environ_cp.get("LD_LIBRARY_PATH") != "1"
      ):
          write_action_env_to_bazelrc(
              "LD_LIBRARY_PATH", environ_cp.get("LD_LIBRARY_PATH")
          )
  
      if environ_cp.get("TF_NEED_ROCM") == "1" and environ_cp.get(
          "ROCM_PATH"
      ):
          write_action_env_to_bazelrc(
              "ROCM_PATH", environ_cp.get("ROCM_PATH")
          )
  
      if environ_cp.get("TF_NEED_ROCM") == "1" and environ_cp.get(
          "HIP_PLATFORM"
      ):
          write_action_env_to_bazelrc(
              "HIP_PLATFORM", environ_cp.get("HIP_PLATFORM")
          )
  
      if is_windows():
          print(
              "\nWARNING: Cannot build with CUDA support on Windows.\n"
              "Starting in TF 2.11, CUDA build is not supported for Windows. "
              "For using XLA GPU on Windows, you will need to build/install "
              "XLA in WSL2.\n"
          )
          environ_cp["TF_NEED_CUDA"] = "0"
      else:
          environ_cp["TF_NEED_CUDA"] = str(
              int(get_var(environ_cp, "TF_NEED_CUDA", "CUDA", False))
          )
      if (
          environ_cp.get("TF_NEED_CUDA") == "1"
          and "TF_CUDA_CONFIG_REPO" not in environ_cp
      ):
          environ_save = dict(environ_cp)
          for _ in range(_DEFAULT_PROMPT_ASK_ATTEMPTS):
              if validate_cuda_config(environ_cp):
                  cuda_env_names = [
                      "TF_CUDA_VERSION",
                      "TF_CUBLAS_VERSION",
                      "TF_CUDNN_VERSION",
                      "TF_NCCL_VERSION",
                      "TF_CUDA_PATHS",
                      # Items below are for backwards compatibility when not using
                      # TF_CUDA_PATHS.
                      "CUDA_TOOLKIT_PATH",
                      "CUDNN_INSTALL_PATH",
                      "NCCL_INSTALL_PATH",
                      "NCCL_HDR_PATH",
                  ]
                  # Note: set_action_env_var above already writes to bazelrc.
                  for name in cuda_env_names:
                      if name in environ_cp:
                          write_action_env_to_bazelrc(
                              name, environ_cp[name]
                          )
                  break
  
              # Restore settings changed below if CUDA config could not be validated.
              environ_cp = dict(environ_save)
  
              set_tf_cuda_version(environ_cp)
              set_tf_cudnn_version(environ_cp)
              if is_linux():
                  set_tf_nccl_version(environ_cp)
  
              set_tf_cuda_paths(environ_cp)
  
          else:
              raise UserInputError(
                  "Invalid CUDA setting were provided %d "
                  "times in a row. Assuming to be a scripting mistake."
                  % _DEFAULT_PROMPT_ASK_ATTEMPTS
              )
  
          set_tf_cuda_compute_capabilities(environ_cp)
          if (
              "LD_LIBRARY_PATH" in environ_cp
              and environ_cp.get("LD_LIBRARY_PATH") != "1"
          ):
              write_action_env_to_bazelrc(
                  "LD_LIBRARY_PATH", environ_cp.get("LD_LIBRARY_PATH")
              )
  
          set_tf_cuda_clang(environ_cp)
          if environ_cp.get("TF_CUDA_CLANG") == "1":
              # Ask whether we should download the clang toolchain.
              set_tf_download_clang(environ_cp)
              if environ_cp.get("TF_DOWNLOAD_CLANG") != "1":
                  # Set up which clang we should use as the cuda / host compiler.
                  set_clang_cuda_compiler_path(environ_cp)
              else:
                  # Use downloaded LLD for linking.
                  write_to_bazelrc(
                      "build:cuda_clang --config=download_clang_use_lld"
                  )
          else:
              # Set up which gcc nvcc should use as the host compiler
              # No need to set this on Windows
              if not is_windows():
                  set_gcc_host_compiler_path(environ_cp)
          set_other_cuda_vars(environ_cp)
      else:
          # CUDA not required. Ask whether we should download the clang toolchain and
          # use it for the CPU build.
          set_tf_download_clang(environ_cp)
  
      # ROCm / CUDA are mutually exclusive.
      # At most 1 GPU platform can be configured.
      gpu_platform_count = 0
      if environ_cp.get("TF_NEED_ROCM") == "1":
          gpu_platform_count += 1
      if environ_cp.get("TF_NEED_CUDA") == "1":
          gpu_platform_count += 1
      if gpu_platform_count >= 2:
          raise UserInputError(
              "CUDA / ROCm are mututally exclusive. "
              "At most 1 GPU platform can be configured."
          )
  
      # Disable NCCL if XLA is configured for CPU
      if gpu_platform_count == 0:
          write_to_bazelrc("build --config=nonccl")
  
      set_cc_opt_flags(environ_cp)
      set_system_libs_flag(environ_cp)
      if is_windows():
          set_windows_build_flags()
  
      system_specific_test_config(environ_cp)
  
      print(
          "Preconfigured Bazel build configs. You can use any of the below by "
          'adding "--config=<>" to your build command. See .bazelrc for more '
          "details."
      )
      config_info_line("mkl", "Build with MKL support.")
      config_info_line(
          "mkl_aarch64",
          "Build with oneDNN and Compute Library for the Arm Architecture (ACL).",
      )
      config_info_line(
          "monolithic", "Config for mostly static monolithic build."
      )
      config_info_line("numa", "Build with NUMA support.")
      config_info_line(
          "dynamic_kernels",
          "(Experimental) Build kernels into separate shared objects.",
      )
      config_info_line(
          "v1", "Build with TensorFlow 1 API instead of TF 2 API."
      )
  
      print(
          "Preconfigured Bazel build configs to DISABLE default on features:"
      )
      config_info_line("nogcp", "Disable GCP support.")
  
      if gpu_platform_count == 1:
          config_info_line("nonccl", "Disable NVIDIA NCCL support.")
  
imports: import argparse
  import os
  import pathlib
  import platform
  import re
  import subprocess
  import sys
label_desc: Use image node_id 39 for calling a global function with example usage: main() without return types