123b3eb3cSopenharmony_ci# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
223b3eb3cSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
323b3eb3cSopenharmony_ci# you may not use this file except in compliance with the License.
423b3eb3cSopenharmony_ci# You may obtain a copy of the License at
523b3eb3cSopenharmony_ci#
623b3eb3cSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
723b3eb3cSopenharmony_ci#
823b3eb3cSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
923b3eb3cSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
1023b3eb3cSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1123b3eb3cSopenharmony_ci# See the License for the specific language governing permissions and
1223b3eb3cSopenharmony_ci# limitations under the License.
1323b3eb3cSopenharmony_ci
1423b3eb3cSopenharmony_ciimport("//build/ohos.gni")
1523b3eb3cSopenharmony_ciimport("//foundation/arkui/ace_engine/ace_config.gni")
1623b3eb3cSopenharmony_ciimport("//foundation/arkui/ace_engine/build/ace_lib.gni")
1723b3eb3cSopenharmony_ci
1823b3eb3cSopenharmony_ci# generate libace_engine and libace_debug targets
1923b3eb3cSopenharmony_ciforeach(item, ace_platforms) {
2023b3eb3cSopenharmony_ci  platform = item.name
2123b3eb3cSopenharmony_ci  engine_config = {
2223b3eb3cSopenharmony_ci  }
2323b3eb3cSopenharmony_ci  engine_config = item.config
2423b3eb3cSopenharmony_ci  support_engines = []
2523b3eb3cSopenharmony_ci  support_engines = engine_config.js_engines
2623b3eb3cSopenharmony_ci
2723b3eb3cSopenharmony_ci  # generate libace_static lib
2823b3eb3cSopenharmony_ci  libace_static("libace_static_" + item.name) {
2923b3eb3cSopenharmony_ci    platform = item.name
3023b3eb3cSopenharmony_ci    config = {
3123b3eb3cSopenharmony_ci    }
3223b3eb3cSopenharmony_ci
3323b3eb3cSopenharmony_ci    if (defined(item.config)) {
3423b3eb3cSopenharmony_ci      config = item.config
3523b3eb3cSopenharmony_ci    }
3623b3eb3cSopenharmony_ci  }
3723b3eb3cSopenharmony_ci
3823b3eb3cSopenharmony_ci  # generate separated libace_engine lib
3923b3eb3cSopenharmony_ci  if (current_os == "ohos") {
4023b3eb3cSopenharmony_ci    build_in_engine = defined(engine_config.use_build_in_js_engine) &&
4123b3eb3cSopenharmony_ci                      engine_config.use_build_in_js_engine
4223b3eb3cSopenharmony_ci    foreach(engine, support_engines) {
4323b3eb3cSopenharmony_ci      if (!build_in_engine) {
4423b3eb3cSopenharmony_ci        # generate libace_engine
4523b3eb3cSopenharmony_ci        ace_bridge_engine("libace_engine_${engine.engine_name}_${platform}") {
4623b3eb3cSopenharmony_ci          platform = item.name
4723b3eb3cSopenharmony_ci          engine_name = engine.engine_name
4823b3eb3cSopenharmony_ci          build_type = "engine"
4923b3eb3cSopenharmony_ci          use_js_debug = false
5023b3eb3cSopenharmony_ci        }
5123b3eb3cSopenharmony_ci
5223b3eb3cSopenharmony_ci        # generate libace_engine_debug
5323b3eb3cSopenharmony_ci        if (defined(engine.have_debug) && engine.have_debug) {
5423b3eb3cSopenharmony_ci          ace_bridge_engine(
5523b3eb3cSopenharmony_ci              "libace_engine_${engine.engine_name}_debug_${platform}") {
5623b3eb3cSopenharmony_ci            platform = item.name
5723b3eb3cSopenharmony_ci            engine_name = engine.engine_name
5823b3eb3cSopenharmony_ci            build_type = "engine"
5923b3eb3cSopenharmony_ci            use_js_debug = true
6023b3eb3cSopenharmony_ci          }
6123b3eb3cSopenharmony_ci        }
6223b3eb3cSopenharmony_ci
6323b3eb3cSopenharmony_ci        # generate libace_engine_declarative
6423b3eb3cSopenharmony_ci        ace_bridge_engine(
6523b3eb3cSopenharmony_ci            "libace_engine_declarative_${engine.engine_name}_${platform}") {
6623b3eb3cSopenharmony_ci          platform = item.name
6723b3eb3cSopenharmony_ci          engine_name = engine.engine_name
6823b3eb3cSopenharmony_ci          build_type = "engine_declarative"
6923b3eb3cSopenharmony_ci        }
7023b3eb3cSopenharmony_ci      }
7123b3eb3cSopenharmony_ci
7223b3eb3cSopenharmony_ci      # generate libace_engine_pa
7323b3eb3cSopenharmony_ci      if (defined(engine_config.js_pa_support) && engine_config.js_pa_support &&
7423b3eb3cSopenharmony_ci          platform != "ohos_ng") {
7523b3eb3cSopenharmony_ci        ace_bridge_engine("libace_engine_pa_${engine.engine_name}") {
7623b3eb3cSopenharmony_ci          platform = item.name
7723b3eb3cSopenharmony_ci          engine_name = engine.engine_name
7823b3eb3cSopenharmony_ci          build_type = "engine_pa"
7923b3eb3cSopenharmony_ci          pa_engine_path = engine_config.pa_engine_path
8023b3eb3cSopenharmony_ci        }
8123b3eb3cSopenharmony_ci      }
8223b3eb3cSopenharmony_ci    }
8323b3eb3cSopenharmony_ci  }
8423b3eb3cSopenharmony_ci}
8523b3eb3cSopenharmony_ci
8623b3eb3cSopenharmony_ci# Config for reduceing eh_frame section on aosp platform to save rom size.
8723b3eb3cSopenharmony_ciconfig("reduce_eh_frame_config") {
8823b3eb3cSopenharmony_ci  if (!use_mingw_win && !use_mac && !use_linux) {
8923b3eb3cSopenharmony_ci    cflags = [
9023b3eb3cSopenharmony_ci      "-fno-unwind-tables",
9123b3eb3cSopenharmony_ci      "-fomit-frame-pointer",
9223b3eb3cSopenharmony_ci    ]
9323b3eb3cSopenharmony_ci    cflags_cc = cflags
9423b3eb3cSopenharmony_ci  }
9523b3eb3cSopenharmony_ci}
9623b3eb3cSopenharmony_ci
9723b3eb3cSopenharmony_ciconfig("ace_engine_public_config") {
9823b3eb3cSopenharmony_ci  if (use_hilog) {
9923b3eb3cSopenharmony_ci    defines = [ "USE_HILOG" ]
10023b3eb3cSopenharmony_ci  }
10123b3eb3cSopenharmony_ci}
10223b3eb3cSopenharmony_ci
10323b3eb3cSopenharmony_ciconfig("lto_link_config") {
10423b3eb3cSopenharmony_ci  if (enable_lto_O0) {
10523b3eb3cSopenharmony_ci    ldflags = [ "-Wl,--lto-O0" ]
10623b3eb3cSopenharmony_ci  } else {
10723b3eb3cSopenharmony_ci    ldflags = [ "-Wl,--lto-O2" ]
10823b3eb3cSopenharmony_ci  }
10923b3eb3cSopenharmony_ci  if (ace_engine_feature_enable_pgo && enable_enhanced_opt) {
11023b3eb3cSopenharmony_ci    ldflags +=
11123b3eb3cSopenharmony_ci        [ "-Wl,-mllvm,-force-sched-model=${ace_engine_feature_sched_model}" ]
11223b3eb3cSopenharmony_ci  }
11323b3eb3cSopenharmony_ci}
11423b3eb3cSopenharmony_ci
11523b3eb3cSopenharmony_ciohos_shared_library("libace_compatible") {
11623b3eb3cSopenharmony_ci  public_configs = [ ":ace_engine_public_config" ]
11723b3eb3cSopenharmony_ci  external_deps = []
11823b3eb3cSopenharmony_ci  if (use_hilog) {
11923b3eb3cSopenharmony_ci    external_deps += [ "hilog:libhilog" ]
12023b3eb3cSopenharmony_ci  }
12123b3eb3cSopenharmony_ci  if (is_ohos) {
12223b3eb3cSopenharmony_ci    sanitize = {
12323b3eb3cSopenharmony_ci      integer_overflow = true
12423b3eb3cSopenharmony_ci      boundary_sanitize = true
12523b3eb3cSopenharmony_ci      debug = ace_sanitize_debug
12623b3eb3cSopenharmony_ci    }
12723b3eb3cSopenharmony_ci    deps = [ "$ace_root/build:libace_static_ohos" ]
12823b3eb3cSopenharmony_ci    version_script = "libace.map"
12923b3eb3cSopenharmony_ci    innerapi_tags = [ "platformsdk" ]
13023b3eb3cSopenharmony_ci    configs = [ "$ace_root:ace_coverage_config" ]
13123b3eb3cSopenharmony_ci    if (is_clang && (target_cpu == "arm" || target_cpu == "arm64") &&
13223b3eb3cSopenharmony_ci        enhanced_opt) {
13323b3eb3cSopenharmony_ci      configs += [ ":lto_link_config" ]
13423b3eb3cSopenharmony_ci    }
13523b3eb3cSopenharmony_ci  } else if (use_mingw_win) {
13623b3eb3cSopenharmony_ci    deps = [ "$ace_root/build:libace_static_windows" ]
13723b3eb3cSopenharmony_ci  } else if (use_mac) {
13823b3eb3cSopenharmony_ci    deps = [ "$ace_root/build:libace_static_mac" ]
13923b3eb3cSopenharmony_ci  } else if (use_linux) {
14023b3eb3cSopenharmony_ci    deps = [ "$ace_root/build:libace_static_linux" ]
14123b3eb3cSopenharmony_ci  }
14223b3eb3cSopenharmony_ci  public_external_deps = external_deps
14323b3eb3cSopenharmony_ci  part_name = ace_engine_part
14423b3eb3cSopenharmony_ci  subsystem_name = ace_engine_subsystem
14523b3eb3cSopenharmony_ci}
14623b3eb3cSopenharmony_ci
14723b3eb3cSopenharmony_ciif (!is_asan) {
14823b3eb3cSopenharmony_ci  ohos_shared_library("libace") {
14923b3eb3cSopenharmony_ci    external_deps = []
15023b3eb3cSopenharmony_ci    if (use_hilog) {
15123b3eb3cSopenharmony_ci      external_deps += [ "hilog:libhilog" ]
15223b3eb3cSopenharmony_ci    }
15323b3eb3cSopenharmony_ci    if (is_ohos) {
15423b3eb3cSopenharmony_ci      sanitize = {
15523b3eb3cSopenharmony_ci        integer_overflow = true
15623b3eb3cSopenharmony_ci        boundary_sanitize = true
15723b3eb3cSopenharmony_ci        debug = ace_sanitize_debug
15823b3eb3cSopenharmony_ci      }
15923b3eb3cSopenharmony_ci      deps = [ "$ace_root/build:libace_static_ohos_ng" ]
16023b3eb3cSopenharmony_ci      version_script = "libace.map"
16123b3eb3cSopenharmony_ci      innerapi_tags = [ "platformsdk" ]
16223b3eb3cSopenharmony_ci      configs = [ "$ace_root:ace_coverage_config" ]
16323b3eb3cSopenharmony_ci    } else if (use_mingw_win) {
16423b3eb3cSopenharmony_ci      deps = [ "$ace_root/build:libace_static_windows" ]
16523b3eb3cSopenharmony_ci    } else if (use_mac) {
16623b3eb3cSopenharmony_ci      deps = [ "$ace_root/build:libace_static_mac" ]
16723b3eb3cSopenharmony_ci    } else if (use_linux) {
16823b3eb3cSopenharmony_ci      deps = [ "$ace_root/build:libace_static_linux" ]
16923b3eb3cSopenharmony_ci    }
17023b3eb3cSopenharmony_ci    public_external_deps = external_deps
17123b3eb3cSopenharmony_ci    part_name = ace_engine_part
17223b3eb3cSopenharmony_ci    subsystem_name = ace_engine_subsystem
17323b3eb3cSopenharmony_ci  }
17423b3eb3cSopenharmony_ci} else {
17523b3eb3cSopenharmony_ci  group("libace") {
17623b3eb3cSopenharmony_ci    # fake target for asan
17723b3eb3cSopenharmony_ci  }
17823b3eb3cSopenharmony_ci}
179