From d53a69801a98109fd7b8e35fcfaeee534215d593 Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Mon, 1 Mar 2021 10:09:20 -0800 Subject: [PATCH] Polishing touches to workspace macros. PiperOrigin-RevId: 360217268 Change-Id: I8d47c8e34e116f16011c48181f0487db48f86da8 --- tensorflow/workspace2.bzl | 52 +++++++++++++++--------------- third_party/absl/workspace.bzl | 4 +-- third_party/eigen3/workspace.bzl | 4 +-- third_party/farmhash/workspace.bzl | 4 +-- third_party/gemmlowp/workspace.bzl | 4 +-- third_party/ortools/BUILD | 1 - third_party/ortools/BUILD.bazel | 13 -------- third_party/ortools/workspace.bzl | 15 --------- 8 files changed, 34 insertions(+), 63 deletions(-) delete mode 100644 third_party/ortools/BUILD delete mode 100644 third_party/ortools/BUILD.bazel delete mode 100644 third_party/ortools/workspace.bzl diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl index 8907896b0ec..ac61a93b6ef 100644 --- a/tensorflow/workspace2.bzl +++ b/tensorflow/workspace2.bzl @@ -1,5 +1,6 @@ """TensorFlow workspace initialization. Consult the WORKSPACE on how to use it.""" +# Import third party config rules. load("//tensorflow:version_check.bzl", "check_bazel_version_at_least") load("//third_party/gpus:cuda_configure.bzl", "cuda_configure") load("//third_party/gpus:rocm_configure.bzl", "rocm_configure") @@ -15,6 +16,8 @@ load("//third_party/toolchains/embedded/arm-linux:arm_linux_toolchain_configure. load("//third_party:repo.bzl", "tf_http_archive") load("//third_party/clang_toolchain:cc_configure_clang.bzl", "cc_download_clang_toolchain") load("//tensorflow/tools/def_file_filter:def_file_filter_configure.bzl", "def_file_filter_configure") + +# Import third party repository rules. See go/tfbr-thirdparty. load("//third_party/FP16:workspace.bzl", FP16 = "repo") load("//third_party/absl:workspace.bzl", absl = "repo") load("//third_party/aws:workspace.bzl", aws = "repo") @@ -39,6 +42,8 @@ load("//third_party/psimd:workspace.bzl", psimd = "repo") load("//third_party/ruy:workspace.bzl", ruy = "repo") load("//third_party/sobol_data:workspace.bzl", sobol_data = "repo") load("//third_party/vulkan_headers:workspace.bzl", vulkan_headers = "repo") + +# Import external repository rules. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external") load("@io_bazel_rules_closure//closure:defs.bzl", "filegroup_external") @@ -47,42 +52,34 @@ load("@tf_toolchains//toolchains/remote_config:configs.bzl", "initialize_rbe_con def _initialize_third_party(): """ Load third party repositories. See above load() statements. """ FP16() + absl() aws() clog() cpuinfo() dlpack() + eigen3() + farmhash() flatbuffers() + gemmlowp() hexagon_nn() highwayhash() hwloc() icu() - kissfft() jpeg() + kissfft() nasm() opencl_headers() pasta() psimd() + ruy() sobol_data() vulkan_headers() - ruy() - -# Sanitize a dependency so that it works correctly from code that includes -# TensorFlow as a submodule. -def _clean_dep(dep): - return str(Label(dep)) # Toolchains & platforms required by Tensorflow to build. def _tf_toolchains(): native.register_execution_platforms("@local_execution_config_platform//:platform") native.register_toolchains("@local_execution_config_python//:py_toolchain") -# Define all external repositories required by TensorFlow -def _tf_repositories(): - """All external dependencies for TF builds.""" - - # Initialize toolchains and platforms. - _tf_toolchains() - # Loads all external repos to configure RBE builds. initialize_rbe_configs() @@ -98,8 +95,6 @@ def _tf_repositories(): rocm_configure(name = "local_config_rocm") remote_execution_configure(name = "local_config_remote_execution") - _initialize_third_party() - # For windows bazel build # TODO: Remove def file filter when TensorFlow can export symbols properly on Windows. def_file_filter_configure(name = "local_config_def_file_filter") @@ -120,6 +115,10 @@ def _tf_repositories(): armhf_repo = "../armhf_linux_toolchain", ) +# Define all external repositories required by TensorFlow +def _tf_repositories(): + """All external dependencies for TF builds.""" + # To update any of the dependencies bellow: # a) update URL and strip_prefix to the new git commit hash # b) get the sha256 hash of the commit by running: @@ -177,10 +176,6 @@ def _tf_repositories(): ], ) - absl("com_google_absl") - - eigen3(name = "eigen_archive") - tf_http_archive( name = "arm_compiler", build_file = "//:arm_compiler.BUILD", @@ -300,10 +295,6 @@ def _tf_repositories(): ], ) - gemmlowp("gemmlowp") - - farmhash("farmhash_archive") - tf_http_archive( name = "png", build_file = "//third_party:png.BUILD", @@ -1078,8 +1069,17 @@ def workspace(): # those rules rely on the version we require here. check_bazel_version_at_least("1.0.0") - # Load tf_repositories() before loading dependencies for other repository so - # that dependencies like com_google_protobuf won't be overridden. + # Initialize toolchains and platforms. + _tf_toolchains() + + # Import third party repositories according to go/tfbr-thirdparty. + _initialize_third_party() + + # Import all other repositories. This should happen before initializing + # any external repositories, because those come with their own + # dependencies. Those recursive dependencies will only be imported if they + # don't already exist (at least if the external repository macros were + # written according to common practice to query native.existing_rule()). _tf_repositories() # Alias so it can be loaded without assigning to a different symbol to prevent diff --git a/third_party/absl/workspace.bzl b/third_party/absl/workspace.bzl index e1987f475c3..a6ab27b33bf 100644 --- a/third_party/absl/workspace.bzl +++ b/third_party/absl/workspace.bzl @@ -2,7 +2,7 @@ load("//third_party:repo.bzl", "tf_http_archive") -def repo(name): +def repo(): """Imports absl.""" # Attention: tools parse and update these lines. @@ -10,7 +10,7 @@ def repo(name): ABSL_SHA256 = "f368a8476f4e2e0eccf8a7318b98dafbe30b2600f4e3cf52636e5eb145aba06a" tf_http_archive( - name = name, + name = "com_google_absl", sha256 = ABSL_SHA256, build_file = "//third_party/absl:com_google_absl.BUILD", # TODO: Remove the patch when https://github.com/abseil/abseil-cpp/issues/326 is resolved diff --git a/third_party/eigen3/workspace.bzl b/third_party/eigen3/workspace.bzl index 96dc3fc4f3a..b4d4b9b7686 100644 --- a/third_party/eigen3/workspace.bzl +++ b/third_party/eigen3/workspace.bzl @@ -2,7 +2,7 @@ load("//third_party:repo.bzl", "tf_http_archive") -def repo(name): +def repo(): """Imports Eigen.""" # Attention: tools parse and update these lines. @@ -10,7 +10,7 @@ def repo(name): EIGEN_SHA256 = "6ae281a5a32d0f4185856e790c06f58858ffc16594483281621746ffb74d88a2" tf_http_archive( - name = name, + name = "eigen_archive", build_file = "//third_party/eigen3:eigen_archive.BUILD", sha256 = EIGEN_SHA256, strip_prefix = "eigen-{commit}".format(commit = EIGEN_COMMIT), diff --git a/third_party/farmhash/workspace.bzl b/third_party/farmhash/workspace.bzl index a15ae663cd2..f72fb746949 100644 --- a/third_party/farmhash/workspace.bzl +++ b/third_party/farmhash/workspace.bzl @@ -2,7 +2,7 @@ load("//third_party:repo.bzl", "tf_http_archive") -def repo(name): +def repo(): """Imports farmhash.""" # Attention: tools parse and update these lines. @@ -10,7 +10,7 @@ def repo(name): FARMHASH_SHA256 = "6560547c63e4af82b0f202cb710ceabb3f21347a4b996db565a411da5b17aba0" tf_http_archive( - name = name, + name = "farmhash_archive", build_file = "//third_party/farmhash:farmhash.BUILD", sha256 = FARMHASH_SHA256, strip_prefix = "farmhash-{commit}".format(commit = FARMHASH_COMMIT), diff --git a/third_party/gemmlowp/workspace.bzl b/third_party/gemmlowp/workspace.bzl index 7b71e43e6dd..da53dfcb745 100644 --- a/third_party/gemmlowp/workspace.bzl +++ b/third_party/gemmlowp/workspace.bzl @@ -2,7 +2,7 @@ load("//third_party:repo.bzl", "tf_http_archive") -def repo(name): +def repo(): """Imports gemmlowp.""" # Attention: tools parse and update these lines. @@ -10,7 +10,7 @@ def repo(name): GEMMLOWP_SHA256 = "43146e6f56cb5218a8caaab6b5d1601a083f1f31c06ff474a4378a7d35be9cfb" tf_http_archive( - name = name, + name = "gemmlowp", sha256 = GEMMLOWP_SHA256, strip_prefix = "gemmlowp-{commit}".format(commit = GEMMLOWP_COMMIT), urls = [ diff --git a/third_party/ortools/BUILD b/third_party/ortools/BUILD deleted file mode 100644 index 2f5d02becb9..00000000000 --- a/third_party/ortools/BUILD +++ /dev/null @@ -1 +0,0 @@ -# Dummy BUILD file to make this directory a package. diff --git a/third_party/ortools/BUILD.bazel b/third_party/ortools/BUILD.bazel deleted file mode 100644 index 61191e3d271..00000000000 --- a/third_party/ortools/BUILD.bazel +++ /dev/null @@ -1,13 +0,0 @@ -# Google's software suite for combinatorial optimization - -licenses(["notice"]) # Apache2 license - -exports_files(["LICENSE-2.0.txt"]) - -native.cc_library( - name = "linear_solver_glop", - deps = [ - "@ortools_archive//linear_solver:linear_solver_glop", - ], - visibility = ["//visibility:public"], -) diff --git a/third_party/ortools/workspace.bzl b/third_party/ortools/workspace.bzl deleted file mode 100644 index 42eb122f7a6..00000000000 --- a/third_party/ortools/workspace.bzl +++ /dev/null @@ -1,15 +0,0 @@ -"""loads the aws library, used by TF.""" - -load("//third_party:repo.bzl", "tf_http_archive") - -def repo(): - tf_http_archive( - name = "ortools_archive", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/or-tools/archive/v6.7.2.tar.gz", - "https://github.com/google/or-tools/archive/v6.7.2.tar.gz", - ], - sha256 = "d025a95f78b5fc5eaa4da5f395f23d11c23cf7dbd5069f1f627f002de87b86b9", - strip_prefix = "or-tools-6.7.2/src", - build_file = "//third_party/ortools:BUILD.bazel", - )