Skip to content

Commit

Permalink
When calculating the target triple for 'arm64-apple-ios<version>-simu…
Browse files Browse the repository at this point in the history
…lator' targets, correctly specify the minimum supported OS.

Precompiled pcm files will be generated with the target triple, however the minimum supported version for arm64 on an ios-simulator is 14.0. Any minimum OS under 14 will be raised to 14 by the swift driver and clang tools. This logic is not applied to the AST serialized into pcm object files. To ensure the AST is correctly specified, adjust the target triple to configure the lower bounds correctly.

PiperOrigin-RevId: 458248769
  • Loading branch information
ashgti authored and swiple-rules-gardener committed Jun 30, 2022
1 parent 912d40d commit b100c3f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions swift/internal/target_triples.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

"""Utility functions to inspect and manipulate target triples."""

_IOS_SIM_ARM64_MIN_OS_VERSION = apple_common.dotted_version("14.0")

def _make(*, cpu, vendor, os, environment = None):
"""Creates a target triple struct from the given values.
Expand Down Expand Up @@ -102,12 +104,27 @@ def _normalize_for_swift(triple, *, unversioned = False):
A target triple struct containing the normalized triple.
"""
os = _normalize_apple_os(triple.os, unversioned = unversioned)

if os.startswith(("ios", "macos", "tvos", "watchos")):
environment = _normalize_apple_environment(triple.environment)
cpu = _normalize_apple_cpu(triple.cpu)

# If the target triple is like `arm64-apple-ios<version>-simulator` and
# version is <14, raise the min version to 14 to match the first
# supported simulator version. Based on
# `getSwiftRuntimeCompatibilityVersionForTarget` from
# https://github.com/apple/swift/blob/main/lib/Basic/Platform.cpp
if os.startswith("ios") and cpu == "arm64" and environment == "simulator":
os_name, version = _split_os_version(os)
target_version = apple_common.dotted_version(version)
if target_version.compare_to(_IOS_SIM_ARM64_MIN_OS_VERSION) == -1:
version = "14.0"
os = os_name + version
return _make(
cpu = _normalize_apple_cpu(triple.cpu),
cpu = cpu,
vendor = "apple",
os = os,
environment = _normalize_apple_environment(triple.environment),
environment = environment,
)

return triple
Expand Down

1 comment on commit b100c3f

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.