Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions engine/src/build/config/apple/apple_sdk.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
# Path to the Xcode toolchain (XcodeDefault.xctoolchain).
apple_host_toolchain_path = ""
}

if (apple_host_toolchain_path == "") {
# Outputs the SDK path on the first line, and the host toolchain path on the
# second.
_find_sdk_lines =
exec_script("//build/mac/find_sdk.py", ["--print_sdk_path", "1.0"], "list lines")

apple_host_toolchain_path = _find_sdk_lines[1]
}
31 changes: 25 additions & 6 deletions engine/src/build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ config("compiler") {
cflags_c = []
cflags_cc = []
cflags_objcc = []
swiftflags = []
ldflags = []
defines = []
configs = []

# Platform-specific configs.
if (is_ios) {
configs += [ "//build/config/ios:compiler" ]
}

# In general, Windows is totally different, but all the other builds share
# some common GCC configuration. This section sets up Windows and the common
Expand Down Expand Up @@ -534,17 +541,26 @@ config("runtime_library") {
}

if (use_flutter_cxx) {
cflags_cc += [ "-nostdinc++" ]
cflags_objcc += [ "-nostdinc++" ]
# Add libcxx[abi]/include via cflags_cc, cflags_objcc to apply to
# C++/Obj-C++ only. Adding them via include_dirs is problematic for Swift,
# whose core libraries expect the Apple SDK C++ headers, module.modulemap.
_libcxx_include = rebase_path("//flutter/third_party/libcxx/include", root_build_dir)
_libcxxabi_include = rebase_path("//flutter/third_party/libcxxabi/include", root_build_dir)
cflags_cc += [
"-nostdinc++",
"-I" + _libcxx_include,
"-I" + _libcxxabi_include,
]
cflags_objcc += [
"-nostdinc++",
"-I" + _libcxx_include,
"-I" + _libcxxabi_include,
]

# Unwind seemes to be in these libraries in Linux.
if (!is_linux) {
ldflags += [ "-nostdlib++" ]
}
include_dirs = [
"//flutter/third_party/libcxx/include",
"//flutter/third_party/libcxxabi/include",
]
}

# Android standard library setup.
Expand Down Expand Up @@ -991,6 +1007,9 @@ config("symbols") {
}
} else {
cflags = [ "-g2" ]
if (is_apple) {
swiftflags = [ "-g" ]
}
}
}

Expand Down
60 changes: 60 additions & 0 deletions engine/src/build/config/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,66 @@ config("sdk") {
cflags_cc = [ "-stdlib=libc++" ]
}

config("compiler") {
# swiftc -sdk flag.
_sdk_root = ios_sdk_path
if (create_xcode_symlinks) {
_sdk_root = rebase_path(ios_sdk_path, root_build_dir)
}

# swiftc -target flag (target triplet).
# CPU architecture.
if (current_cpu == "x64") {
_triplet_cpu = "x86_64"
} else if (current_cpu == "arm64") {
_triplet_cpu = "arm64"
} else {
# x86, arm, armv7, etc.
assert(false, "unsupported cpu: $current_cpu")
}
# Environment.
if (use_ios_simulator) {
_triplet_environment = "-simulator"
} else {
_triplet_environment = ""
}
# OS.
if (is_ios) {
_triplet_os = "apple-ios"
} else if (is_mac) {
_triplet_os = "apple-macos"
} else {
assert(false, "unsupported Apple os")
}
_target_triplet = "$_triplet_cpu-$_triplet_os$ios_deployment_target$_triplet_environment"

# swiftc -swift-version flag.
#
# Swift 6 transition: As of April 2025, no public Flutter framework API is
# authored in Swift. Swift 6 is ABI-compatible with Swift 5, but not
# source-compatible. If any public API *is* written in Swift, it's possible
# we may need to prepare concurrent Swift 5 and 6 builds during a transition
# period.
_swift_version = "5"

# TODO(cbracken): https://github.com/flutter/flutter/issues/167592
# Look up xcode_version in ios_sdk.gni/mac_sdk.gni.
#
# This is here so that all files get recompiled after an Xcode update.
# (defines are passed via the command line, and build system rebuild things
# when their commandline changes). Nothing should ever read this define.
#defines = [ "CR_XCODE_VERSION=$xcode_version" ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@cbracken Oh i just remembered I came across this a while back when trying to support swift 6.

From the comment it looks like you intended to pass it in below to handle xcode update scenario, but it's commented out. Wondering what's the current state (can it be removed or do we still want it?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This can be removed.


swiftflags = [
"-sdk",
_sdk_root,
"-target",
_target_triplet,
"-swift-version",
_swift_version
]
}

config("ios_application_extension") {
cflags_objc = [ "-fapplication-extension" ]
cflags_objcc = [ "-fapplication-extension" ]
Expand Down
18 changes: 17 additions & 1 deletion engine/src/build/config/ios/ios_sdk.gni
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/apple/apple_sdk.gni")
import("//build/toolchain/rbe.gni")

declare_args() {
Expand All @@ -27,6 +28,9 @@ declare_args() {
# The path to the iOS simulator SDK.
ios_simulator_sdk_path = ""

# The path to iOS SDK Swift libraries.
ios_swift_lib_paths = []

# Version of iOS that we're targeting for tests.
ios_testing_deployment_target = "13.0"
}
Expand Down Expand Up @@ -66,3 +70,15 @@ if (ios_sdk_path == "") {
ios_sdk_path = ios_device_sdk_path
}
}

# Set in //build/config/apple/apple_sdk.gni.
assert (apple_host_toolchain_path != "")

if (ios_swift_lib_paths == []) {
ios_swift_lib_paths += [rebase_path("$ios_sdk_path/usr/lib/swift")]
if (use_ios_simulator) {
ios_swift_lib_paths += [rebase_path("$apple_host_toolchain_path/usr/lib/swift/iphonesimulator")]
} else {
ios_swift_lib_paths += [rebase_path("$apple_host_toolchain_path/usr/lib/swift/iphoneos")]
}
}
2 changes: 1 addition & 1 deletion engine/src/build/config/ios/ios_sdk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down
11 changes: 6 additions & 5 deletions engine/src/build/config/mac/mac_sdk.gni
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/apple/apple_sdk.gni")
import("//build/toolchain/rbe.gni")

declare_args() {
Expand Down Expand Up @@ -35,10 +36,10 @@ if (mac_sdk_path == "") {
mac_sdk_min,
]

# The tool will print the SDK path on the first line, and the version on the
# second line.
find_sdk_lines =
# Outputs the SDK path on the first line, and the host toolchain path on the
# second.
_find_sdk_lines =
exec_script("//build/mac/find_sdk.py", find_sdk_args, "list lines")

mac_sdk_path = find_sdk_lines[0]
mac_sdk_path = _find_sdk_lines[0]
}
13 changes: 11 additions & 2 deletions engine/src/build/mac/find_sdk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -91,7 +91,11 @@ def main():
'|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
'if you are using Xcode 4.') % job.returncode)

# xcrun --sdk macosx --show-sdk-path
# Locate the host toolchain.
xcode_dir = run_command_with_retry(['xcode-select', '-print-path'], timeout=300)
toolchain_dir = os.path.join(xcode_dir, 'Toolchains/XcodeDefault.xctoolchain')

# Locate the target SDK.
sdk_command = [
'xcrun',
'--sdk',
Expand All @@ -101,12 +105,17 @@ def main():
sdk_output = run_command_with_retry(sdk_command, timeout=300)
if symlink_path:
sdks_path = os.path.join(symlink_path, 'SDKs')
# Symlink the host toolchain.
toolchain_target = os.path.join(sdks_path, 'XcodeDefault.xctoolchain')
symlink(toolchain_dir, toolchain_target)
# Symlink the SDK.
symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output))
symlink(sdk_output, symlink_target)
sdk_output = symlink_target

if not options.as_gclient_hook:
print(sdk_output)
print(toolchain_dir)
return 0


Expand Down
20 changes: 20 additions & 0 deletions engine/src/build/toolchain/apple/get_tool_mtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
Comment thread
cbracken marked this conversation as resolved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


import os
import sys

# Usage: python get_tool_mtime.py path/to/file1.py path/to/file2.py
#
# Prints a GN scope with the variable name being the basename sans-extension
# and the value being the file modification time. A variable is emitted for
# each file argument on the command line.

if __name__ == '__main__':
for f in sys.argv[1:]:
variable = os.path.splitext(os.path.basename(f))[0]
print('%s = %d' % (variable, os.path.getmtime(f)))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["AppIntent","EntityQuery","AppEntity","TransientEntity","AppEnum","AppShortcutProviding","AppShortcutsProvider","AnyResolverProviding","AppIntentsPackage","DynamicOptionsProvider"]
Loading