From ef512f913b104f01464b36ddbc9a2f4f326196a6 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Wed, 16 Oct 2024 14:41:01 -0700 Subject: [PATCH] Internal PiperOrigin-RevId: 686647682 --- WORKSPACE | 97 +--- ..._multi_arch_split_with_new_transition.diff | 421 +++++++++++++++ .../org_tensorflow_c_api_experimental.diff | 97 ++++ third_party/org_tensorflow_system_python.diff | 510 ------------------ 4 files changed, 547 insertions(+), 578 deletions(-) create mode 100644 third_party/build_bazel_rules_apple_multi_arch_split_with_new_transition.diff create mode 100644 third_party/org_tensorflow_c_api_experimental.diff delete mode 100644 third_party/org_tensorflow_system_python.diff diff --git a/WORKSPACE b/WORKSPACE index bcf99a7ae1..36b19c4911 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -35,36 +35,12 @@ http_archive( sha256 = "f841f78243f179326f2a80b719f2887c38fe226d288ecdc46e2aa091e6aa43bc", ) -http_archive( - name = "rules_cc", - strip_prefix = "rules_cc-2f8c04c04462ab83c545ab14c0da68c3b4c96191", -# The commit can be updated if the build passes. Last updated 6/23/22. - urls = ["https://github.com/bazelbuild/rules_cc/archive/2f8c04c04462ab83c545ab14c0da68c3b4c96191.zip"], -) - -http_archive( - name = "rules_foreign_cc", - sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51", - strip_prefix = "rules_foreign_cc-0.9.0", - url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz", -) - -load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") - -rules_foreign_cc_dependencies() - http_archive( name = "rules_java", sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934", url = "https://github.com/bazelbuild/rules_java/releases/download/5.3.5/rules_java-5.3.5.tar.gz", ) -http_archive( - name = "rules_python", - sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b", - strip_prefix = "rules_python-0.26.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz", -) http_archive( name = "rules_android_ndk", @@ -75,6 +51,21 @@ http_archive( load("@rules_android_ndk//:rules.bzl", "android_ndk_repository") +http_archive( + name = "build_bazel_rules_apple", + sha256 = "3e2c7ae0ddd181c4053b6491dad1d01ae29011bc322ca87eea45957c76d3a0c3", + url = "https://github.com/bazelbuild/rules_apple/releases/download/2.1.0/rules_apple.2.1.0.tar.gz", + patches = [ + # Bypass checking ios unit test runner when building MP ios applications. + "@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff", + # https://github.com/bazelbuild/rules_apple/commit/95b1305255dc29874cacc3dc7fdc017f16d8dbe8 + "@//third_party:build_bazel_rules_apple_multi_arch_split_with_new_transition.diff" + ], + patch_args = [ + "-p1", + ], +) + http_archive( name = "com_google_protobuf", sha256 = "87407cd28e7a9c95d9f61a098a53cf031109d451a7763e7dd1253abf8b4df422", @@ -243,35 +234,6 @@ http_archive( url = "https://github.com/google/XNNPACK/archive/9007aa93227010168e615f9c6552035040c94a15.zip", ) - -# 2020-07-09 -http_archive( - name = "pybind11_bazel", - strip_prefix = "pybind11_bazel-203508e14aab7309892a1c5f7dd05debda22d9a5", - urls = ["https://github.com/pybind/pybind11_bazel/archive/203508e14aab7309892a1c5f7dd05debda22d9a5.zip"], - sha256 = "75922da3a1bdb417d820398eb03d4e9bd067c4905a4246d35a44c01d62154d91", -) - -# 2022-10-20 -http_archive( - name = "pybind11", - urls = [ - "https://github.com/pybind/pybind11/archive/v2.10.1.zip", - ], - sha256 = "fcf94065efcfd0a7a828bacf118fa11c43f6390d0c805e3e6342ac119f2e9976", - strip_prefix = "pybind11-2.10.1", - build_file = "@pybind11_bazel//:pybind11.BUILD", -) - -http_archive( - name = "pybind11_protobuf", - sha256 = "baa1f53568283630a5055c85f0898b8810f7a6431bd01bbaedd32b4c1defbcb1", - strip_prefix = "pybind11_protobuf-3594106f2df3d725e65015ffb4c7886d6eeee683", - urls = [ - "https://github.com/pybind/pybind11_protobuf/archive/3594106f2df3d725e65015ffb4c7886d6eeee683.tar.gz", - ], -) - # TF on 2024-09-24 _TENSORFLOW_GIT_COMMIT = "5329ec8dd396487982ef3e743f98c0195af39a6b" @@ -284,7 +246,7 @@ http_archive( "https://github.com/tensorflow/tensorflow/archive/%s.tar.gz" % _TENSORFLOW_GIT_COMMIT, ], patches = [ - "@//third_party:org_tensorflow_system_python.diff", + "@//third_party:org_tensorflow_c_api_experimental.diff", # Diff is generated with a script, don't update it manually. "@//third_party:org_tensorflow_custom_ops.diff", # Works around Bazel issue with objc_library. @@ -346,6 +308,19 @@ pip_parse( load("@model_maker_pip_deps//:requirements.bzl", mm_install_deps = "install_deps") mm_install_deps() +http_archive( + name = "rules_foreign_cc", + sha256 = "a2e6fb56e649c1ee79703e99aa0c9d13c6cc53c8d7a0cbb8797ab2888bbc99a3", + strip_prefix = "rules_foreign_cc-0.12.0", + url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.12.0/rules_foreign_cc-0.12.0.tar.gz", +) + +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") +rules_foreign_cc_dependencies() + +load("@bazel_features//:deps.bzl", "bazel_features_deps") +bazel_features_deps() + http_archive( name = "cpuinfo", sha256 = "2bf2b62eb86e2d2eaf862d0b9683a6c467a4d69fb2f7f1dc47c799809148608f", @@ -373,20 +348,6 @@ http_archive( urls = ["https://github.com/Maratyszcza/pthreadpool/archive/4fe0e1e183925bf8cfa6aae24237e724a96479b8.zip"], ) -# iOS basic build deps. -http_archive( - name = "build_bazel_rules_apple", - sha256 = "3e2c7ae0ddd181c4053b6491dad1d01ae29011bc322ca87eea45957c76d3a0c3", - url = "https://github.com/bazelbuild/rules_apple/releases/download/2.1.0/rules_apple.2.1.0.tar.gz", - patches = [ - # Bypass checking ios unit test runner when building MP ios applications. - "@//third_party:build_bazel_rules_apple_bypass_test_runner_check.diff" - ], - patch_args = [ - "-p1", - ], -) - load( "@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies", diff --git a/third_party/build_bazel_rules_apple_multi_arch_split_with_new_transition.diff b/third_party/build_bazel_rules_apple_multi_arch_split_with_new_transition.diff new file mode 100644 index 0000000000..d775daddc5 --- /dev/null +++ b/third_party/build_bazel_rules_apple_multi_arch_split_with_new_transition.diff @@ -0,0 +1,421 @@ +diff --git a/apple/internal/apple_universal_binary.bzl b/apple/internal/apple_universal_binary.bzl +index 664bdf6d..2c1971b2 100644 +--- a/apple/internal/apple_universal_binary.bzl ++++ b/apple/internal/apple_universal_binary.bzl +@@ -72,7 +72,7 @@ The `lipo` tool is used to combine built binaries of multiple architectures. + additional_attrs = { + "binary": attr.label( + mandatory = True, +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + doc = "Target to generate a 'fat' binary from.", + ), + "forced_cpus": attr.string_list( +diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl +index c51f3124..f7cab13b 100644 +--- a/apple/internal/rule_factory.bzl ++++ b/apple/internal/rule_factory.bzl +@@ -111,7 +111,7 @@ _COMMON_ATTRS = dicts.add( + apple_support.action_required_attrs(), + ) + +-def _common_linking_api_attrs(*, cfg = apple_common.multi_arch_split): ++def _common_linking_api_attrs(*, cfg = transition_support.apple_platform_split_transition): + """Returns dictionary of required attributes for Bazel Apple linking API's. + + These rule attributes are required by both Bazel Apple linking API's under apple_common module: +@@ -128,7 +128,7 @@ def _common_linking_api_attrs(*, cfg = apple_common.multi_arch_split): + ), + } + +-def _link_multi_arch_static_library_attrs(*, cfg = apple_common.multi_arch_split): ++def _link_multi_arch_static_library_attrs(*, cfg = transition_support.apple_platform_split_transition): + """Returns dictionary of required attributes for apple_common.link_multi_arch_static_library. + + Args: +@@ -136,7 +136,7 @@ def _link_multi_arch_static_library_attrs(*, cfg = apple_common.multi_arch_split + """ + return _common_linking_api_attrs(cfg = cfg) + +-def _link_multi_arch_binary_attrs(*, cfg = apple_common.multi_arch_split): ++def _link_multi_arch_binary_attrs(*, cfg = transition_support.apple_platform_split_transition): + """Returns dictionary of required attributes for apple_common.link_multi_arch_binary. + + Args: +@@ -163,7 +163,7 @@ def _link_multi_arch_binary_attrs(*, cfg = apple_common.multi_arch_split): + # apple_common.link_multi_arch_binary. + _J2OBJC_BINARY_LINKING_ATTRS = { + "_dummy_lib": attr.label( +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + default = Label("@bazel_tools//tools/objc:dummy_lib"), + ), + } +@@ -605,7 +605,7 @@ umbrella header will be generated under the same name as this target. + """, + ), + "avoid_deps": attr.label_list( +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + doc = """ + A list of library targets on which this framework depends in order to compile, but the transitive + closure of which will not be linked into the framework's binary. +@@ -908,7 +908,7 @@ umbrella header will be generated under the same name as this target. + """, + ), + "avoid_deps": attr.label_list( +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + doc = """ + A list of library targets on which this framework depends in order to compile, but the transitive + closure of which will not be linked into the framework's binary. +@@ -1045,7 +1045,7 @@ umbrella header will be generated under the same name as this target. + """, + ), + "avoid_deps": attr.label_list( +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + doc = """ + A list of library targets on which this framework depends in order to compile, but the transitive + closure of which will not be linked into the framework's binary. +@@ -1232,7 +1232,7 @@ binaries/libraries will be created combining all architectures specified by + is_executable = False + if require_linking_attrs: + rule_attrs.append(_common_binary_linking_attrs( +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = None, + )) + else: +diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl +index 0c8d1f37..38e00e81 100644 +--- a/apple/internal/rule_support.bzl ++++ b/apple/internal/rule_support.bzl +@@ -29,6 +29,10 @@ load( + "@build_bazel_rules_apple//apple/internal:bundle_package_type.bzl", + "bundle_package_type", + ) ++load( ++ "@build_bazel_rules_apple//apple/internal:transition_support.bzl", ++ "transition_support", ++) + + # Options to declare signing behavior and exceptions. + # +@@ -122,7 +126,7 @@ def _describe_rule_type( + default_test_runner: Default test runner to set in the runner attribute. Only used for + tests. + deps_cfg: The configuration for the deps attribute. This should be None for rules that use +- the apple_binary intermediate target, and apple_common.multi_arch_split for the rules ++ the apple_binary intermediate target, and transition_support.apple_platform_split_transition for the rules + that use the Starlark linking API. + expose_non_archive_relative_output: Whether or not to expose an output archive that ignores + the `archive_relative` bundle location, to permit embedding within another target. Has no +@@ -214,7 +218,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".app", + bundle_locations = _describe_bundle_locations(archive_relative = "Payload"), + bundle_package_type = bundle_package_type.application, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + has_alternate_icons = True, + has_launch_images = True, + has_settings_bundle = True, +@@ -238,7 +242,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".app", + bundle_locations = _describe_bundle_locations(archive_relative = "Payload"), + bundle_package_type = bundle_package_type.application, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + expose_non_archive_relative_output = True, + is_executable = True, + mandatory_families = True, +@@ -258,7 +262,7 @@ _RULE_TYPE_DESCRIPTORS = { + app_icon_extension = ".appiconset", + bundle_extension = ".appex", + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-fapplication-extension", + "-e", +@@ -280,7 +284,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".framework", + bundle_package_type = bundle_package_type.framework, + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + mandatory_families = True, + product_type = apple_product_type.framework, + rpaths = [ +@@ -317,7 +321,7 @@ _RULE_TYPE_DESCRIPTORS = { + app_icon_extension = ".stickersiconset", + bundle_extension = ".appex", + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-fapplication-extension", + "-e", +@@ -352,7 +356,7 @@ _RULE_TYPE_DESCRIPTORS = { + allowed_device_families = ["iphone", "ipad"], + bundle_extension = ".framework", + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + has_infoplist = False, + product_type = apple_product_type.static_framework, + requires_bundle_id = False, +@@ -365,7 +369,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:ios_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -388,7 +392,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:ios_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -415,7 +419,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".app", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.application, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + is_executable = True, + product_type = apple_product_type.application, + provisioning_profile_extension = ".provisionprofile", +@@ -431,7 +435,7 @@ _RULE_TYPE_DESCRIPTORS = { + apple_product_type.tool: _describe_rule_type( + allowed_device_families = ["mac"], + bundle_extension = "", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + is_executable = True, + product_type = apple_product_type.tool, + provisioning_profile_extension = ".provisionprofile", +@@ -442,7 +446,7 @@ _RULE_TYPE_DESCRIPTORS = { + apple_product_type.dylib: _describe_rule_type( + allowed_device_families = ["mac"], + bundle_extension = "", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.dylib, + requires_signing_for_device = False, + ), +@@ -455,7 +459,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".appex", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-fapplication-extension", + "-e", +@@ -480,7 +484,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".qlgenerator", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.quicklook_plugin, + provisioning_profile_extension = ".provisionprofile", + requires_deps = True, +@@ -494,7 +498,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".bundle", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.bundle, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.bundle, + provisioning_profile_extension = ".provisionprofile", + requires_signing_for_device = False, +@@ -512,7 +516,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".kext", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.kernel_extension, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + # This was added for b/122473338, and should be removed eventually once symbol + # stripping is better-handled. It's redundant with an option added in the CROSSTOOL + # for the "kernel_extension" feature, but for now it's necessary to detect kext +@@ -531,7 +535,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".mdimporter", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.spotlight_importer, + provisioning_profile_extension = ".provisionprofile", + requires_deps = True, +@@ -543,7 +547,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".xpc", + bundle_locations = _DEFAULT_MACOS_BUNDLE_LOCATIONS, + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.xpc_service, + provisioning_profile_extension = ".provisionprofile", + requires_deps = True, +@@ -564,7 +568,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:macos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -588,7 +592,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:macos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -616,7 +620,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".app", + bundle_locations = _describe_bundle_locations(archive_relative = "Payload"), + bundle_package_type = bundle_package_type.application, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + has_launch_images = True, + has_settings_bundle = True, + is_executable = True, +@@ -634,7 +638,7 @@ _RULE_TYPE_DESCRIPTORS = { + allows_locale_trimming = True, + bundle_extension = ".appex", + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-e", + "_TVExtensionMain", +@@ -657,7 +661,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".framework", + bundle_package_type = bundle_package_type.framework, + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.framework, + rpaths = [ + # Framework binaries live in +@@ -673,7 +677,7 @@ _RULE_TYPE_DESCRIPTORS = { + allowed_device_families = ["tv"], + bundle_extension = ".framework", + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + has_infoplist = False, + product_type = apple_product_type.static_framework, + requires_bundle_id = False, +@@ -686,7 +690,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:tvos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -709,7 +713,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:tvos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -747,7 +751,7 @@ _RULE_TYPE_DESCRIPTORS = { + allows_locale_trimming = True, + bundle_extension = ".appex", + bundle_package_type = bundle_package_type.extension_or_xpc, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-fapplication-extension", + ], +@@ -766,7 +770,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_extension = ".framework", + bundle_package_type = bundle_package_type.framework, + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + product_type = apple_product_type.framework, + rpaths = [ + # Framework binaries live in +@@ -782,7 +786,7 @@ _RULE_TYPE_DESCRIPTORS = { + allowed_device_families = ["watch"], + bundle_extension = ".framework", + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.skip_signing, +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + has_infoplist = False, + product_type = apple_product_type.static_framework, + requires_bundle_id = False, +@@ -795,7 +799,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:watchos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +@@ -818,7 +822,7 @@ _RULE_TYPE_DESCRIPTORS = { + bundle_package_type = bundle_package_type.bundle, + default_infoplist = "@build_bazel_rules_apple//apple/testing:DefaultTestBundlePlist", + default_test_runner = "@build_bazel_rules_apple//apple/testing/default_runner:watchos_default_runner", +- deps_cfg = apple_common.multi_arch_split, ++ deps_cfg = transition_support.apple_platform_split_transition, + extra_linkopts = [ + "-framework", + "XCTest", +diff --git a/apple/internal/testing/build_test_rules.bzl b/apple/internal/testing/build_test_rules.bzl +index 2e102ab7..e2de5203 100644 +--- a/apple/internal/testing/build_test_rules.bzl ++++ b/apple/internal/testing/build_test_rules.bzl +@@ -78,7 +78,7 @@ number (for example, `"9.0"`). + """, + ), + "targets": attr.label_list( +- cfg = apple_common.multi_arch_split, ++ cfg = transition_support.apple_platform_split_transition, + doc = "The targets to check for successful build.", + # Since `CcInfo` is the currency provider for rules that + # propagate libraries for linking to Apple bundles, this is +@@ -89,7 +89,7 @@ number (for example, `"9.0"`). + providers = [[CcInfo]], + ), + # This is a public attribute due to an implementation detail of +- # `apple_common.multi_arch_split`. The private attribute of the ++ # `transition_support.apple_platform_split_transition`. The private attribute of the + # same name is used in the implementation function to verify that + # the user has not modified it. + "platform_type": attr.string(default = platform_type), +diff --git a/apple/internal/transition_support.bzl b/apple/internal/transition_support.bzl +index 65f51b89..9c958ebe 100644 +--- a/apple/internal/transition_support.bzl ++++ b/apple/internal/transition_support.bzl +@@ -552,9 +552,9 @@ _apple_platform_split_transition = transition( + + # TODO(b/230527536): Add support for Bazel platforms on ios/tvos_static_framework transition support method + def _apple_common_multi_arch_split_key(*, cpu, environment, platform_type): +- """Returns split key for the apple_common.multi_arch_split transition based on target triplet. ++ """Returns split key for the transition_support.apple_platform_split_transition transition based on target triplet. + +- See ApplePlatform.cpuStringForTarget for reference on how apple_common.multi_arch_split ++ See ApplePlatform.cpuStringForTarget for reference on how transition_support.apple_platform_split_transition + transition key is built. + + Args: diff --git a/third_party/org_tensorflow_c_api_experimental.diff b/third_party/org_tensorflow_c_api_experimental.diff new file mode 100644 index 0000000000..6a98bb4e57 --- /dev/null +++ b/third_party/org_tensorflow_c_api_experimental.diff @@ -0,0 +1,97 @@ +diff --git a/tensorflow/lite/c/BUILD b/tensorflow/lite/c/BUILD +index 19cdd37ed4f..b4253b49a61 100644 +--- a/tensorflow/lite/c/BUILD ++++ b/tensorflow/lite/c/BUILD +@@ -119,10 +119,7 @@ cc_library_with_tflite_with_c_headers_test( + tflite_deps = [ + ":c_api", + ], +- deps = [ +- "//tensorflow/lite/core/c:c_api_experimental", +- "//tensorflow/lite/core/c:c_api_opaque", +- ], ++ deps = ["//tensorflow/lite/core/c:c_api_experimental"], + ) + + # Same as ":c_api_experimental", but without linking in the default CreateOpResolver implementation. +@@ -143,10 +140,7 @@ cc_library_with_tflite_with_c_headers_test( + tflite_deps = [ + ":c_api_without_op_resolver", + ], +- deps = [ +- "//tensorflow/lite/core/c:c_api_experimental_without_op_resolver", +- "//tensorflow/lite/core/c:c_api_opaque_without_op_resolver", +- ], ++ deps = ["//tensorflow/lite/core/c:c_api_experimental_without_op_resolver"], + ) + + # Same as ":c_api_experimental", but without linking in the default CreateOpResolver implementation, +@@ -183,6 +177,7 @@ cc_library_with_tflite_with_c_headers_test( + copts = tflite_copts() + tflite_copts_warnings(), + generate_opaque_delegate_target = True, + tflite_deps = [":c_api"], ++ linkstatic = 1, + deps = ["//tensorflow/lite/core/c:c_api_opaque"], + ) + +@@ -209,7 +204,7 @@ cc_library_with_tflite_with_c_headers_test( + tflite_deps = [ + ":c_api_without_op_resolver_without_alwayslink", + ], +- deps = ["//tensorflow/lite/core/c:c_api_opaque_without_op_resolver_without_alwayslink"], ++ deps = ["//tensorflow/lite/core/c:c_api_experimental_without_op_resolver_without_alwayslink"], + ) + + cc_library_with_tflite_with_c_headers_test( +@@ -457,7 +452,6 @@ cc_test( + ":c_api_experimental", + "//tensorflow/lite/core/c:c_api", + "//tensorflow/lite/core/c:c_api_experimental", +- "//tensorflow/lite/core/c:c_api_opaque", + "//tensorflow/lite/core/c:c_api_types", + "//tensorflow/lite/core/c:common", + ], +diff --git a/tensorflow/lite/core/c/BUILD b/tensorflow/lite/core/c/BUILD +index 018b6e1004c..cf355612386 100644 +--- a/tensorflow/lite/core/c/BUILD ++++ b/tensorflow/lite/core/c/BUILD +@@ -378,7 +378,6 @@ tflite_cc_library_with_c_headers_test( + deps = [ + ":c_api", + ":c_api_experimental_without_op_resolver", +- ":c_api_opaque", + ":c_api_types", + ":common", + ":operator", +@@ -399,6 +398,7 @@ tflite_cc_library_with_c_headers_test( + name = "c_api_experimental_without_op_resolver", + srcs = [ + "c_api_experimental.cc", ++ "c_api_opaque.cc", + ], + hdrs = [ + "c_api_experimental.h", +@@ -413,7 +413,6 @@ tflite_cc_library_with_c_headers_test( + copts = tflite_copts(), + tags = ["allow_undefined_symbols"], # For tflite::CreateOpResolver(). + deps = [ +- ":c_api_opaque_without_op_resolver", + ":c_api_types", + ":c_api_without_op_resolver", + ":common", +@@ -451,6 +450,7 @@ tflite_cc_library_with_c_headers_test( + name = "c_api_experimental_without_op_resolver_without_alwayslink", + srcs = [ + "c_api_experimental.cc", ++ "c_api_opaque.cc", + ], + hdrs = [ + "c_api_experimental.h", +@@ -467,7 +467,6 @@ tflite_cc_library_with_c_headers_test( + copts = tflite_copts(), + tags = ["allow_undefined_symbols"], # For tflite::CreateOpResolver(). + deps = [ +- ":c_api_opaque_without_op_resolver_without_alwayslink", + ":c_api_types", + ":c_api_without_op_resolver_without_alwayslink", + ":common", diff --git a/third_party/org_tensorflow_system_python.diff b/third_party/org_tensorflow_system_python.diff deleted file mode 100644 index a05c94b38f..0000000000 --- a/third_party/org_tensorflow_system_python.diff +++ /dev/null @@ -1,510 +0,0 @@ -diff --git a/tensorflow/lite/c/BUILD b/tensorflow/lite/c/BUILD -index 19cdd37ed4f..b4253b49a61 100644 ---- a/tensorflow/lite/c/BUILD -+++ b/tensorflow/lite/c/BUILD -@@ -119,10 +119,7 @@ cc_library_with_tflite_with_c_headers_test( - tflite_deps = [ - ":c_api", - ], -- deps = [ -- "//tensorflow/lite/core/c:c_api_experimental", -- "//tensorflow/lite/core/c:c_api_opaque", -- ], -+ deps = ["//tensorflow/lite/core/c:c_api_experimental"], - ) - - # Same as ":c_api_experimental", but without linking in the default CreateOpResolver implementation. -@@ -143,10 +140,7 @@ cc_library_with_tflite_with_c_headers_test( - tflite_deps = [ - ":c_api_without_op_resolver", - ], -- deps = [ -- "//tensorflow/lite/core/c:c_api_experimental_without_op_resolver", -- "//tensorflow/lite/core/c:c_api_opaque_without_op_resolver", -- ], -+ deps = ["//tensorflow/lite/core/c:c_api_experimental_without_op_resolver"], - ) - - # Same as ":c_api_experimental", but without linking in the default CreateOpResolver implementation, -@@ -183,6 +177,7 @@ cc_library_with_tflite_with_c_headers_test( - copts = tflite_copts() + tflite_copts_warnings(), - generate_opaque_delegate_target = True, - tflite_deps = [":c_api"], -+ linkstatic = 1, - deps = ["//tensorflow/lite/core/c:c_api_opaque"], - ) - -@@ -209,7 +204,7 @@ cc_library_with_tflite_with_c_headers_test( - tflite_deps = [ - ":c_api_without_op_resolver_without_alwayslink", - ], -- deps = ["//tensorflow/lite/core/c:c_api_opaque_without_op_resolver_without_alwayslink"], -+ deps = ["//tensorflow/lite/core/c:c_api_experimental_without_op_resolver_without_alwayslink"], - ) - - cc_library_with_tflite_with_c_headers_test( -@@ -457,7 +452,6 @@ cc_test( - ":c_api_experimental", - "//tensorflow/lite/core/c:c_api", - "//tensorflow/lite/core/c:c_api_experimental", -- "//tensorflow/lite/core/c:c_api_opaque", - "//tensorflow/lite/core/c:c_api_types", - "//tensorflow/lite/core/c:common", - ], -diff --git a/tensorflow/lite/core/c/BUILD b/tensorflow/lite/core/c/BUILD -index 018b6e1004c..cf355612386 100644 ---- a/tensorflow/lite/core/c/BUILD -+++ b/tensorflow/lite/core/c/BUILD -@@ -378,7 +378,6 @@ tflite_cc_library_with_c_headers_test( - deps = [ - ":c_api", - ":c_api_experimental_without_op_resolver", -- ":c_api_opaque", - ":c_api_types", - ":common", - ":operator", -@@ -399,6 +398,7 @@ tflite_cc_library_with_c_headers_test( - name = "c_api_experimental_without_op_resolver", - srcs = [ - "c_api_experimental.cc", -+ "c_api_opaque.cc", - ], - hdrs = [ - "c_api_experimental.h", -@@ -413,7 +413,6 @@ tflite_cc_library_with_c_headers_test( - copts = tflite_copts(), - tags = ["allow_undefined_symbols"], # For tflite::CreateOpResolver(). - deps = [ -- ":c_api_opaque_without_op_resolver", - ":c_api_types", - ":c_api_without_op_resolver", - ":common", -@@ -451,6 +450,7 @@ tflite_cc_library_with_c_headers_test( - name = "c_api_experimental_without_op_resolver_without_alwayslink", - srcs = [ - "c_api_experimental.cc", -+ "c_api_opaque.cc", - ], - hdrs = [ - "c_api_experimental.h", -@@ -467,7 +467,6 @@ tflite_cc_library_with_c_headers_test( - copts = tflite_copts(), - tags = ["allow_undefined_symbols"], # For tflite::CreateOpResolver(). - deps = [ -- ":c_api_opaque_without_op_resolver_without_alwayslink", - ":c_api_types", - ":c_api_without_op_resolver_without_alwayslink", - ":common", -diff --git a/third_party/py/non_hermetic/BUILD b/third_party/py/non_hermetic/BUILD -new file mode 100644 -index 00000000000..d14731cafcd ---- /dev/null -+++ b/third_party/py/non_hermetic/BUILD -@@ -0,0 +1,2 @@ -+# Empty BUILD file -+ -diff --git a/third_party/py/non_hermetic/BUILD.tpl b/third_party/py/non_hermetic/BUILD.tpl -new file mode 100644 -index 00000000000..0d2d06da29a ---- /dev/null -+++ b/third_party/py/non_hermetic/BUILD.tpl -@@ -0,0 +1,80 @@ -+licenses(["restricted"]) -+ -+package(default_visibility = ["//visibility:public"]) -+ -+# Point both runtimes to the same python binary to ensure we always -+# use the python binary specified by ./configure.py script. -+load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") -+ -+py_runtime( -+ name = "py2_runtime", -+ interpreter_path = "%{PYTHON_BIN_PATH}", -+ python_version = "PY2", -+) -+ -+py_runtime( -+ name = "py3_runtime", -+ interpreter_path = "%{PYTHON_BIN_PATH}", -+ python_version = "PY3", -+) -+ -+py_runtime_pair( -+ name = "py_runtime_pair", -+ py2_runtime = ":py2_runtime", -+ py3_runtime = ":py3_runtime", -+) -+ -+toolchain( -+ name = "py_toolchain", -+ toolchain = ":py_runtime_pair", -+ toolchain_type = "@bazel_tools//tools/python:toolchain_type", -+ target_compatible_with = [%{PLATFORM_CONSTRAINT}], -+ exec_compatible_with = [%{PLATFORM_CONSTRAINT}], -+) -+ -+# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib -+# See https://docs.python.org/3/extending/windows.html -+cc_import( -+ name = "python_lib", -+ interface_library = select({ -+ ":windows": ":python_import_lib", -+ # A placeholder for Unix platforms which makes --no_build happy. -+ "//conditions:default": "not-existing.lib", -+ }), -+ system_provided = 1, -+) -+ -+cc_library( -+ name = "python_headers", -+ hdrs = [":python_include"], -+ deps = select({ -+ ":windows": [":python_lib"], -+ "//conditions:default": [], -+ }), -+ includes = ["python_include"], -+) -+ -+# This alias is exists for the use of targets in the @llvm-project dependency, -+# which expect a python_headers target called @python_runtime//:headers. We use -+# a repo_mapping to alias python_runtime to this package, and an alias to create -+# the correct target. -+alias( -+ name = "headers", -+ actual = ":python_headers", -+) -+ -+cc_library( -+ name = "numpy_headers", -+ hdrs = [":numpy_include"], -+ includes = ["numpy_include"], -+) -+ -+config_setting( -+ name = "windows", -+ values = {"cpu": "x64_windows"}, -+ visibility = ["//visibility:public"], -+) -+ -+%{PYTHON_INCLUDE_GENRULE} -+%{NUMPY_INCLUDE_GENRULE} -+%{PYTHON_IMPORT_LIB_GENRULE} -diff --git a/third_party/py/non_hermetic/python_configure.bzl b/third_party/py/non_hermetic/python_configure.bzl -new file mode 100644 -index 00000000000..e6eeb02641a ---- /dev/null -+++ b/third_party/py/non_hermetic/python_configure.bzl -@@ -0,0 +1,313 @@ -+"""Repository rule for Python autoconfiguration. -+ -+`python_configure` depends on the following environment variables: -+ -+ * `PYTHON_BIN_PATH`: location of python binary. -+ * `PYTHON_LIB_PATH`: Location of python libraries. -+""" -+ -+load( -+ "//third_party/remote_config:common.bzl", -+ "BAZEL_SH", -+ "PYTHON_BIN_PATH", -+ "PYTHON_LIB_PATH", -+ "TF_PYTHON_CONFIG_REPO", -+ "auto_config_fail", -+ "config_repo_label", -+ "execute", -+ "get_bash_bin", -+ "get_host_environ", -+ "get_python_bin", -+ "is_windows", -+ "raw_exec", -+ "read_dir", -+) -+ -+def _genrule(src_dir, genrule_name, command, outs): -+ """Returns a string with a genrule. -+ -+ Genrule executes the given command and produces the given outputs. -+ """ -+ return ( -+ "genrule(\n" + -+ ' name = "' + -+ genrule_name + '",\n' + -+ " outs = [\n" + -+ outs + -+ "\n ],\n" + -+ ' cmd = """\n' + -+ command + -+ '\n """,\n' + -+ ")\n" -+ ) -+ -+def _norm_path(path): -+ """Returns a path with '/' and remove the trailing slash.""" -+ path = path.replace("\\", "/") -+ if path[-1] == "/": -+ path = path[:-1] -+ return path -+ -+def _symlink_genrule_for_dir( -+ repository_ctx, -+ src_dir, -+ dest_dir, -+ genrule_name, -+ src_files = [], -+ dest_files = []): -+ """Returns a genrule to symlink(or copy if on Windows) a set of files. -+ -+ If src_dir is passed, files will be read from the given directory; otherwise -+ we assume files are in src_files and dest_files -+ """ -+ if src_dir != None: -+ src_dir = _norm_path(src_dir) -+ dest_dir = _norm_path(dest_dir) -+ files = "\n".join(read_dir(repository_ctx, src_dir)) -+ -+ # Create a list with the src_dir stripped to use for outputs. -+ dest_files = files.replace(src_dir, "").splitlines() -+ src_files = files.splitlines() -+ command = [] -+ outs = [] -+ for i in range(len(dest_files)): -+ if dest_files[i] != "": -+ # If we have only one file to link we do not want to use the dest_dir, as -+ # $(@D) will include the full path to the file. -+ dest = "$(@D)/" + dest_dir + dest_files[i] if len(dest_files) != 1 else "$(@D)/" + dest_files[i] -+ -+ # Copy the headers to create a sandboxable setup. -+ cmd = "cp -f" -+ command.append(cmd + ' "%s" "%s"' % (src_files[i], dest)) -+ outs.append(' "' + dest_dir + dest_files[i] + '",') -+ genrule = _genrule( -+ src_dir, -+ genrule_name, -+ " && ".join(command), -+ "\n".join(outs), -+ ) -+ return genrule -+ -+def _get_python_lib(repository_ctx, python_bin): -+ """Gets the python lib path.""" -+ python_lib = get_host_environ(repository_ctx, PYTHON_LIB_PATH) -+ if python_lib != None: -+ return python_lib -+ -+ # The interesting program to execute. -+ print_lib = [ -+ "from __future__ import print_function", -+ "import site", -+ "import os", -+ "python_paths = []", -+ "if os.getenv('PYTHONPATH') is not None:", -+ " python_paths = os.getenv('PYTHONPATH').split(':')", -+ "try:", -+ " library_paths = site.getsitepackages()", -+ "except AttributeError:", -+ " from distutils.sysconfig import get_python_lib", -+ " library_paths = [get_python_lib()]", -+ "all_paths = set(python_paths + library_paths)", -+ "paths = []", -+ "for path in all_paths:", -+ " if os.path.isdir(path):", -+ " paths.append(path)", -+ "if len(paths) >=1:", -+ " print(paths[0])", -+ ] -+ -+ # The below script writes the above program to a file -+ # and executes it. This is to work around the limitation -+ # of not being able to upload files as part of execute. -+ cmd = "from os import linesep;" -+ cmd += "f = open('script.py', 'w');" -+ for line in print_lib: -+ cmd += "f.write(\"%s\" + linesep);" % line -+ cmd += "f.close();" -+ cmd += "from subprocess import call;" -+ cmd += "call([\"%s\", \"script.py\"]);" % python_bin -+ -+ result = execute(repository_ctx, [python_bin, "-c", cmd]) -+ return result.stdout.strip() -+ -+def _check_python_lib(repository_ctx, python_lib): -+ """Checks the python lib path.""" -+ cmd = 'test -d "%s" -a -x "%s"' % (python_lib, python_lib) -+ result = raw_exec(repository_ctx, [get_bash_bin(repository_ctx), "-c", cmd]) -+ if result.return_code == 1: -+ auto_config_fail("Invalid python library path: %s" % python_lib) -+ -+def _check_python_bin(repository_ctx, python_bin): -+ """Checks the python bin path.""" -+ cmd = '[[ -x "%s" ]] && [[ ! -d "%s" ]]' % (python_bin, python_bin) -+ result = raw_exec(repository_ctx, [get_bash_bin(repository_ctx), "-c", cmd]) -+ if result.return_code == 1: -+ auto_config_fail("--define %s='%s' is not executable. Is it the python binary?" % ( -+ PYTHON_BIN_PATH, -+ python_bin, -+ )) -+ -+def _get_python_include(repository_ctx, python_bin): -+ """Gets the python include path.""" -+ result = execute( -+ repository_ctx, -+ [ -+ python_bin, -+ "-Wignore", -+ "-c", -+ "import sysconfig; " + -+ "print(sysconfig.get_path('include'))", -+ ], -+ error_msg = "Problem getting python include path.", -+ error_details = ("Is the Python binary path set up right? " + -+ "(See ./configure or " + PYTHON_BIN_PATH + ".) " + -+ "Is distutils installed?"), -+ ) -+ return result.stdout.splitlines()[0] -+ -+def _get_python_import_lib_name(repository_ctx, python_bin): -+ """Get Python import library name (pythonXY.lib) on Windows.""" -+ result = execute( -+ repository_ctx, -+ [ -+ python_bin, -+ "-c", -+ "import sys;" + -+ 'print("python" + str(sys.version_info[0]) + ' + -+ ' str(sys.version_info[1]) + ".lib")', -+ ], -+ error_msg = "Problem getting python import library.", -+ error_details = ("Is the Python binary path set up right? " + -+ "(See ./configure or " + PYTHON_BIN_PATH + ".) "), -+ ) -+ return result.stdout.splitlines()[0] -+ -+def _get_numpy_include(repository_ctx, python_bin): -+ """Gets the numpy include path.""" -+ return execute( -+ repository_ctx, -+ [ -+ python_bin, -+ "-c", -+ "from __future__ import print_function;" + -+ "import numpy;" + -+ " print(numpy.get_include());", -+ ], -+ error_msg = "Problem getting numpy include path.", -+ error_details = "Is numpy installed?", -+ ).stdout.splitlines()[0] -+ -+def _create_local_python_repository(repository_ctx): -+ """Creates the repository containing files set up to build with Python.""" -+ -+ # Resolve all labels before doing any real work. Resolving causes the -+ # function to be restarted with all previous state being lost. This -+ # can easily lead to a O(n^2) runtime in the number of labels. -+ build_tpl = repository_ctx.path(Label("//third_party/py/non_hermetic:BUILD.tpl")) -+ -+ python_bin = get_python_bin(repository_ctx) -+ _check_python_bin(repository_ctx, python_bin) -+ python_lib = _get_python_lib(repository_ctx, python_bin) -+ _check_python_lib(repository_ctx, python_lib) -+ python_include = _get_python_include(repository_ctx, python_bin) -+ numpy_include = _get_numpy_include(repository_ctx, python_bin) + "/numpy" -+ python_include_rule = _symlink_genrule_for_dir( -+ repository_ctx, -+ python_include, -+ "python_include", -+ "python_include", -+ ) -+ python_import_lib_genrule = "" -+ -+ # To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib -+ # See https://docs.python.org/3/extending/windows.html -+ if is_windows(repository_ctx): -+ python_bin = python_bin.replace("\\", "/") -+ python_include = _norm_path(python_include) -+ python_import_lib_name = _get_python_import_lib_name(repository_ctx, python_bin) -+ python_import_lib_src = python_include.rsplit("/", 1)[0] + "/libs/" + python_import_lib_name -+ python_import_lib_genrule = _symlink_genrule_for_dir( -+ repository_ctx, -+ None, -+ "", -+ "python_import_lib", -+ [python_import_lib_src], -+ [python_import_lib_name], -+ ) -+ numpy_include_rule = _symlink_genrule_for_dir( -+ repository_ctx, -+ numpy_include, -+ "numpy_include/numpy", -+ "numpy_include", -+ ) -+ -+ platform_constraint = "" -+ if repository_ctx.attr.platform_constraint: -+ platform_constraint = "\"%s\"" % repository_ctx.attr.platform_constraint -+ repository_ctx.template("BUILD", build_tpl, { -+ "%{PYTHON_BIN_PATH}": python_bin, -+ "%{PYTHON_INCLUDE_GENRULE}": python_include_rule, -+ "%{PYTHON_IMPORT_LIB_GENRULE}": python_import_lib_genrule, -+ "%{NUMPY_INCLUDE_GENRULE}": numpy_include_rule, -+ "%{PLATFORM_CONSTRAINT}": platform_constraint, -+ }) -+ -+def _create_remote_python_repository(repository_ctx, remote_config_repo): -+ """Creates pointers to a remotely configured repo set up to build with Python. -+ """ -+ repository_ctx.template("BUILD", config_repo_label(remote_config_repo, ":BUILD"), {}) -+ -+def _python_autoconf_impl(repository_ctx): -+ """Implementation of the python_autoconf repository rule.""" -+ if get_host_environ(repository_ctx, TF_PYTHON_CONFIG_REPO) != None: -+ _create_remote_python_repository( -+ repository_ctx, -+ get_host_environ(repository_ctx, TF_PYTHON_CONFIG_REPO), -+ ) -+ else: -+ _create_local_python_repository(repository_ctx) -+ -+_ENVIRONS = [ -+ BAZEL_SH, -+ PYTHON_BIN_PATH, -+ PYTHON_LIB_PATH, -+] -+ -+local_python_configure = repository_rule( -+ implementation = _create_local_python_repository, -+ environ = _ENVIRONS, -+ attrs = { -+ "environ": attr.string_dict(), -+ "platform_constraint": attr.string(), -+ }, -+) -+ -+remote_python_configure = repository_rule( -+ implementation = _create_local_python_repository, -+ environ = _ENVIRONS, -+ remotable = True, -+ attrs = { -+ "environ": attr.string_dict(), -+ "platform_constraint": attr.string(), -+ }, -+) -+ -+python_configure = repository_rule( -+ implementation = _python_autoconf_impl, -+ environ = _ENVIRONS + [TF_PYTHON_CONFIG_REPO], -+ attrs = { -+ "platform_constraint": attr.string(), -+ }, -+) -+"""Detects and configures the local Python. -+ -+Add the following to your WORKSPACE FILE: -+ -+```python -+python_configure(name = "local_config_python") -+``` -+ -+Args: -+ name: A unique name for this workspace rule. -+""" -+