From 36d0f2e19430742d307215efb7088d09618db668 Mon Sep 17 00:00:00 2001 From: Christian Sigg <csigg@google.com> Date: Wed, 2 Dec 2020 23:52:23 -0800 Subject: [PATCH] Simplify initialization of bazel repositories that TensorFlow depends on. Repositories depending on TensorFlow should use the content of the WORKSPACE file to initialize TensorFlow and its dependencies. This will make it much less likely for us to break dependent projects when we add/change TensorFlow's dependencies. PiperOrigin-RevId: 345391447 Change-Id: Ia5f66a341247d0da491e40aee39f460ac10d5c9b --- WORKSPACE | 132 ++++---------------------------------- tensorflow/workspace.bzl | 3 +- tensorflow/workspace0.bzl | 78 ++++++++++++++++++++++ tensorflow/workspace1.bzl | 16 +++++ tensorflow/workspace2.bzl | 13 ++++ tensorflow/workspace3.bzl | 14 ++++ 6 files changed, 136 insertions(+), 120 deletions(-) create mode 100644 tensorflow/workspace0.bzl create mode 100644 tensorflow/workspace1.bzl create mode 100644 tensorflow/workspace2.bzl create mode 100644 tensorflow/workspace3.bzl diff --git a/WORKSPACE b/WORKSPACE index 9db1d9b80eb..4042cedcefd 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,124 +1,20 @@ workspace(name = "org_tensorflow") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +# Initialize the TensorFlow repository and all dependencies. +# +# The cascade of load() statements and workspace() calls works around the +# restriction that load() statements need to be at the top of .bzl files. +# E.g. we can not retrieve a new repository with http_archive and then load() +# a macro from that repository in the same file. +load("@//tensorflow:workspace3.bzl", "workspace") +workspace() +load("@//tensorflow:workspace2.bzl", "workspace") +workspace() +load("@//tensorflow:workspace1.bzl", "workspace") +workspace() +load("@//tensorflow:workspace0.bzl", "workspace") +workspace() -http_archive( - name = "io_bazel_rules_closure", - sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9", - strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", - "https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13 - ], -) -# Load tf_repositories() before loading dependencies for other repository so -# that dependencies like com_google_protobuf won't be overridden. -load("//tensorflow:workspace.bzl", "tf_repositories") -# Please add all new TensorFlow dependencies in workspace.bzl. -tf_repositories() -register_toolchains("@local_config_python//:py_toolchain") - -load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories") - -closure_repositories() - -load("//third_party/toolchains/preconfig/generate:archives.bzl", - "bazel_toolchains_archive") - -bazel_toolchains_archive() - -load( - "@bazel_toolchains//repositories:repositories.bzl", - bazel_toolchains_repositories = "repositories", -) - -bazel_toolchains_repositories() - -# Use `swift_rules_dependencies` to fetch the toolchains. With the -# `git_repository` rules above, the following call will skip redefining them. -load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") -swift_rules_dependencies() - -# We must check the bazel version before trying to parse any other BUILD -# files, in case the parsing of those build files depends on the bazel -# version we require here. -load("//tensorflow:version_check.bzl", "check_bazel_version_at_least") -check_bazel_version_at_least("1.0.0") - -load("//third_party/android:android_configure.bzl", "android_configure") -android_configure(name="local_config_android") -load("@local_config_android//:android.bzl", "android_workspace") -android_workspace() - -# If a target is bound twice, the later one wins, so we have to do tf bindings -# at the end of the WORKSPACE file. -load("//tensorflow:workspace.bzl", "tf_bind") -tf_bind() - -http_archive( - name = "inception_v1", - build_file = "//:models.BUILD", - sha256 = "7efe12a8363f09bc24d7b7a450304a15655a57a7751929b2c1593a71183bb105", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/models/inception_v1.zip", - ], -) - -http_archive( - name = "mobile_ssd", - build_file = "//:models.BUILD", - sha256 = "bddd81ea5c80a97adfac1c9f770e6f55cbafd7cce4d3bbe15fbeb041e6b8f3e8", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip", - ], -) - -http_archive( - name = "mobile_multibox", - build_file = "//:models.BUILD", - sha256 = "859edcddf84dddb974c36c36cfc1f74555148e9c9213dedacf1d6b613ad52b96", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/models/mobile_multibox_v1a.zip", - ], -) - -http_archive( - name = "stylize", - build_file = "//:models.BUILD", - sha256 = "3d374a730aef330424a356a8d4f04d8a54277c425e274ecb7d9c83aa912c6bfa", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/models/stylize_v1.zip", - ], -) - -http_archive( - name = "speech_commands", - build_file = "//:models.BUILD", - sha256 = "c3ec4fea3158eb111f1d932336351edfe8bd515bb6e87aad4f25dbad0a600d0c", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/models/speech_commands_v0.01.zip", - ], -) - -http_archive( - name = "person_detect_data", - sha256 = "170542270da256994ce24d1e357f6e84a54fdaf7d28ff2b74725a40b70b082cf", - urls = [ - "https://storage.googleapis.com/download.tensorflow.org/data/tf_lite_micro_person_data_grayscale_2020_05_24.zip", - ], -) - -# Required for dependency @com_github_grpc_grpc - -load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") -grpc_deps() - -load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") -grpc_extra_deps() - -load("//third_party/googleapis:repository_rules.bzl", "config_googleapis") - -config_googleapis() diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index 737883088de..1067193f40c 100755 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -69,8 +69,7 @@ def clean_dep(dep): return str(Label(dep)) # If TensorFlow is linked as a submodule. -# path_prefix is no longer used. -# tf_repo_name is thought to be under consideration. +# path_prefix and tf_repo_name are no longer used. def tf_workspace(path_prefix = "", tf_repo_name = ""): tf_repositories(path_prefix, tf_repo_name) tf_bind() diff --git a/tensorflow/workspace0.bzl b/tensorflow/workspace0.bzl new file mode 100644 index 00000000000..a6f3b0502f0 --- /dev/null +++ b/tensorflow/workspace0.bzl @@ -0,0 +1,78 @@ +"""TensorFlow workspace initialization. Consult the WORKSPACE on how to use it.""" + +load("//third_party/googleapis:repository_rules.bzl", "config_googleapis") +load("//tensorflow:workspace.bzl", "tf_bind") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_toolchains//repositories:repositories.bzl", bazel_toolchains_repositories = "repositories") +load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies") +load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") +load("@local_config_android//:android.bzl", "android_workspace") + +def workspace(): + http_archive( + name = "inception_v1", + build_file = "//:models.BUILD", + sha256 = "7efe12a8363f09bc24d7b7a450304a15655a57a7751929b2c1593a71183bb105", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/models/inception_v1.zip", + ], + ) + + http_archive( + name = "mobile_ssd", + build_file = "//:models.BUILD", + sha256 = "bddd81ea5c80a97adfac1c9f770e6f55cbafd7cce4d3bbe15fbeb041e6b8f3e8", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_android_export.zip", + ], + ) + + http_archive( + name = "mobile_multibox", + build_file = "//:models.BUILD", + sha256 = "859edcddf84dddb974c36c36cfc1f74555148e9c9213dedacf1d6b613ad52b96", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/models/mobile_multibox_v1a.zip", + ], + ) + + http_archive( + name = "stylize", + build_file = "//:models.BUILD", + sha256 = "3d374a730aef330424a356a8d4f04d8a54277c425e274ecb7d9c83aa912c6bfa", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/models/stylize_v1.zip", + ], + ) + + http_archive( + name = "speech_commands", + build_file = "//:models.BUILD", + sha256 = "c3ec4fea3158eb111f1d932336351edfe8bd515bb6e87aad4f25dbad0a600d0c", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/models/speech_commands_v0.01.zip", + ], + ) + + http_archive( + name = "person_detect_data", + sha256 = "170542270da256994ce24d1e357f6e84a54fdaf7d28ff2b74725a40b70b082cf", + urls = [ + "https://storage.googleapis.com/download.tensorflow.org/data/tf_lite_micro_person_data_grayscale_2020_05_24.zip", + ], + ) + + bazel_toolchains_repositories() + + # Use `swift_rules_dependencies` to fetch the toolchains. With the + # `git_repository` rules above, the following call will skip redefining them. + swift_rules_dependencies() + + android_workspace() + + # If a target is bound twice, the later one wins, so we have to do tf bindings + # at the end of the WORKSPACE file. + tf_bind() + + grpc_extra_deps() + config_googleapis() diff --git a/tensorflow/workspace1.bzl b/tensorflow/workspace1.bzl new file mode 100644 index 00000000000..76609b83079 --- /dev/null +++ b/tensorflow/workspace1.bzl @@ -0,0 +1,16 @@ +"""TensorFlow workspace initialization. Consult the WORKSPACE on how to use it.""" + +load("//third_party/android:android_configure.bzl", "android_configure") +load("//third_party/toolchains/preconfig/generate:archives.bzl", "bazel_toolchains_archive") +load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") +load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories") + +def workspace(): + native.register_toolchains("@local_config_python//:py_toolchain") + + closure_repositories() + bazel_toolchains_archive() + + android_configure(name = "local_config_android") + + grpc_deps() diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl new file mode 100644 index 00000000000..9b628866543 --- /dev/null +++ b/tensorflow/workspace2.bzl @@ -0,0 +1,13 @@ +"""TensorFlow workspace initialization. Consult the WORKSPACE on how to use it.""" + +load("//tensorflow:version_check.bzl", "check_bazel_version_at_least") +load("//tensorflow:workspace.bzl", "tf_repositories") + +def workspace(): + # Check the bazel version before executing any repository rules, in case + # 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. + tf_repositories() diff --git a/tensorflow/workspace3.bzl b/tensorflow/workspace3.bzl new file mode 100644 index 00000000000..03364c8001e --- /dev/null +++ b/tensorflow/workspace3.bzl @@ -0,0 +1,14 @@ +"""TensorFlow workspace initialization. Consult the WORKSPACE on how to use it.""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def workspace(): + http_archive( + name = "io_bazel_rules_closure", + sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9", + strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", + "https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13 + ], + )