From 7d722c50a46b538c64b89efccc491f50d9c55712 Mon Sep 17 00:00:00 2001 From: Chandan Padhi Date: Mon, 20 Aug 2018 22:45:14 -0700 Subject: [PATCH] [Rom Size] Refactor tizen GN build This patch reduces libchromiumewk.so file size by ~17MB. out.tz_v5.0.standard.armv7l/libchromium-ewk.so size: w/o patch: 115M with patch: 98M It also reduces .text size by ~18MB. .text size: w/o patch: 53M with patch: 35M Change-Id: I801a7a8904d745593f5f181883a6dbb4d8bc35fe Signed-off-by: Chandan Padhi --- tizen_src/build/config/BUILD.gn | 24 +--- tizen_src/build/config/BUILDCONFIG.gn | 175 ++++++++++++++++++++++-------- tizen_src/build/config/compiler/BUILD.gn | 4 - tizen_src/build/config/tizen_features.gni | 3 - tizen_src/build/gn_chromiumefl.sh | 6 +- tizen_src/build/toolchain/tizen/BUILD.gn | 11 +- 6 files changed, 141 insertions(+), 82 deletions(-) diff --git a/tizen_src/build/config/BUILD.gn b/tizen_src/build/config/BUILD.gn index 5e52daf..069eb3c 100644 --- a/tizen_src/build/config/BUILD.gn +++ b/tizen_src/build/config/BUILD.gn @@ -2,24 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//build/config/features.gni") -import("//build/config/ui.gni") +import("//tizen_src/build/config/tizen_features.gni") -# One common error that happens is that GYP-generated headers within gen/ get -# included rather than the GN-generated ones within gen/ subdirectories. -# TODO(agrieve): Remove once GYP is gone (as well as exec_script exception). -#assert( -# exec_script("//build/dir_exists.py", [ "obj.host" ], "string") == "False", -# "GYP artifacts detected in $root_build_dir.$0x0A" + -# "You must wipe this directory before building with GN.") - -# TODO(brettw) Most of these should be removed. Instead of global feature -# flags, we should have more modular flags that apply only to a target and its -# dependents. For example, depending on the "x11" meta-target should define -# USE_X11 for all dependents so that everything that could use X11 gets the -# define, but anything that doesn't depend on X11 doesn't see it. -# -# For now we define these globally to match the current GYP build. config("tizen_feature_flags") { defines = [ # TODO: Check if those defines are still necessary. If they are add an explanation why. @@ -27,7 +11,6 @@ config("tizen_feature_flags") { "BUILDING_V8_SHARED", "V8_SHARED", ] - if (use_efl) { defines += [ "USE_EFL" ] if (tizen_version >= 50) { @@ -40,18 +23,13 @@ config("tizen_feature_flags") { if (ewk_bringup) { defines += [ "EWK_BRINGUP" ] } - if (is_tizen) { defines += [ "OS_TIZEN", - "WTF_OS_TIZEN", "TIZEN_VERSION_MAJOR=${tizen_version_major}", "TIZEN_VERSION_MINOR=${tizen_version_minor}", "TIZEN_VERSION_PATCH=${tizen_version_patch}", ] - - defines += [ "NO_UNWIND_TABLES" ] - if (use_wayland) { defines += [ "USE_WAYLAND" ] } diff --git a/tizen_src/build/config/BUILDCONFIG.gn b/tizen_src/build/config/BUILDCONFIG.gn index 2ebb902..13cecd7 100644 --- a/tizen_src/build/config/BUILDCONFIG.gn +++ b/tizen_src/build/config/BUILDCONFIG.gn @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# Update this file on every upversion based on //build/config/BUILDCONFIG.gn. + # ============================================================================= # WHAT IS THIS FILE? # ============================================================================= @@ -130,15 +132,18 @@ declare_args() { # separate flags. is_official_build = false - # Debug build. Enabling official builds automatically sets is_debug to false. - is_debug = false - # Whether we're a traditional desktop unix. is_desktop_linux = current_os == "linux" # Set to true when compiling with the Clang compiler. Typically this is used # to configure warnings. - is_clang = current_os == "ios" + is_clang = + current_os == "mac" || current_os == "ios" || current_os == "chromeos" || + current_os == "fuchsia" || current_os == "android" || + current_os == "win" || + (current_os == "linux" && current_cpu != "s390x" && + current_cpu != "s390" && current_cpu != "ppc64" && + current_cpu != "ppc" && current_cpu != "mips" && current_cpu != "mips64") # Allows the path to a custom target toolchain to be injected as a single # argument, and set as the default toolchain. @@ -146,16 +151,17 @@ declare_args() { # This should not normally be set as a build argument. It's here so that # every toolchain can pass through the "global" value via toolchain_args(). - if (current_os == "tizen") { - host_toolchain = "//tizen_src/build/toolchain/tizen:$host_cpu" - } else { - host_toolchain = "" - } + host_toolchain = "" # DON'T ADD MORE FLAGS HERE. Read the comment above. } declare_args() { + # Debug build. is_debug is set to false for efl port. + is_debug = false +} + +declare_args() { # Component build. Setting to true compiles targets declared as "components" # as shared libraries loaded dynamically. This speeds up development time. # When false, components will be linked statically. @@ -204,10 +210,12 @@ if (host_toolchain == "") { # On Windows always use the target CPU for host builds. On the # configurations we support this will always work and it saves build steps. if (is_clang) { - host_toolchain = "//build/toolchain/win:clang_$target_cpu" + host_toolchain = "//build/toolchain/win:win_clang_$target_cpu" } else { host_toolchain = "//build/toolchain/win:$target_cpu" } + } else if (host_os == "aix") { + host_toolchain = "//build/toolchain/aix:$host_cpu" } else { assert(false, "Unsupported host_os: $host_os") } @@ -215,13 +223,18 @@ if (host_toolchain == "") { _default_toolchain = "" -if (target_os == "tizen") { +if (target_os == "android") { + assert(host_os == "linux" || host_os == "mac", + "Android builds are only supported on Linux and Mac hosts.") + _default_toolchain = "//build/toolchain/android:android_clang_$target_cpu" +} else if (target_os == "tizen") { assert(host_os == "linux" || host_os == "mac", "Tizen builds are only supported on Linux and Mac hosts.") if (is_clang) { - _default_toolchain = "//tizen_src/build/toolchain/tizen_clang_$target_cpu" + _default_toolchain = + "//tizen_src/build/toolchain/tizen:tizen_clang_$target_cpu" } else { - _default_toolchain = "//tizen_src/build/toolchain/tizen:$target_cpu" + _default_toolchain = "//tizen_src/build/toolchain/tizen:tizen_$target_cpu" } } else if (target_os == "chromeos" || target_os == "linux") { # See comments in build/toolchain/cros/BUILD.gn about board compiles. @@ -230,6 +243,8 @@ if (target_os == "tizen") { } else { _default_toolchain = "//build/toolchain/linux:$target_cpu" } +} else if (target_os == "fuchsia") { + _default_toolchain = "//build/toolchain/fuchsia:$target_cpu" } else if (target_os == "ios") { _default_toolchain = "//build/toolchain/mac:ios_clang_$target_cpu" } else if (target_os == "mac") { @@ -237,15 +252,23 @@ if (target_os == "tizen") { _default_toolchain = host_toolchain } else if (target_os == "win") { # On Windows we use the same toolchain for host and target by default. - assert(target_os == host_os, "Win cross-compiles only work on win hosts.") + # Beware, win cross builds have some caveats, see docs/win_cross.md + # TODO(thakis): See if we want to make 32-bit builds on mac hosts work. + assert(host_os != "mac" || target_cpu == "x64", + "Mac hosts can only build 64-bit chrome/win, https://crbug.com/794838") if (is_clang) { - _default_toolchain = "//build/toolchain/win:clang_$target_cpu" + _default_toolchain = "//build/toolchain/win:win_clang_$target_cpu" } else { _default_toolchain = "//build/toolchain/win:$target_cpu" } -} else if (target_os == "winrt_81" || target_os == "winrt_81_phone" || - target_os == "winrt_10") { - _default_toolchain = "//build/toolchain/win:winrt_$target_cpu" +} else if (target_os == "winuwp") { + # Only target WinUWP on for a Windows store application and only + # x86, x64 and arm are supported target CPUs. + assert(target_cpu == "x86" || target_cpu == "x64" || target_cpu == "arm" || + target_cpu == "arm64") + _default_toolchain = "//build/toolchain/win:uwp_$target_cpu" +} else if (target_os == "aix") { + _default_toolchain = "//build/toolchain/aix:$target_cpu" } else { assert(false, "Unsupported target_os: $target_os") } @@ -276,10 +299,10 @@ if (custom_toolchain != "") { # aix or one of the BSDs. If you need to check these, just check the # current_os value directly. -if (current_os == "win" || current_os == "winrt_81" || - current_os == "winrt_81_phone" || current_os == "winrt_10") { +if (current_os == "win" || current_os == "winuwp") { is_android = false is_chromeos = false + is_fuchsia = false is_ios = false is_linux = false is_mac = false @@ -291,6 +314,7 @@ if (current_os == "win" || current_os == "winrt_81" || } else if (current_os == "mac") { is_android = false is_chromeos = false + is_fuchsia = false is_ios = false is_linux = false is_mac = true @@ -311,12 +335,37 @@ if (current_os == "win" || current_os == "winrt_81" || is_win = false is_tizen = true use_efl = true +} else if (current_os == "android") { + is_android = true + is_chromeos = false + is_fuchsia = false + is_ios = false + is_linux = false + is_mac = false + is_nacl = false + is_posix = true + is_win = false + is_tizen = false + use_efl = false +} else if (current_os == "chromeos") { + is_android = false + is_chromeos = true + is_fuchsia = false + is_ios = false + is_linux = true + is_mac = false + is_nacl = false + is_posix = true + is_win = false + is_tizen = false + use_efl = false } else if (current_os == "nacl") { # current_os == "nacl" will be passed by the nacl toolchain definition. # It is not set by default or on the command line. We treat is as a # Posix variant. is_android = false is_chromeos = false + is_fuchsia = false is_ios = false is_linux = false is_mac = false @@ -325,9 +374,20 @@ if (current_os == "win" || current_os == "winrt_81" || is_win = false is_tizen = false use_efl = false +} else if (current_os == "fuchsia") { + is_android = false + is_chromeos = false + is_fuchsia = true + is_ios = false + is_linux = false + is_mac = false + is_nacl = false + is_posix = false + is_win = false } else if (current_os == "ios") { is_android = false is_chromeos = false + is_fuchsia = false is_ios = true is_linux = false is_mac = false @@ -348,6 +408,16 @@ if (current_os == "win" || current_os == "winrt_81" || is_win = false is_tizen = false use_efl = true +} else if (current_os == "aix") { + is_android = false + is_chromeos = false + is_fuchsia = false + is_ios = false + is_linux = false + is_mac = false + is_nacl = false + is_posix = true + is_win = false } # ============================================================================= @@ -367,7 +437,9 @@ if (current_os == "win" || current_os == "winrt_81" || # DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call # below. sources_assignment_filter = [] -if (!is_posix) { + +# TODO(crbug.com/812974): Clean up _posix files and remove Fuchsia here. +if (!is_posix && !is_fuchsia) { sources_assignment_filter += [ "*_posix.h", "*_posix.cc", @@ -376,6 +448,7 @@ if (!is_posix) { "*\bposix/*", ] } + if (!is_win) { sources_assignment_filter += [ "*_win.cc", @@ -471,31 +544,39 @@ set_sources_assignment_filter(sources_assignment_filter) # The values configured here will be automatically set on the scope of the # corresponding target. Target definitions can add or remove to the settings # here as needed. +# +# WHAT GOES HERE? +# +# Other than the main compiler and linker configs, the only reason for a config +# to be in this list is if some targets need to explicitly override that config +# by removing it. This is how targets opt-out of flags. If you don't have that +# requirement and just need to add a config everywhere, reference it as a +# sub-config of an existing one, most commonly the main "compiler" one. # Holds all configs used for running the compiler. default_compiler_configs = [ "//build/config:feature_flags", "//tizen_src/build/config:tizen_feature_flags", "//build/config/compiler:afdo", + "//build/config/compiler:afdo_optimize_size", "//build/config/compiler:compiler", "//build/config/compiler:clang_stackrealign", "//build/config/compiler:compiler_arm_fpu", + "//build/config/compiler:compiler_arm_thumb", "//build/config/compiler:chromium_code", "//build/config/compiler:default_include_dirs", "//tizen_src/build/config/compiler:tizen_default_include_dirs", "//build/config/compiler:default_optimization", "//build/config/compiler:default_stack_frames", "//build/config/compiler:default_symbols", + "//build/config/compiler:no_exceptions", "//build/config/compiler:no_rtti", "//build/config/compiler:runtime_library", "//build/config/compiler:thin_archive", "//build/config/coverage:default_coverage", "//build/config/sanitizers:default_sanitizer_flags", ] -if (!is_tizen) { - default_compiler_configs += - [ "//tizen_src/build/config/compiler:tizen_default_lib_dirs" ] -} + if (is_win) { default_compiler_configs += [ "//build/config/win:default_crt", @@ -506,22 +587,28 @@ if (is_win) { "//build/config/win:vs_code_analysis", ] } -if (current_os == "winrt_81" || current_os == "winrt_81_phone" || - current_os == "winrt_10") { - default_compiler_configs += [ "//build/config/win:target_winrt" ] -} + if (is_posix) { - default_compiler_configs += [ - "//build/config/compiler:no_exceptions", - "//build/config/gcc:symbol_visibility_hidden", - ] + if (current_os != "aix") { + default_compiler_configs += + [ "//build/config/gcc:symbol_visibility_hidden" ] + } +} + +if (is_fuchsia) { + default_compiler_configs += [ "//build/config/gcc:symbol_visibility_hidden" ] } -if (!use_efl) { +if (is_android) { default_compiler_configs += [ "//build/config/android:default_cygprofile_instrumentation" ] } +if (is_win) { + default_compiler_configs += + [ "//build/config/win:default_cygprofile_instrumentation" ] +} + if (is_clang && !is_nacl) { default_compiler_configs += [ "//build/config/clang:find_bad_constructs", @@ -556,7 +643,7 @@ if (is_win) { # that shouldn't use the windows subsystem. "//build/config/win:console", ] -} else if (is_mac || is_ios) { +} else if (is_mac) { _linker_configs = [ "//build/config/mac:strip_all" ] } else { _linker_configs = [] @@ -571,28 +658,28 @@ set_defaults("executable") { configs = default_executable_configs } -# Test defaults. -set_defaults("test") { - configs = default_executable_configs -} - # Shared library and loadable module defaults (also for components in component -# Test defaults.# mode). +# mode). default_shared_library_configs = default_compiler_configs + [ "//build/config:default_libs", "//build/config:shared_library_config", ] + _linker_configs -if (!use_efl) { +if (is_android) { # Strip native JNI exports from shared libraries by default. Binaries that # want this can remove this config. default_shared_library_configs += - [ "//build/config/android:hide_native_jni_exports" ] + [ "//build/config/android:hide_all_but_jni_onload" ] } set_defaults("shared_library") { configs = default_shared_library_configs } set_defaults("loadable_module") { configs = default_shared_library_configs + + # loadable_modules are generally used by other libs, not just via JNI. + if (is_android) { + configs -= [ "//build/config/android:hide_all_but_jni_onload" ] + } } # ============================================================================== @@ -664,7 +751,7 @@ set_defaults("component") { if (is_component_build) { configs = default_shared_library_configs if (is_android) { - configs -= [ "//build/config/android:hide_native_jni_exports" ] + configs -= [ "//build/config/android:hide_all_but_jni_onload" ] } } else { configs = default_compiler_configs diff --git a/tizen_src/build/config/compiler/BUILD.gn b/tizen_src/build/config/compiler/BUILD.gn index 43df313..b1e649d 100644 --- a/tizen_src/build/config/compiler/BUILD.gn +++ b/tizen_src/build/config/compiler/BUILD.gn @@ -14,10 +14,6 @@ declare_args() { } } -config("tizen_default_lib_dirs") { - lib_dirs = [] -} - config("tizen_default_include_dirs") { include_dirs = [ "//tizen_src", diff --git a/tizen_src/build/config/tizen_features.gni b/tizen_src/build/config/tizen_features.gni index 0e4bd3d..c861c9b 100644 --- a/tizen_src/build/config/tizen_features.gni +++ b/tizen_src/build/config/tizen_features.gni @@ -6,12 +6,9 @@ import("//build/config/ui.gni") declare_args() { gcc_version = 49 - is_tizen = false use_wayland = false - disable_fatal_linker_warnings = true # no use of this variable, if removing then revome from gn_chromiumefl.sh also - python_ver = "2.5" # no use of this variable, if removing then revome from gn_chromiumefl.sh also depth = "" # no use of this variable, if removing then revome from gn_chromiumefl.sh also diff --git a/tizen_src/build/gn_chromiumefl.sh b/tizen_src/build/gn_chromiumefl.sh index 11e77da..13c5405 100755 --- a/tizen_src/build/gn_chromiumefl.sh +++ b/tizen_src/build/gn_chromiumefl.sh @@ -82,7 +82,6 @@ COMMON_GN_PARAMETERS="use_libjpeg_turbo=true enable_extensions=false use_cups=false use_allocator=\"none\" - disable_fatal_linker_warnings=true depth=\"${TOPDIR}\" use_libpci=false " @@ -128,7 +127,8 @@ add_tizen_flags() { current_cpu=\"${host_arch}\" host_cpu=\"${host_arch}\" target_cpu=\"${host_arch}\" - v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:$host_arch\" + host_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\" + v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\" " # FIXME : Note that the v8_snapshot_toolchain has been set to wrong @@ -136,7 +136,7 @@ add_tizen_flags() { # This sets it to toolchain gcc forcibly as workaround. # It needs to be set to the toolchain gcc under is_clang is false. if [ "$host_arch" == "x64" ]; then - ADDITIONAL_GN_PARAMETERS+="v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:x64\" + ADDITIONAL_GN_PARAMETERS+="v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_x64\" " fi diff --git a/tizen_src/build/toolchain/tizen/BUILD.gn b/tizen_src/build/toolchain/tizen/BUILD.gn index d22e48c..a24d6d5 100644 --- a/tizen_src/build/toolchain/tizen/BUILD.gn +++ b/tizen_src/build/toolchain/tizen/BUILD.gn @@ -2,7 +2,7 @@ # 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") # Imports android/config.gni. +import("//build/config/clang/clang.gni") import("//build/toolchain/gcc_toolchain.gni") template("tizen_gcc_toolchain") { @@ -22,16 +22,17 @@ template("tizen_gcc_toolchain") { _prefix = rebase_path("$clang_base_path/bin", root_build_dir) cc = "$_prefix/clang" cxx = "$_prefix/clang++" + ar = "$_prefix/llvm-ar" } else { cc = "gcc" cxx = "g++" + ar = cc + "-ar" } - ar = cc + "-ar" ld = cxx readelf = "readelf" nm = "nm" - #strip = "strip" + #strip = rebase_path("//third_party/eu-strip/bin/eu-strip", root_build_dir) # Don't use .cr.so for loadable_modules since they are always loaded via # absolute path. @@ -40,12 +41,12 @@ template("tizen_gcc_toolchain") { } template("tizen_gcc_toolchains_helper") { - tizen_gcc_toolchain(target_name) { + tizen_gcc_toolchain("tizen_$target_name") { forward_variables_from(invoker, "*") toolchain_args.is_clang = false } - tizen_gcc_toolchain("clang_$target_name") { + tizen_gcc_toolchain("tizen_clang_$target_name") { forward_variables_from(invoker, "*") toolchain_args.is_clang = true } -- 2.7.4