Skip to content

Commit 4a96b2e

Browse files
committed
[gn build] Add libclang_rt.ios.a, libclang_rt.iossim.a to the build
It's built with just-built clang, like all other compiler-rt parts in the GN build. This requires adding some cross build support to the mac toolchain. Also add explicit mmacosx-version-min and miphoneos-version-min flags to the build. ios.a is only built with the arm64 slice, iossim.a only with the x86_64 slice for now. (The latter should maybe become host_cpu when Arm Macs become a common iOS development platform.) With this, it's possible to build chromium/iOS with a GN-built LLVM. Differential Revision: https://reviews.llvm.org/D89260
1 parent fe145b6 commit 4a96b2e

File tree

8 files changed

+98
-19
lines changed

8 files changed

+98
-19
lines changed

llvm/utils/gn/build/BUILD.gn

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,36 @@ config("compiler_defaults") {
4242
cflags = target_flags
4343
ldflags = target_flags + target_ldflags
4444

45-
if (host_os == "mac" && clang_base_path != "") {
45+
if ((current_os == "ios" || current_os == "mac") && clang_base_path != "") {
46+
if (current_os == "ios" && current_cpu == "arm64") {
47+
sdk_path = ios_sdk_path
48+
} else if (current_os == "ios" && current_cpu == "x64") {
49+
sdk_path = iossim_sdk_path
50+
} else if (current_os == "mac") {
51+
sdk_path = mac_sdk_path
52+
}
4653
cflags += [
4754
"-isysroot",
48-
mac_sdk_path,
55+
sdk_path,
4956
]
5057
ldflags += [
5158
"-isysroot",
52-
mac_sdk_path,
59+
sdk_path,
5360
]
5461
}
5562

63+
# Mostly for compiler-rt, see compiler-rt/cmake/config-ix.cmake
64+
if (current_os == "ios") {
65+
asmflags += [ "-miphoneos-version-min=8.0" ]
66+
cflags += [ "-miphoneos-version-min=8.0" ]
67+
ldflags += [ "-miphoneos-version-min=8.0" ]
68+
}
69+
if (current_os == "mac") {
70+
asmflags += [ "-mmacosx-version-min=10.10" ]
71+
cflags += [ "-mmacosx-version-min=10.10" ]
72+
ldflags += [ "-mmacosx-version-min=10.10" ]
73+
}
74+
5675
if (host_os != "win") {
5776
if (is_debug) {
5877
cflags += [ "-g" ]
@@ -296,7 +315,7 @@ config("no_rtti") {
296315
# To make an archive that can be distributed, you need to remove this config and
297316
# set complete_static_lib.
298317
config("thin_archive") {
299-
if (current_os != "win" && current_os != "mac") {
318+
if (current_os != "ios" && current_os != "mac" && current_os != "win") {
300319
arflags = [ "-T" ]
301320
}
302321
}

llvm/utils/gn/build/mac_sdk.gni

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ declare_args() {
99
# but that makes `gn gen` take twice as long and almost everyone has Xcode
1010
# installed. So require that people who don't have it installed set a gn arg.
1111
if (mac_use_commandline_tools_sdk) {
12+
ios_sdk_path = "/Library/Developer/CommandLineTools/SDKs/iPhoneOS.sdk"
13+
iossim_sdk_path =
14+
"/Library/Developer/CommandLineTools/SDKs/iPhoneSimulator.sdk"
1215
mac_sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
1316
} else {
17+
ios_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
18+
iossim_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
1419
mac_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
1520
}

llvm/utils/gn/build/toolchain/BUILD.gn

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ template("unix_toolchain") {
5656
}
5757

5858
tool("alink") {
59-
if (current_os == "mac") {
59+
if (current_os == "ios" || current_os == "mac") {
6060
command = "libtool -D -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
6161
} else {
6262
# Remove the output file first so that ar doesn't try to modify the
@@ -70,7 +70,7 @@ template("unix_toolchain") {
7070
default_output_dir = "{{root_out_dir}}/lib"
7171
}
7272

73-
if (current_os == "mac") {
73+
if (current_os == "ios" || current_os == "mac") {
7474
# gn < 1693 (e214b5d35898) doesn't support |frameworks|, requiring
7575
# frameworks to be listed in |libs|, but gn >= 1808 (3028c6a426a4) forbids
7676
# frameworks from appearing in |libs|. This assertion provides a helpful
@@ -89,7 +89,7 @@ template("unix_toolchain") {
8989

9090
tool("solink") {
9191
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
92-
if (current_os == "mac") {
92+
if (current_os == "ios" || current_os == "mac") {
9393
command = "$ld -shared {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}"
9494
default_output_extension = ".dylib"
9595
} else {
@@ -105,7 +105,7 @@ template("unix_toolchain") {
105105

106106
tool("solink_module") {
107107
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
108-
if (current_os == "mac") {
108+
if (current_os == "ios" || current_os == "mac") {
109109
command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{inputs}} {{libs}} {{frameworks}}"
110110
default_output_extension = ".dylib"
111111
} else {
@@ -120,7 +120,7 @@ template("unix_toolchain") {
120120

121121
tool("link") {
122122
outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
123-
if (current_os == "mac") {
123+
if (current_os == "ios" || current_os == "mac") {
124124
command =
125125
"$ld {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}"
126126
} else {
@@ -141,7 +141,7 @@ template("unix_toolchain") {
141141
description = "COPY {{source}} {{output}}"
142142
}
143143

144-
if (current_os == "mac") {
144+
if (current_os == "ios" || current_os == "mac") {
145145
tool("copy_bundle_data") {
146146
# http://serverfault.com/q/209888/43689
147147
_copydir = "mkdir -p {{output}} && cd {{source}} && " +
@@ -164,7 +164,7 @@ template("unix_toolchain") {
164164
}
165165

166166
unix_toolchain("unix") {
167-
if (current_os != "mac") {
167+
if (current_os != "ios" && current_os != "mac") {
168168
ar = "ar"
169169
}
170170

@@ -189,7 +189,7 @@ template("stage2_unix_toolchain") {
189189
"//:clang($host_toolchain)",
190190
"//:lld($host_toolchain)",
191191
]
192-
if (current_os != "mac") {
192+
if (current_os != "ios" && current_os != "mac") {
193193
ar = "bin/llvm-ar"
194194
deps += [ "//:llvm-ar($host_toolchain)" ]
195195
}
@@ -219,6 +219,22 @@ if (android_ndk_path != "") {
219219
}
220220
}
221221

222+
if (host_os == "mac") {
223+
stage2_unix_toolchain("stage2_ios_aarch64") {
224+
toolchain_args = {
225+
current_os = "ios"
226+
current_cpu = "arm64"
227+
}
228+
}
229+
230+
stage2_unix_toolchain("stage2_iossim_x64") {
231+
toolchain_args = {
232+
current_os = "ios"
233+
current_cpu = "x64"
234+
}
235+
}
236+
}
237+
222238
toolchain("win") {
223239
cl = "cl"
224240
link = "link"

llvm/utils/gn/build/toolchain/target_flags.gni

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import("//llvm/triples.gni")
22
import("//llvm/utils/gn/build/toolchain/compiler.gni")
33

4+
# Flags in this file are passed both to the compiler that's building
5+
# compiler-rt at build time (via normal gn cflags/ldflags), as well as to the
6+
# compiler building compiler-rt test programs at test time (via
7+
# COMPILER_RT_TEST_COMPILER_CFLAGS).
8+
49
target_flags = []
510
target_ldflags = []
611

@@ -14,6 +19,26 @@ if (current_os == "android") {
1419
if (current_cpu == "arm") {
1520
target_flags += [ "-march=armv7-a" ]
1621
}
22+
} else if (current_os == "ios") {
23+
if (current_cpu == "arm64") {
24+
target_flags += [
25+
"-arch",
26+
"arm64",
27+
]
28+
target_ldflags += [
29+
"-arch",
30+
"arm64",
31+
]
32+
} else if (current_cpu == "x64") {
33+
target_flags += [
34+
"-arch",
35+
"x86_64",
36+
]
37+
target_ldflags += [
38+
"-arch",
39+
"x86_64",
40+
]
41+
}
1742
}
1843

1944
if (current_cpu == "x86") {

llvm/utils/gn/secondary/compiler-rt/BUILD.gn

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import("//llvm/lib/Target/targets.gni")
12
import("//llvm/utils/gn/build/toolchain/compiler.gni")
23

34
# In the GN build, compiler-rt is always built by just-built clang and lld.
@@ -10,10 +11,20 @@ if (android_ndk_path != "") {
1011
"//llvm/utils/gn/build/toolchain:stage2_android_arm",
1112
]
1213
}
13-
1414
group("compiler-rt") {
1515
deps = []
1616
foreach(toolchain, supported_toolchains) {
1717
deps += [ "//compiler-rt/lib($toolchain)" ]
1818
}
19+
20+
# FIXME: Do this only if a gn arg compiler_rt_enable_ios is set?
21+
# That would match the cmake build.
22+
if (host_os == "mac") {
23+
if (llvm_build_AArch64) {
24+
deps += [ "//compiler-rt/lib/builtins(//llvm/utils/gn/build/toolchain:stage2_ios_aarch64)" ]
25+
}
26+
if (llvm_build_X86) {
27+
deps += [ "//compiler-rt/lib/builtins(//llvm/utils/gn/build/toolchain:stage2_iossim_x64)" ]
28+
}
29+
}
1930
}

llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ static_library("builtins") {
1313
output_dir = crt_current_out_dir
1414
if (current_os == "mac") {
1515
output_name = "clang_rt.osx"
16+
} else if (current_os == "ios" && current_cpu == "arm64") {
17+
output_name = "clang_rt.ios"
18+
} else if (current_os == "ios" && current_cpu == "x64") {
19+
output_name = "clang_rt.iossim"
1620
} else {
1721
output_name = "clang_rt.builtins$crt_current_target_suffix"
1822
}
@@ -177,7 +181,7 @@ static_library("builtins") {
177181
sources += [ "clear_cache.c" ]
178182
}
179183

180-
if (current_os == "mac") {
184+
if (current_os == "mac" || current_os == "ios") {
181185
sources += [
182186
"atomic_flag_clear.c",
183187
"atomic_flag_clear_explicit.c",
@@ -496,8 +500,7 @@ static_library("builtins") {
496500
}
497501
}
498502

499-
# Currently unused but necessary to make the sync_source_lists_from_cmake.py
500-
# happy.
503+
# Currently unused but necessary to make sync_source_lists_from_cmake.py happy.
501504
source_set("_unused") {
502505
sources = [
503506
# Thumb1

llvm/utils/gn/secondary/compiler-rt/target.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (clang_enable_per_target_runtime_dir) {
2626
if (current_os == "android") {
2727
crt_current_target_suffix += "-android"
2828
}
29-
} else if (current_os == "mac") {
29+
} else if (current_os == "ios" || current_os == "mac") {
3030
crt_current_out_dir = "$clang_resource_dir/lib/darwin"
3131
} else {
3232
assert(false, "unimplemented current_os " + current_os)

llvm/utils/gn/secondary/llvm/triples.gni

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (current_cpu == "x86") {
77
llvm_current_triple = "x86_64-unknown-freebsd"
88
} else if (current_os == "linux") {
99
llvm_current_triple = "x86_64-unknown-linux-gnu"
10-
} else if (current_os == "mac") {
10+
} else if (current_os == "ios" || current_os == "mac") {
1111
llvm_current_triple = "x86_64-apple-darwin"
1212
} else if (current_os == "win") {
1313
llvm_current_triple = "x86_64-pc-windows-msvc"
@@ -19,7 +19,7 @@ if (current_cpu == "x86") {
1919
} else if (current_cpu == "arm64") {
2020
if (current_os == "android") {
2121
llvm_current_triple = "aarch64-linux-android29"
22-
} else if (current_os == "mac") {
22+
} else if (current_os == "ios" || current_os == "mac") {
2323
llvm_current_triple = "arm64-apple-darwin"
2424
}
2525
} else if (current_cpu == "ppc64") {

0 commit comments

Comments
 (0)