1# Copyright 2018 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15_PLATFORMS = { 16 "armv7-apple-ios": (apple_common.platform.ios_device, apple_common.platform_type.ios), 17 "armv7-apple-tvos": (apple_common.platform.tvos_device, apple_common.platform_type.tvos), 18 "armv7k-apple-watchos": (apple_common.platform.watchos_device, apple_common.platform_type.watchos), 19 "arm64-apple-ios": (apple_common.platform.ios_device, apple_common.platform_type.ios), 20 "arm64-apple-tvos": (apple_common.platform.tvos_device, apple_common.platform_type.tvos), 21 "i386-apple-ios": (apple_common.platform.ios_simulator, apple_common.platform_type.ios), 22 "i386-apple-tvos": (apple_common.platform.tvos_simulator, apple_common.platform_type.tvos), 23 "i386-apple-watchos": (apple_common.platform.watchos_simulator, apple_common.platform_type.watchos), 24 "x86_64-apple-ios": (apple_common.platform.ios_simulator, apple_common.platform_type.ios), 25 "x86_64-apple-tvos": (apple_common.platform.ios_simulator, apple_common.platform_type.tvos), 26 "x86_64-apple-watchos": (apple_common.platform.watchos_simulator, apple_common.platform_type.watchos), 27} 28 29def _apple_version_min(ctx, platform, platform_type): 30 xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig] 31 min_os = str(xcode_config.minimum_os_for_platform_type(platform_type)) 32 return "-m{}-version-min={}".format(platform.name_in_plist.lower(), min_os) 33 34def _apple_env(ctx, platform): 35 xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig] 36 return apple_common.target_apple_env(xcode_config, platform) 37 38def apple_ensure_options(ctx, env, _tags, compiler_option_lists, linker_option_lists, target_gnu_system_name): 39 """Returns environment, flags, and Go tags for Apple targets.""" 40 platform, platform_type = _PLATFORMS.get(target_gnu_system_name, (None, None)) 41 if not platform: 42 return 43 env.update(_apple_env(ctx, platform)) 44 min_version = _apple_version_min(ctx, platform, platform_type) 45 for compiler_options in compiler_option_lists: 46 compiler_options.append(min_version) 47 for linker_options in linker_option_lists: 48 linker_options.append(min_version) 49