1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174

build / config / mac / mac_sdk.gni [blame]

# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chrome_build.gni")
import("//build/config/gclient_args.gni")
import("//build/config/mac/mac_sdk_overrides.gni")
import("//build/toolchain/rbe.gni")
import("//build/toolchain/siso.gni")
import("//build/toolchain/toolchain.gni")

# Allow Android builds on macOS
assert(current_os == "mac" || current_toolchain == default_toolchain ||
       target_os == "android")

declare_args() {
  # The following two variables control the minimum supported version for
  # macOS:
  #
  # This variable affects how Chromium is compiled and corresponds to the
  # `MACOSX_DEPLOYMENT_TARGET` define. Changing this controls which symbols
  # the macOS SDK marks as available (via `__builtin_available` and
  # `@available`) and deprecated (producing a warning if called). Modifying
  # this variable often requires additional code changes to handle differences
  # in availability and deprecation, which is why it is often changed
  # separately from `mac_min_system_version` when dropping support for older
  # macOSes.
  mac_deployment_target = "11.0"

  # The value of the `LSMinimumSystemVersion` in `Info.plist` files. This value
  # controls the minimum OS version that may launch the application, and OS
  # releases older than this will refuse to launch the application. When
  # dropping support for older macOSes, this variable is often changed before
  # `mac_deployment_target` to increase the system requirement without changing
  # how Chromium is compiled. This must be greater than or equal to the
  # `mac_deployment_target` version.
  mac_min_system_version = "11.0"

  # Path to a specific version of the Mac SDK, not including a slash at the end.
  # If empty, the path to the lowest version greater than or equal to
  # `mac_sdk_min` is used.
  mac_sdk_path = ""

  # The SDK name as accepted by `xcodebuild`.
  mac_sdk_name = "macosx"

  # The SDK version used when making official builds. This is a single exact
  # version, not a minimum. If this version isn't available official builds
  # will fail.
  mac_sdk_official_version = "15.1"

  # The SDK build version used when making official builds.  This is a single
  # exact version found at "System/Library/CoreServices/SystemVersion.plist"
  # inside the SDK.
  mac_sdk_official_build_version = "24B75"

  # Production builds should use hermetic Xcode. If you want to do production
  # builds with system Xcode to test new SDKs, set this.
  # Don't set this on any bots.
  mac_allow_system_xcode_for_official_builds_for_testing = false
}

# Check that the version of macOS SDK used is the one requested when building
# a version of Chrome shipped to the users. Disable the check if building for
# iOS as the version macOS SDK used is not relevant for the tool build for the
# host (they are not shipped) --- this is required as Chrome on iOS is usually
# build with the latest version of Xcode that may not ship with the version of
# the macOS SDK used to build Chrome on mac.
# TODO(crbug.com/40479759): the check for target_os should be replaced by a
# check that current_toolchain is default_toolchain, and the file should
# assert that current_os is "mac" once this file is no longer included by
# iOS toolchains.
if (is_chrome_branded && is_official_build && target_os != "ios") {
  assert(!use_system_xcode ||
             mac_allow_system_xcode_for_official_builds_for_testing,
         "official branded builds should use hermetic xcode")
}

# The path to the hermetic install of Xcode. Only relevant when
# use_system_xcode = false.
if (!use_system_xcode) {
  _hermetic_xcode_path = "//build/mac_files/xcode_binaries"
}

script_name = "//build/config/apple/sdk_info.py"
sdk_info_args = []
if (!use_system_xcode) {
  sdk_info_args += [
    "--developer_dir",
    rebase_path(_hermetic_xcode_path, "", root_build_dir),
  ]
}

# Building crashpard requires some files that are part of the macOS SDK
# (and shipped inside Xcode.app) into the application. When using the
# system installation of Xcode, those files are outside of the checkout.
# Using absolute path works with gn, however the distributed build system
# requires that all paths are relative to the checkout. This is faked by
# using symbolic links to the SDK inside of Xcode. Additionally, each build
# directory may use a distinct version of Xcode (e.g. to build with beta),
# so the symlink needs to be present in the $root_build_dir. However, when
# doing that, we need to list inputs pointing to file in $root_build_dir,
# and gn requires all files in $root_build_dir to be listed as outputs of
# another target.
#
# To fulfill all of those requirements, we 1. create symlinks pointing to
# the SDK files in Xcode, 2. declare a target listing the files as outputs
# (the target is a script that does nothing, it only pretends to create
# the files but they already exists).
#
# This works, but results in some files in $root_build_dir being links to
# files outside of the build directory. Running `ninja -t clean` will try
# to delete those files breaking Xcode installation. The recommendation is
# to use `gn clean` or `ninja -t cleandead` instead.
#
# This variable controls whether we create the symlink and the workaround
# is needed or not. See https://crbug.com/336382863#comment16 for details.
mac_use_xcode_symlinks = use_system_xcode && use_remoteexec

# RBE requires paths relative to source directory. When using system
# Xcode, this is done by creating symbolic links in root_build_dir.
if (mac_use_xcode_symlinks) {
  sdk_info_args += [
    "--get_sdk_info",
    "--create_symlink_at",
    "sdk/xcode_links",
    "--root_build_dir",
    root_build_dir,
  ]
}
sdk_info_args += [ mac_sdk_name ]

_mac_sdk_result = exec_script(script_name, sdk_info_args, "scope")
xcode_version = _mac_sdk_result.xcode_version
xcode_build = _mac_sdk_result.xcode_build
if (mac_sdk_path == "" && use_system_xcode && use_remoteexec) {
  mac_sdk_path = _mac_sdk_result.sdk_path
}

if (use_system_xcode) {
  # The tool will print the SDK path on the first line, and the version on the
  # second line.
  find_sdk_args = [
    "--print_sdk_path",
    "--print_bin_path",
    "--print_sdk_build",
    mac_sdk_min,
  ]
  find_sdk_lines =
      exec_script("//build/mac/find_sdk.py", find_sdk_args, "list lines")
  mac_sdk_version = find_sdk_lines[3]
  mac_sdk_build_version = find_sdk_lines[2]
  if (mac_sdk_path == "") {
    mac_sdk_path = find_sdk_lines[0]
    mac_bin_path = find_sdk_lines[1]
  } else {
    mac_bin_path = find_sdk_lines[1]
  }
} else {
  mac_sdk_version = mac_sdk_official_version
  mac_sdk_build_version = mac_sdk_official_build_version
  _dev = _hermetic_xcode_path + "/Contents/Developer"
  _sdk = "MacOSX${mac_sdk_version}.sdk"
  mac_sdk_path = _dev + "/Platforms/MacOSX.platform/Developer/SDKs/$_sdk"
  mac_bin_path = _dev + "/Toolchains/XcodeDefault.xctoolchain/usr/bin/"

  # If we're using hermetic Xcode, then we want the paths to be relative so that
  # generated ninja files are independent of the directory location.
  # TODO(thakis): Do this at the uses of this variable instead.
  mac_bin_path = rebase_path(mac_bin_path, root_build_dir)
}

_sdk_root = rebase_path(mac_sdk_path, root_build_dir)
mac_sdk_logs = [ "mac_sdk_path=${_sdk_root}" ]