From 251c5421f6d8018cc07df9f6db3a6f25cb8a34e0 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Thu, 13 Jul 2023 02:51:29 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 547735699 --- mediapipe/BUILD | 151 ++++++++++++++++++++++++++++------------------ platform_mappings | 64 ++++++++++++++++++++ 2 files changed, 157 insertions(+), 58 deletions(-) create mode 100644 platform_mappings diff --git a/mediapipe/BUILD b/mediapipe/BUILD index fd0cbab36..41443c414 100644 --- a/mediapipe/BUILD +++ b/mediapipe/BUILD @@ -68,30 +68,108 @@ config_setting( visibility = ["//visibility:public"], ) -# Note: this cannot just match "apple_platform_type": "macos" because that option -# defaults to "macos" even when building on Linux! -alias( +# Generic MacOS. +config_setting( name = "macos", - actual = select({ - ":macos_i386": ":macos_i386", - ":macos_x86_64": ":macos_x86_64", - ":macos_arm64": ":macos_arm64", - "//conditions:default": ":macos_i386", # Arbitrarily chosen from above. - }), + constraint_values = [ + "@platforms//os:macos", + ], visibility = ["//visibility:public"], ) -# Note: this also matches on crosstool_top so that it does not produce ambiguous -# selectors when used together with "android". +# MacOS x86 64-bit. +config_setting( + name = "macos_x86_64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], + visibility = ["//visibility:public"], +) + +# MacOS ARM64. +config_setting( + name = "macos_arm64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:arm64", + ], + visibility = ["//visibility:public"], +) + +# Generic iOS. config_setting( name = "ios", - values = { - "crosstool_top": "@bazel_tools//tools/cpp:toolchain", - "apple_platform_type": "ios", - }, + constraint_values = [ + "@platforms//os:ios", + ], visibility = ["//visibility:public"], ) +# iOS device ARM32. +config_setting( + name = "ios_armv7", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:arm", + ], + visibility = ["//visibility:public"], +) + +# iOS device ARM64. +config_setting( + name = "ios_arm64", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:arm64", + ], + visibility = ["//visibility:public"], +) + +# iOS device ARM64E. +config_setting( + name = "ios_arm64e", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:arm64e", + ], + visibility = ["//visibility:public"], +) + +# iOS simulator x86 32-bit. +config_setting( + name = "ios_i386", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:x86_32", + "@build_bazel_apple_support//constraints:simulator", + ], + visibility = ["//visibility:public"], +) + +# iOS simulator x86 64-bit. +config_setting( + name = "ios_x86_64", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:x86_64", + "@build_bazel_apple_support//constraints:simulator", + ], + visibility = ["//visibility:public"], +) + +# iOS simulator ARM64. +config_setting( + name = "ios_sim_arm64", + constraint_values = [ + "@platforms//os:ios", + "@platforms//cpu:arm64", + "@build_bazel_apple_support//constraints:simulator", + ], + visibility = ["//visibility:public"], +) + +# Generic Apple. alias( name = "apple", actual = select({ @@ -102,49 +180,6 @@ alias( visibility = ["//visibility:public"], ) -config_setting( - name = "macos_i386", - values = { - "apple_platform_type": "macos", - "cpu": "darwin", - }, - visibility = ["//visibility:public"], -) - -config_setting( - name = "macos_x86_64", - values = { - "apple_platform_type": "macos", - "cpu": "darwin_x86_64", - }, - visibility = ["//visibility:public"], -) - -config_setting( - name = "macos_arm64", - values = { - "apple_platform_type": "macos", - "cpu": "darwin_arm64", - }, - visibility = ["//visibility:public"], -) - -[ - config_setting( - name = arch, - values = {"cpu": arch}, - visibility = ["//visibility:public"], - ) - for arch in [ - "ios_i386", - "ios_x86_64", - "ios_armv7", - "ios_arm64", - "ios_arm64e", - "ios_sim_arm64", - ] -] - config_setting( name = "windows", values = {"cpu": "x64_windows"}, diff --git a/platform_mappings b/platform_mappings new file mode 100644 index 000000000..cfe26f37b --- /dev/null +++ b/platform_mappings @@ -0,0 +1,64 @@ +# This file allows automatically mapping flags such as '--cpu' to the more +# modern Bazel platforms (https://bazel.build/concepts/platforms). + +# In particular, Bazel platforms lack support for Apple for now if no such +# mapping is put into place. It's inspired from: +# https://github.com/bazelbuild/rules_apple/issues/1764 + +platforms: + @build_bazel_apple_support//platforms:macos_x86_64 + --cpu=darwin_x86_64 + + @build_bazel_apple_support//platforms:macos_arm64 + --cpu=darwin_arm64 + + @build_bazel_apple_support//platforms:ios_i386 + --cpu=ios_i386 + + @build_bazel_apple_support//platforms:ios_x86_64 + --cpu=ios_x86_64 + + @build_bazel_apple_support//platforms:ios_sim_arm64 + --cpu=ios_sim_arm64 + + @build_bazel_apple_support//platforms:ios_armv7 + --cpu=ios_armv7 + + @build_bazel_apple_support//platforms:ios_arm64 + --cpu=ios_arm64 + + @build_bazel_apple_support//platforms:ios_arm64e + --cpu=ios_arm64e + +flags: + --cpu=darwin_x86_64 + --apple_platform_type=macos + @build_bazel_apple_support//platforms:macos_x86_64 + + --cpu=darwin_arm64 + --apple_platform_type=macos + @build_bazel_apple_support//platforms:macos_arm64 + + --cpu=ios_i386 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_i386 + + --cpu=ios_x86_64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_x86_64 + + --cpu=ios_sim_arm64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_sim_arm64 + + --cpu=ios_armv7 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_armv7 + + --cpu=ios_arm64 + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_arm64 + + --cpu=ios_arm64e + --apple_platform_type=ios + @build_bazel_apple_support//platforms:ios_arm64e