diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -42,17 +42,36 @@ cflags = target_flags ldflags = target_flags + target_ldflags - if (host_os == "mac" && clang_base_path != "") { + if ((current_os == "ios" || current_os == "mac") && clang_base_path != "") { + if (current_os == "ios" && current_cpu == "arm64") { + sdk_path = ios_sdk_path + } else if (current_os == "ios" && current_cpu == "x64") { + sdk_path = iossim_sdk_path + } else if (current_os == "mac") { + sdk_path = mac_sdk_path + } cflags += [ "-isysroot", - mac_sdk_path, + sdk_path, ] ldflags += [ "-isysroot", - mac_sdk_path, + sdk_path, ] } + # Mostly for compiler-rt, see compiler-rt/cmake/config-ix.cmake + if (current_os == "ios") { + asmflags += [ "-miphoneos-version-min=8.0" ] + cflags += [ "-miphoneos-version-min=8.0" ] + ldflags += [ "-miphoneos-version-min=8.0" ] + } + if (current_os == "mac") { + asmflags += [ "-mmacosx-version-min=10.10" ] + cflags += [ "-mmacosx-version-min=10.10" ] + ldflags += [ "-mmacosx-version-min=10.10" ] + } + if (host_os != "win") { if (is_debug) { cflags += [ "-g" ] @@ -296,7 +315,7 @@ # To make an archive that can be distributed, you need to remove this config and # set complete_static_lib. config("thin_archive") { - if (current_os != "win" && current_os != "mac") { + if (current_os != "ios" && current_os != "mac" && current_os != "win") { arflags = [ "-T" ] } } diff --git a/llvm/utils/gn/build/mac_sdk.gni b/llvm/utils/gn/build/mac_sdk.gni --- a/llvm/utils/gn/build/mac_sdk.gni +++ b/llvm/utils/gn/build/mac_sdk.gni @@ -9,7 +9,12 @@ # but that makes `gn gen` take twice as long and almost everyone has Xcode # installed. So require that people who don't have it installed set a gn arg. if (mac_use_commandline_tools_sdk) { + ios_sdk_path = "/Library/Developer/CommandLineTools/SDKs/iPhoneOS.sdk" + iossim_sdk_path = + "/Library/Developer/CommandLineTools/SDKs/iPhoneSimulator.sdk" mac_sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" } else { + ios_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" + iossim_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" mac_sdk_path = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" } diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -56,7 +56,7 @@ } tool("alink") { - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { command = "libtool -D -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}" } else { # Remove the output file first so that ar doesn't try to modify the @@ -70,7 +70,7 @@ default_output_dir = "{{root_out_dir}}/lib" } - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { # gn < 1693 (e214b5d35898) doesn't support |frameworks|, requiring # frameworks to be listed in |libs|, but gn >= 1808 (3028c6a426a4) forbids # frameworks from appearing in |libs|. This assertion provides a helpful @@ -89,7 +89,7 @@ tool("solink") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { command = "$ld -shared {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}" default_output_extension = ".dylib" } else { @@ -105,7 +105,7 @@ tool("solink_module") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { command = "$ld -shared {{ldflags}} -Wl,-flat_namespace -Wl,-undefined,suppress -o $outfile {{inputs}} {{libs}} {{frameworks}}" default_output_extension = ".dylib" } else { @@ -120,7 +120,7 @@ tool("link") { outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { command = "$ld {{ldflags}} -o $outfile {{inputs}} {{libs}} {{frameworks}}" } else { @@ -141,7 +141,7 @@ description = "COPY {{source}} {{output}}" } - if (current_os == "mac") { + if (current_os == "ios" || current_os == "mac") { tool("copy_bundle_data") { # http://serverfault.com/q/209888/43689 _copydir = "mkdir -p {{output}} && cd {{source}} && " + @@ -164,7 +164,7 @@ } unix_toolchain("unix") { - if (current_os != "mac") { + if (current_os != "ios" && current_os != "mac") { ar = "ar" } @@ -189,7 +189,7 @@ "//:clang($host_toolchain)", "//:lld($host_toolchain)", ] - if (current_os != "mac") { + if (current_os != "ios" && current_os != "mac") { ar = "bin/llvm-ar" deps += [ "//:llvm-ar($host_toolchain)" ] } @@ -219,6 +219,22 @@ } } +if (host_os == "mac") { + stage2_unix_toolchain("stage2_ios_aarch64") { + toolchain_args = { + current_os = "ios" + current_cpu = "arm64" + } + } + + stage2_unix_toolchain("stage2_iossim_x64") { + toolchain_args = { + current_os = "ios" + current_cpu = "x64" + } + } +} + toolchain("win") { cl = "cl" link = "link" diff --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni --- a/llvm/utils/gn/build/toolchain/target_flags.gni +++ b/llvm/utils/gn/build/toolchain/target_flags.gni @@ -1,6 +1,11 @@ import("//llvm/triples.gni") import("//llvm/utils/gn/build/toolchain/compiler.gni") +# Flags in this file are passed both to the compiler that's building +# compiler-rt at build time (via normal gn cflags/ldflags), as well as to the +# compiler building compiler-rt test programs at test time (via +# COMPILER_RT_TEST_COMPILER_CFLAGS). + target_flags = [] target_ldflags = [] @@ -14,6 +19,26 @@ if (current_cpu == "arm") { target_flags += [ "-march=armv7-a" ] } +} else if (current_os == "ios") { + if (current_cpu == "arm64") { + target_flags += [ + "-arch", + "arm64", + ] + target_ldflags += [ + "-arch", + "arm64", + ] + } else if (current_cpu == "x64") { + target_flags += [ + "-arch", + "x86_64", + ] + target_ldflags += [ + "-arch", + "x86_64", + ] + } } if (current_cpu == "x86") { diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn --- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn @@ -1,3 +1,4 @@ +import("//llvm/lib/Target/targets.gni") import("//llvm/utils/gn/build/toolchain/compiler.gni") # In the GN build, compiler-rt is always built by just-built clang and lld. @@ -10,10 +11,20 @@ "//llvm/utils/gn/build/toolchain:stage2_android_arm", ] } - group("compiler-rt") { deps = [] foreach(toolchain, supported_toolchains) { deps += [ "//compiler-rt/lib($toolchain)" ] } + + # FIXME: Do this only if a gn arg compiler_rt_enable_ios is set? + # That would match the cmake build. + if (host_os == "mac") { + if (llvm_build_AArch64) { + deps += [ "//compiler-rt/lib/builtins(//llvm/utils/gn/build/toolchain:stage2_ios_aarch64)" ] + } + if (llvm_build_X86) { + deps += [ "//compiler-rt/lib/builtins(//llvm/utils/gn/build/toolchain:stage2_iossim_x64)" ] + } + } } diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn --- a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn @@ -13,6 +13,10 @@ output_dir = crt_current_out_dir if (current_os == "mac") { output_name = "clang_rt.osx" + } else if (current_os == "ios" && current_cpu == "arm64") { + output_name = "clang_rt.ios" + } else if (current_os == "ios" && current_cpu == "x64") { + output_name = "clang_rt.iossim" } else { output_name = "clang_rt.builtins$crt_current_target_suffix" } @@ -177,7 +181,7 @@ sources += [ "clear_cache.c" ] } - if (current_os == "mac") { + if (current_os == "mac" || current_os == "ios") { sources += [ "atomic_flag_clear.c", "atomic_flag_clear_explicit.c", @@ -496,8 +500,7 @@ } } -# Currently unused but necessary to make the sync_source_lists_from_cmake.py -# happy. +# Currently unused but necessary to make sync_source_lists_from_cmake.py happy. source_set("_unused") { sources = [ # Thumb1 diff --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni --- a/llvm/utils/gn/secondary/compiler-rt/target.gni +++ b/llvm/utils/gn/secondary/compiler-rt/target.gni @@ -26,7 +26,7 @@ if (current_os == "android") { crt_current_target_suffix += "-android" } -} else if (current_os == "mac") { +} else if (current_os == "ios" || current_os == "mac") { crt_current_out_dir = "$clang_resource_dir/lib/darwin" } else { assert(false, "unimplemented current_os " + current_os) diff --git a/llvm/utils/gn/secondary/llvm/triples.gni b/llvm/utils/gn/secondary/llvm/triples.gni --- a/llvm/utils/gn/secondary/llvm/triples.gni +++ b/llvm/utils/gn/secondary/llvm/triples.gni @@ -7,7 +7,7 @@ llvm_current_triple = "x86_64-unknown-freebsd" } else if (current_os == "linux") { llvm_current_triple = "x86_64-unknown-linux-gnu" - } else if (current_os == "mac") { + } else if (current_os == "ios" || current_os == "mac") { llvm_current_triple = "x86_64-apple-darwin" } else if (current_os == "win") { llvm_current_triple = "x86_64-pc-windows-msvc" @@ -19,7 +19,7 @@ } else if (current_cpu == "arm64") { if (current_os == "android") { llvm_current_triple = "aarch64-linux-android29" - } else if (current_os == "mac") { + } else if (current_os == "ios" || current_os == "mac") { llvm_current_triple = "arm64-apple-darwin" } } else if (current_cpu == "ppc64") {