From f9025456768b63f57cddb9c576d97ce84719efaa Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Mon, 3 Feb 2014 12:04:33 +0000 Subject: [PATCH] Work on GN iOS build. Separates out some "SDK" related setup on Mac land Linux like we do on Windows. I'm trying to make the "compiler" BUILD file just compiler warnings and CPU options, and have system library stuff on the platform directories. This adds the capability for GN to produce GYP files on Mac that vary according to the GYP generator as well as target-vs-host. I added a bunch of logic to the GN iOS build to set up stuff accordingly based on my current knowledge of what's required. Sadly, this means we now have an 8-way GN build (all combinations of debug/release, host/target, and xcode/ninja). I did some refactoring of the GYP code in GN to make this less unreasonable. I checked that the GYP files look the way I want, but I didn't actually test the resulting builds yet. There is still likely to be some conditions wrong or things not being set properly. I'm going to follow up with a second pass based on actual testing. I believe, however, that with this new GYP generator code in GN, we can express in the .gn files what we need to do the iOS build. Review URL: https://codereview.chromium.org/149163005 git-svn-id: http://src.chromium.org/svn/trunk/src/build@248476 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- config/BUILDCONFIG.gn | 18 ++++++++++++------ config/compiler/BUILD.gn | 19 +------------------ config/ios/BUILD.gn | 19 +++++++++++++++++++ config/ios/ios_sdk.gni | 34 ++++++++++++++++++++++++++++------ config/linux/BUILD.gn | 14 ++++++++++++++ config/mac/BUILD.gn | 12 ++++++++++++ gyp_chromium | 11 ++++++++++- 7 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 config/ios/BUILD.gn diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn index 38da66cef..671bdee93 100644 --- a/config/BUILDCONFIG.gn +++ b/config/BUILDCONFIG.gn @@ -80,6 +80,10 @@ declare_args() { # When running in gyp-generating mode, this is the root of the build tree. gyp_output_dir = "out" + + # When running in gyp-generating mode, this flag indicates if the current GYP + # generator is xcode. Can only be true when building for iOS). + is_gyp_xcode_generator = false } # ============================================================================= @@ -161,9 +165,8 @@ if (os == "win") { is_nacl = false is_posix = true is_win = false - if (!is_clang) { + if (!is_gyp_xcode_generator) { # Always use clang on iOS when using ninja - # (which is always true when using GN). is_clang = true } } else if (os == "linux") { @@ -332,10 +335,13 @@ native_compiler_configs = [ "//build/config/compiler:runtime_library", ] if (is_win) { - native_compiler_configs += [ - "//build/config/win:sdk", - ] -} else if (is_clang) { + native_compiler_configs += [ "//build/config/win:sdk", ] +} else if (is_mac) { + native_compiler_configs += [ "//build/config/mac:sdk", ] +} else if (is_ios) { + native_compiler_configs += [ "//build/config/ios:sdk", ] +} +if (is_clang) { native_compiler_configs += [ "//build/config/clang:find_bad_constructs" ] } diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn index e0e107354..3ed78f3ba 100644 --- a/config/compiler/BUILD.gn +++ b/config/compiler/BUILD.gn @@ -3,7 +3,6 @@ # found in the LICENSE file. import("//build/config/android/config.gni") -import("//build/config/sysroot.gni") if (cpu_arch == "arm") { import("//build/config/arm.gni") } @@ -63,12 +62,7 @@ config("compiler") { # ---------------------------------- if (is_mac || is_ios) { # These flags are shared between the C compiler and linker. - common_mac_flags = [ "-isysroot", sysroot ] - if (is_mac) { - common_mac_flags += [ "-mmacosx-version-min=10.6" ] - } else { - cflags += [ "-mios-simulator-version-min=6.0" ] - } + common_mac_flags = [] # CPU architecture. if (cpu_arch == "x64") { @@ -175,17 +169,6 @@ config("compiler") { ] } - if (sysroot != "") { - cflags += [ "--sysroot=" + sysroot ] - ldflags += [ "--sysroot=" + sysroot ] - - # Need to get some linker flags out of the sysroot. - ldflags += [ exec_script("../linux/sysroot_ld_path.py", - [rebase_path("../../linux/sysroot_ld_path.sh", ".", root_build_dir), - sysroot], - "value") ] - } - ldflags += [ "-fPIC", "-pthread", diff --git a/config/ios/BUILD.gn b/config/ios/BUILD.gn new file mode 100644 index 000000000..0886be458 --- /dev/null +++ b/config/ios/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright 2014 The Chromium 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/sysroot.gni") +import("//build/config/ios/ios_sdk.gni") + +config("sdk") { + common_flags = [ "-isysroot", sysroot ] + + cflags = common_flags + ldflags = common_flags + + if (use_ios_simulator) { + cflags += [ "-mios-simulator-version-min=$ios_deployment_target" ] + } else { + cflags += [ "-miphoneos-version-min=$ios_deployment_target" ] + } +} diff --git a/config/ios/ios_sdk.gni b/config/ios/ios_sdk.gni index f941f3ce0..7acbaaa17 100644 --- a/config/ios/ios_sdk.gni +++ b/config/ios/ios_sdk.gni @@ -2,9 +2,31 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# TODO(brettw) support "iphoneos" in addition to the simulator. May also need -# support for common.gypi's "ios_sdk" variable (seems to be a version number) -# and ios_sdk_path (argument that overrides the one returned below). -ios_sdk_result = - exec_script("ios_sdk.py", [ "iphonesimulator" ], "list lines") -ios_sdk_path = ios_sdk_result[0] +declare_args() { + # SDK path to use. When empty this will use the default SDK based on the + # value of use_ios_simulator. + ios_sdk_path = "" + + # Set to true when targeting a simulator build on iOS. False means that the + # target is for running on the device. + use_ios_simulator = true + + ios_deployment_target = "6.0" +} + +if (!is_gyp_xcode_generator) { + # The Ninja build currently only targets the simulator. + assert(use_ios_simulator, "You can't do an iOS device build using Ninja yet.") +} + +if (ios_sdk_path == "") { + # Compute default target. + if (use_ios_simulator) { + _ios_sdk_to_query = "iphonesimulator" + } else { + _ios_sdk_to_query = "iphoneos" + } + _ios_sdk_result = + exec_script("ios_sdk.py", [ _ios_sdk_to_query ], "list lines") + ios_sdk_path = _ios_sdk_result[0] +} diff --git a/config/linux/BUILD.gn b/config/linux/BUILD.gn index 29b446ae0..d166ac792 100644 --- a/config/linux/BUILD.gn +++ b/config/linux/BUILD.gn @@ -3,6 +3,20 @@ # found in the LICENSE file. import("//build/config/linux/pkg_config.gni") +import("//build/config/sysroot.gni") + +config("sdk") { + if (sysroot != "") { + cflags = [ "--sysroot=" + sysroot ] + ldflags = [ "--sysroot=" + sysroot ] + + # Need to get some linker flags out of the sysroot. + ldflags += [ exec_script("sysroot_ld_path.py", + [ rebase_path("//build/linux/sysroot_ld_path.sh", ".", root_build_dir), + sysroot ], + "value") ] + } +} # Sets up the dynamic library search path to include our "lib" directory. config("executable_ldconfig") { diff --git a/config/mac/BUILD.gn b/config/mac/BUILD.gn index 78c106aeb..b6db8e0b7 100644 --- a/config/mac/BUILD.gn +++ b/config/mac/BUILD.gn @@ -2,6 +2,18 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/sysroot.gni") + +config("sdk") { + common_flags = [ + "-isysroot", sysroot, + "-mmacosx-version-min=10.6" + ] + + cflags = common_flags + ldflags = common_flags +} + # On Mac, this is used for everything except static libraries. config("mac_dynamic_flags") { ldflags = [ diff --git a/gyp_chromium b/gyp_chromium index 8713b4340..9034c823e 100755 --- a/gyp_chromium +++ b/gyp_chromium @@ -223,7 +223,8 @@ def GetArgsStringForGN(supplemental_files): gn_args += ' ' + i[2] # These string arguments get passed directly as GN strings. - for v in ['android_src', 'windows_sdk_path', 'arm_float_abi']: + for v in ['android_src', 'arm_float_abi', 'ios_deployment_target', + 'ios_sdk_path', 'windows_sdk_path']: if v in vars_dict: gn_args += ' ' + v + '=' + EscapeStringForGN(vars_dict[v]) @@ -231,6 +232,14 @@ def GetArgsStringForGN(supplemental_files): if 'gomadir' in vars_dict: gn_args += ' goma_dir=%s' % EscapeStringForGN(vars_dict['gomadir']) + # Clear the "use_ios_simulator" flag if the ios_sdk_path is set and is + # not a simulator SDK. This duplicates code done in GYP's xcode emulation. + if 'ios_sdk_path' in vars_dict: + if not os.path.basename(vars_dict['ios_sdk_path']).lower().startswith( + 'iphonesimulator'): + gn_args += ' use_ios_simulator=false' + + # These arguments get passed directly as integers (avoiding the quoting and # escaping of the string ones above). for v in ['arm_version']: