Skip to content

Commit

Permalink
Bug 1834908 - Reintroduce iOS support in the build system. r=firefox-…
Browse files Browse the repository at this point in the history
…build-system-reviewers,andi

Differential Revision: https://phabricator.services.mozilla.com/D178998
  • Loading branch information
glandium committed Feb 29, 2024
1 parent fd1d748 commit 434c5a4
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build/gyp_includes/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@
# The Mac SDK is set for iOS builds and passed through to Mac
# sub-builds. This allows the Mac sub-build SDK in an iOS build to be
# overridden from the command line the same way it is for a Mac build.
'mac_sdk%': '<!(<(PYTHON) <(DEPTH)/build/mac/find_sdk.py 10.6)',
'mac_sdk%': '',

# iOS SDK and deployment target support. The iOS 5.0 SDK is actually
# what is required, but the value is left blank so when it is set in
Expand Down
17 changes: 16 additions & 1 deletion build/moz.configure/init.configure
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ def split_triplet(triplet, allow_wasi=False):
elif os.startswith("darwin"):
canonical_kernel = "Darwin"
canonical_os = "OSX"
elif os.startswith("ios"):
canonical_kernel = "Darwin"
canonical_os = "iOS"
# old-configure does plenty of tests against $target and $target_os
# and expects darwin for iOS, so make it happy.
sub_configure_alias = sub_configure_alias[: -len(os)] + "darwin"
elif os.startswith("dragonfly"):
canonical_os = canonical_kernel = "DragonFly"
elif os.startswith("freebsd"):
Expand Down Expand Up @@ -603,7 +609,7 @@ def split_triplet(triplet, allow_wasi=False):
# prefixes. We need to be more specific about the LLVM target on Mac
# so cross-language LTO will work correctly.

if os.startswith("darwin"):
if os.startswith(("darwin", "ios")):
toolchain = "%s-apple-%s" % (cpu, os)
else:
toolchain = "%s-%s" % (cpu, os)
Expand Down Expand Up @@ -902,6 +908,15 @@ def host_is_osx(host):
set_define("XP_MACOSX", target_is_osx)


@depends(target)
def target_is_ios(target):
if target.kernel == "Darwin" and target.os == "iOS":
return True


set_define("XP_IOS", target_is_ios)


@depends(target)
def target_has_linux_kernel(target):
if target.kernel == "Linux":
Expand Down
5 changes: 2 additions & 3 deletions build/moz.configure/lto-pgo.configure
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def lto(

if (
target.kernel == "Darwin"
and target.os == "OSX"
and "cross" in values
and select_linker.KIND == "ld64"
and not ld64_known_good
Expand Down Expand Up @@ -395,7 +394,7 @@ def lto(
# (For hot functions, PGO will put a multiplier on this limit.)
if target.os == "WINNT":
ldflags.append("-mllvm:-import-instr-limit=10")
elif target.os == "OSX":
elif target.kernel == "Darwin":
ldflags.append("-Wl,-mllvm,-import-instr-limit=10")
elif c_compiler.type == "clang":
ldflags.append("-Wl,-plugin-opt=-import-instr-limit=10")
Expand All @@ -409,7 +408,7 @@ def lto(
ldflags.append("-opt:ltonewpassmanager")
if c_compiler.version >= "12.0.0":
ldflags.append("-mllvm:-import-hot-multiplier=30")
elif target.os == "OSX":
elif target.kernel == "Darwin":
ldflags.append("-Wl,-mllvm,-import-hot-multiplier=30")
else:
if c_compiler.version < "13.0.0":
Expand Down
2 changes: 1 addition & 1 deletion build/moz.configure/pkg.configure
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pkg_config = check_prog(
bootstrap=depends(when=target_sysroot.bootstrapped)(lambda: "pkgconf"),
allow_missing=True,
when=compile_environment
& depends(target.os)(lambda os: os not in ("WINNT", "OSX", "Android")),
& depends(target.os)(lambda os: os not in ("WINNT", "OSX", "iOS", "Android")),
)


Expand Down
138 changes: 115 additions & 23 deletions build/moz.configure/toolchain.configure
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ with only_when(target_is_osx):
return value[0]


@imports("plistlib")
@imports(_from="__builtin__", _import="open")
@imports(_from="__builtin__", _import="Exception")
def get_sdk_version(sdk):
with open(os.path.join(sdk, "SDKSettings.plist"), "rb") as plist:
obj = plistlib.load(plist)
if not obj:
raise Exception(
"Error parsing SDKSettings.plist in the SDK directory: %s" % sdk
)
if "Version" not in obj:
raise Exception(
"Error finding Version information in SDKSettings.plist from the SDK: %s"
% sdk
)
return Version(obj["Version"])


with only_when(host_is_osx | target_is_osx):
# MacOS SDK
# =========
Expand All @@ -81,31 +99,14 @@ with only_when(host_is_osx | target_is_osx):
help="Location of platform SDK to use",
)

@imports("plistlib")
@imports(_from="__builtin__", _import="open")
@imports(_from="__builtin__", _import="Exception")
def get_sdk_version(sdk):
with open(os.path.join(sdk, "SDKSettings.plist"), "rb") as plist:
obj = plistlib.load(plist)
if not obj:
raise Exception(
"Error parsing SDKSettings.plist in the SDK directory: %s" % sdk
)
if "Version" not in obj:
raise Exception(
"Error finding Version information in SDKSettings.plist from the SDK: %s"
% sdk
)
return Version(obj["Version"])

def sdk_min_version():
def mac_sdk_min_version():
return "14.2"

@depends(
"--with-macos-sdk",
host,
bootstrap_path(
"MacOSX{}.sdk".format(sdk_min_version()),
"MacOSX{}.sdk".format(mac_sdk_min_version()),
when=depends("--with-macos-sdk")(lambda x: not x),
allow_failure=True,
),
Expand Down Expand Up @@ -155,10 +156,10 @@ with only_when(host_is_osx | target_is_osx):
"tools are selected during the Xcode/Developer Tools installation."
% sdk
)
if version < Version(sdk_min_version()):
if version < Version(mac_sdk_min_version()):
die(
'SDK version "%s" is too old. Please upgrade to at least %s. Try '
"updating your system Xcode." % (version, sdk_min_version())
"updating your system Xcode." % (version, mac_sdk_min_version())
)
return sdk

Expand Down Expand Up @@ -195,6 +196,90 @@ with only_when(target_is_osx):
set_config("MACOS_PRIVATE_FRAMEWORKS_DIR", macos_private_frameworks)


with only_when(target_is_ios):
# iOS deployment target version
# ==============================================================
# This needs to happen before any compilation test is done.

option(
"--enable-ios-target",
env="IPHONEOS_DEPLOYMENT_TARGET",
nargs=1,
default="16.4",
help="Set the minimum iOS version needed at runtime",
)

@depends_if("--enable-ios-target")
def ios_target(value):
return value[0]


with only_when(target_is_ios):
# MacOS SDK
# =========
option(
"--with-ios-sdk",
env="IPHONEOS_SDK_DIR",
nargs=1,
help="Location of platform SDK to use",
)

def ios_sdk_min_version():
return "16.4"

@depends("--with-ios-sdk", host)
@imports(_from="__builtin__", _import="Exception")
@imports(_from="os.path", _import="isdir")
@imports(_from="os", _import="listdir")
def ios_sdk(sdk, host):
if sdk:
sdk = sdk[0]
try:
version = get_sdk_version(sdk)
except Exception as e:
die(e)
elif host.os == "OSX":
sdk = check_cmd_output(
"xcrun", "--show-sdk-path", "--sdk", "iphoneos", onerror=lambda: ""
).rstrip()
if not sdk:
die(
"Could not find the iOS SDK. Please use --with-ios-sdk to give "
"the path to a iOS SDK."
)
# Scan the parent directory xcrun returns for the most recent SDK.
sdk_dir = os.path.dirname(sdk)
versions = []
for d in listdir(sdk_dir):
if d.lower().startswith("iphoneos"):
try:
sdk = os.path.join(sdk_dir, d)
versions.append((get_sdk_version(sdk), sdk))
except Exception:
pass
version, sdk = max(versions)
else:
die(
"Need an iOS SDK when targeting iOS. Please use --with-ios-sdk "
"to give the path to a iOS SDK."
)

if not isdir(sdk):
die(
"SDK not found in %s. When using --with-ios-sdk, you must specify a "
"valid SDK. SDKs are installed when the optional cross-development "
"tools are selected during the Xcode installation." % sdk
)
if version < Version(ios_sdk_min_version()):
die(
'SDK version "%s" is too old. Please upgrade to at least %s. Try '
"updating your system Xcode." % (version, ios_sdk_min_version())
)
return sdk

set_config("IPHONEOS_SDK_DIR", ios_sdk)


# GC rooting and hazard analysis.
# ==============================================================
option(env="MOZ_HAZARD", help="Build for the GC rooting hazard analysis")
Expand Down Expand Up @@ -1065,18 +1150,21 @@ def sysroot(host_or_target, target_sysroot=None):
sysroot_input,
host_or_target,
macos_sdk,
ios_sdk,
bootstrap_path(
depends(host_or_target)(lambda t: "sysroot-{}".format(t.toolchain)),
when=bootstrap_sysroot,
),
)
@imports("os")
def sysroot(sysroot_input, host_or_target, macos_sdk, path):
def sysroot(sysroot_input, host_or_target, macos_sdk, ios_sdk, path):
version = None
if sysroot_input:
path = sysroot_input[0]
elif host_or_target.kernel == "Darwin" and macos_sdk:
elif host_or_target.os == "OSX" and macos_sdk:
path = macos_sdk
elif host_or_target.os == "iOS" and ios_sdk:
path = ios_sdk
if path:
# Find the version of libstdc++ headears in the sysroot
include = os.path.join(path, "usr/include/c++")
Expand Down Expand Up @@ -1229,6 +1317,7 @@ def compiler(
host_or_target,
sysroot,
macos_target,
ios_target,
android_version,
vc_compiler_version,
multiarch_dir,
Expand All @@ -1246,6 +1335,7 @@ def compiler(
host_or_target,
sysroot,
macos_target,
ios_target,
android_version,
vc_compiler_version,
multiarch_dir,
Expand Down Expand Up @@ -1276,6 +1366,8 @@ def compiler(

if host_or_target.os == "OSX" and macos_target:
flags.append("-mmacosx-version-min=%s" % macos_target)
if host_or_target.os == "iOS" and ios_target:
flags.append("-mios-version-min=%s" % ios_target)

# When not given an explicit compatibility version, clang-cl tries
# to get one from MSVC, which might not even be the one used by the
Expand Down
6 changes: 3 additions & 3 deletions build/moz.configure/update-programs.configure
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# Updater
# ==============================================================
@depends(build_project)
def updater_default(build_project):
return build_project != "mobile/android"
@depends(build_project, target)
def updater_default(build_project, target):
return build_project != "mobile/android" and target.os != "iOS"


option(
Expand Down
3 changes: 3 additions & 0 deletions config/makefiles/rust.mk
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ ifeq ($(OS_ARCH), Darwin)
ifdef MACOS_SDK_DIR
export COREAUDIO_SDK_PATH=$(MACOS_SDK_DIR)
endif
ifdef IPHONEOS_SDK_DIR
export COREAUDIO_SDK_PATH=$(IPHONEOS_SDK_DIR)
endif
endif

ifndef RUSTC_BOOTSTRAP
Expand Down
2 changes: 1 addition & 1 deletion js/moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True
# FJCVTZS instruction as part of ARMv8.3-JSConv.
@depends(target)
def is_apple_silicon(target):
return target.os == "OSX" and target.kernel == "Darwin" and target.cpu == "aarch64"
return target.kernel == "Darwin" and target.cpu == "aarch64"


option(
Expand Down
1 change: 1 addition & 0 deletions python/mozbuild/mozbuild/configure/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class OS(EnumString):
"DragonFly",
"FreeBSD",
"GNU",
"iOS",
"NetBSD",
"OpenBSD",
"OSX",
Expand Down
4 changes: 4 additions & 0 deletions security/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ gyp_vars["ssl_enable_zlib"] = 0
gyp_vars["use_system_sqlite"] = 1
gyp_vars["sqlite_libs"] = "sqlite"
gyp_vars["enable_draft_hpke"] = 1
# This makes a block in security/nss/coreconf/config.gypi happy, but it
# doesn't actually matter because it's for xcode settings, which the
# build system ignores.
gyp_vars["iphone_deployment_target"] = "doesntmatter"

# Clang can build NSS with its integrated assembler since version 9.
if (
Expand Down
Loading

0 comments on commit 434c5a4

Please sign in to comment.