diff --git a/build/README.md b/build/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a930d7a84e1e183d960edb76ec6dfb4c56bed31c --- /dev/null +++ b/build/README.md @@ -0,0 +1,75 @@ +# 方舟编译器部件 + +## 简介 +方舟编译器部件供了一个基于GN和Ninja的集成编译构建框架。构建流程由鸿蒙方舟编译分流,并在构建基础上增加跨平台方式。 + +方舟编译器部件架构图: + +![](../figures/zh-cn_image_arkcompiler.png) + +## 目录结构 +``` +/arkcompiler/ +├── profiler # 性能调优组件 +├── ets_runtime # 方舟eTS(兼容JS/TS)运行时时 +├── runtime_core # 方舟运行时公共库 +├── ets_frontend # 方舟eTS(兼容JS/TS)前端编译器 +├── toolchain # 方舟运行时调试调优工具链 +│ └── build # 编译配置 +├── third_party # 三方库 +│ └── protobuf +│ └── icu +│ └── zlib +│ └── bounds_checking_function +``` + +## 环境配置 +获取源码及安装依赖工具,详细参考[点击这里](https://gitee.com/lordwithcc/arkcompiler_toolchain/blob/add_standalone_part/build/preconfig_ubuntu.md) + +## 使用说明 +abc文件:由方舟前端将js文件转换生成的字节码文件 + +ark_js_vm:运行abc文件的工具 + +### step1 生成编译产物ark_js_vm +``` +python ark.py x64.release +``` +### step2 将js文件转换为abc文件 +``` +./out/x64.release/ark/ark/es2abc test.js +``` +### step3 执行生成的abc文件 +``` +LD_LIBRARY_PATH=out/x64.release:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/x64.release/ark/ark_js_runtime/ark_js_vm test.abc +``` +### 执行262测试套 +``` +python ark.py x64.release -test262 +``` + +## 编译选项 + +交叉编译可根据目标选择不同平台,在x64平台构建android_arm目标平台 +``` +python ark.py android_arm.release +``` +编译模式选择,在x64平台构建debug版本 +``` +python ark.py x64.debug +``` +获取更多编译说明 +``` +python ark.py -help +``` + +## 相关仓 +[arkcompiler\_runtime\_core](https://gitee.com/openharmony/arkcompiler_runtime_core) + +[arkcompiler\_ets\_runtime](https://gitee.com/openharmony/arkcompiler_ets_runtime) + +[arkcompiler\_ets\_frontend](https://gitee.com/openharmony/arkcompiler_ets_frontend) + +**[arkcompiler\_toolchain](https://gitee.com/openharmony/arkcompiler_toolchain)** + +[developtools\_profiler](https://gitee.com/openharmony/developtools_profiler) \ No newline at end of file diff --git a/build/ark.gni b/build/ark.gni new file mode 100644 index 0000000000000000000000000000000000000000..0d3472d083a7525f901d3e9813b908303f225d6e --- /dev/null +++ b/build/ark.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/ark_var.gni") + +# import cxx base templates +import("$build_root/templates/cxx/cxx.gni") diff --git a/build/ark_var.gni b/build/ark_var.gni new file mode 100644 index 0000000000000000000000000000000000000000..82914ea356e6b04d1a654301531c1173e4873b49 --- /dev/null +++ b/build/ark_var.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + # build version + build_public_version = true +} diff --git a/build/compile_script/.gn b/build/compile_script/.gn new file mode 100755 index 0000000000000000000000000000000000000000..3c041cd9b8c2e045e6593be8a2837865fa4828e1 --- /dev/null +++ b/build/compile_script/.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The location of the build configuration file. +buildconfig = "//toolchain/build/config/BUILDCONFIG.gn" + +# The source root location. +root = "//toolchain/build/core/gn" + +# The executable used to execute scripts in action and exec_script. +script_executable = "/usr/bin/env" diff --git a/build/compile_script/ark.py b/build/compile_script/ark.py new file mode 100644 index 0000000000000000000000000000000000000000..d07b664e6060be692b0e5906f94b5dffd618f19f --- /dev/null +++ b/build/compile_script/ark.py @@ -0,0 +1,212 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from __future__ import print_function +import errno +import os +import platform +import re +import subprocess +import sys + +USE_PTY = "linux" in sys.platform +if USE_PTY: + import pty + +ARCHES = ["x64", "arm", "arm64"] +DEFAULT_ARCHES = "x64" +MODES = ["release", "debug"] +DEFAULT_MODES = "release" +TARGETS = ["ark_js_vm"] +DEFAULT_TARGETS = "all" +TARGETS_TEST = ["-test262"] + + +USER_ARGS_TEMPLATE = """\ +is_standard_system = true +%s +""" + +OUTDIR = "out" + + +Help_message = """ +formot like python ark.py [arch].[mode].[options] [test] +for example , python ark.py x64.release +[arch] can be one of ["x64", "arm", "arm64"] +[mode] can be one of ["release", "debug"] +[options] +target: only support ark_js_vm and all now +clean: clear your data in output dir +[test] +-test262: run test262 +""" + +def PrintHelp(): + print(Help_message) + sys.exit(0) + +def _Call(cmd, silent=False): + if not silent: print("# %s" % cmd) + return subprocess.call(cmd, shell=True) + +def _Write(filename, content, mode): + with open(filename, mode) as f: + f.write(content) + +def GetPath(arch,mode): + subdir = "%s.%s" % (arch, mode) + return os.path.join(OUTDIR, subdir) + +def _CallWithOutput(cmd,file): + host, guest = pty.openpty() + h = subprocess.Popen(cmd, shell=True, stdin=guest, stdout=guest, stderr=guest) + os.close(guest) + output_data = [] + while True: + try: + build_data = os.read(host, 512).decode('utf-8') + except OSError as error: + if error == errno.ENOENT: + print ("no such file") + elif error == errno.EPERM: + print ("permission denied") + break + else: + if not build_data: + break + print(build_data) + sys.stdout.flush() + _Write(file, build_data, "a") + os.close(host) + h.wait() + return h.returncode + +def Get_args(argvs): + args_list = argvs + args_len = len(args_list) + if args_len < 1: + print("Wrong usage") + PrintHelp() + elif args_len == 1: + args_out = args_list + if "-help" in args_out: + PrintHelp() + else : + args_out = args_list + return Get_templete(args_out) + +def Get_templete(args_list): + global_arche = DEFAULT_ARCHES + global_mode = DEFAULT_MODES + global_target = DEFAULT_TARGETS + global_test = '' + global_clean = False + for args in args_list: + parameter = args.split(".") + for part in parameter: + if part in ARCHES: + global_arche = part + elif part in MODES: + global_mode = part + elif part in TARGETS: + global_target = part + elif part == "clean": + global_clean = True + elif part in TARGETS_TEST: + global_test = part + else: + print("\033[34mUnkown word: %s\033[0m" % part) + sys.exit(1) + # Determine the target CPU + if global_arche in ("arm", "arm64"): + ARK_cpu = global_arche + else: + ARK_cpu = "x64" + target_cpu = "target_cpu = \"%s\"" % ARK_cpu + # Determine the target OS,Only ohos for now + ARK_os = "ohos" + target_os = "target_os = \"%s\"" % ARK_os + if global_mode == "debug": + is_debug = "is_debug = true" + else: + is_debug = "is_debug = false" + all_part = (is_debug+"\n"+target_os+"\n"+target_cpu) + return [global_arche,global_mode,global_target,global_clean,USER_ARGS_TEMPLATE%(all_part),global_test] + + +def Build(template): + arch = template[0] + mode = template[1] + target = template[2] + clean = template[3] + template_part = template[4] + path = GetPath(arch,mode) + if not os.path.exists(path): + print("# mkdir -p %s" % path) + os.makedirs(path) + if clean: + print("=== start clean ===") + code = _Call("./prebuilts/build-tools/linux-x86/bin/gn clean %s" % path) + code += _Call("./prebuilts/build-tools/linux-x86/bin/ninja -C %s -t clean" % path) + if code != 0: return code + print("=== clean success! ===") + build_log = os.path.join(path, "build.log") + if not os.path.exists("args.gn"): + args_gn = os.path.join(path, "args.gn") + _Write(args_gn, template_part, "w") + if not os.path.exists("build.ninja"): + build_ninja = os.path.join(path, "build.ninja") + code = _Call("./prebuilts/build-tools/linux-x86/bin/gn gen %s" % path) + print("=== gn success! ===") + if code != 0: return code + pass_code = _CallWithOutput("./prebuilts/build-tools/linux-x86/bin/ninja -C %s %s" % + (path, target),build_log) + if pass_code == 0:print("=== ninja success! ===") + return pass_code + + +def RunTest(template): + arch = template[0] + mode = template[1] + test = template[5] + test_dir = arch+"."+mode + test262_code = '''cd ets_frontend + python3 test262/run_test262.py --es2021 all --timeout 180000 --libs-dir ../out/%s:../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../out/%s/ark/ark_js_runtime/ark_js_vm --ark-frontend-binary=../out/%s/clang_x64/ark/ark/es2abc --merge-abc-binary=../out/%s/clang_x64/ark/ark/merge_abc --ark-frontend=es2panda + '''%(test_dir,test_dir,test_dir,test_dir) + if ("-test262" == test): + print("=== come to test ===") + return _Call(test262_code) + else: + print("=== nothing to test ===") + return 0 + + +def Main(argvs): + pass_code = 0 + templete = Get_args(argvs) + pass_code += Build(templete) + if pass_code == 0: + pass_code += RunTest(templete) + if pass_code == 0: + print('\033[32mDone!\033[0m', '\033[32mARK_{} compilation finished successfully.\033[0m'.format(argvs[0].split('.')[0])) + else: + print('\033[31mError!\033[0m', '\033[31mARK_{} compilation finished with errors.\033[0m'.format(argvs[0].split('.')[0])) + return pass_code + +if __name__ == "__main__": + sys.exit(Main(sys.argv[1:])) \ No newline at end of file diff --git a/build/compile_script/gen.sh b/build/compile_script/gen.sh new file mode 100755 index 0000000000000000000000000000000000000000..a49bf9becec05fb090622f33f700b48499737e11 --- /dev/null +++ b/build/compile_script/gen.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -e +clear + +echo "++++++++++++++++++++++++++++++++++++++++" +date +%F' '%H:%M:%S +echo $@ +echo "++++++++++++++++++++++++++++++++++++++++" +echo + +source_root_dir=$(cd $(dirname $0);pwd) + +if [[ "${source_root_dir}x" == "x" ]]; then + echo "Error: source_root_dir cannot be empty." + exit 1 +fi + +case $(uname -s) in + Darwin) + HOST_DIR="darwin-x86" + HOST_OS="mac" + ;; + Linux) + HOST_DIR="linux-x86" + HOST_OS="linux" + ;; + *) + echo "Unsupported host platform: $(uname -s)" + RET=1 + exit $RET +esac + +export PATH=${source_root_dir}/prebuilts/build-tools/${HOST_DIR}/bin:$PATH + +tools="${source_root_dir}/prebuilts/build-tools/${HOST_DIR}/bin" +ark_root="out/ark" +add_path="out:${source_root_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib" + + +if [ "$1" = "c" ] +then + echo "clear out !" + rm -rf out *.log test.abc test test.js gen.sh .gn +elif [ "$1" = "log" ] +then + $tools/gn gen out + cd out/ + $tools/ninja all -v | tee ../xxx.log + cd .. +elif [ "$1" = "abc" ] +then + export LD_LIBRARY_PATH=$add_path + ./$ark_root/ark/es2abc test.js +elif [ "$1" = "." ] +then + export LD_LIBRARY_PATH=$add_path + ./$ark_root/ark_js_runtime/ark_js_vm test.abc +elif [ "$1" = "all" ] +then + export LD_LIBRARY_PATH=$add_path + ./$ark_root/ark/es2abc test.js + ./$ark_root/ark_js_runtime/ark_js_vm test.abc +elif [ "$1" = "ark" ] +then + export SCRIPT_ROOT_DIR=$(cd $(dirname $0);pwd) #获取sh脚本绝对路径 + cp -r $SCRIPT_ROOT_DIR/* $SCRIPT_ROOT_DIR/.gn ./ + echo "cp -r build/compile_script/* ./" +else + $tools/gn gen out + cd out/ + $tools/ninja all + cd .. + echo + echo -e "\033[32m + c == clear out !\033[0m" + echo -e "\033[32m + . == execute test.abc !\033[0m" + echo -e "\033[32m + abc == get test.abc !\033[0m" + echo -e "\033[32m + all == all !\033[0m" + echo -e "\033[32m + ark == cp tools !\033[0m" +fi + +echo +echo "++++++++++++++++++++++++++++++++++++++++" +echo -e "\033[32m=====$@ successful=====\033[0m" + +date +%F' '%H:%M:%S +echo "++++++++++++++++++++++++++++++++++++++++" \ No newline at end of file diff --git a/build/compile_script/test.js b/build/compile_script/test.js new file mode 100644 index 0000000000000000000000000000000000000000..b431aa41abc08c8686f5e6b45627b11d459abd4d --- /dev/null +++ b/build/compile_script/test.js @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +"use strict"; +print("Hello World !"); + diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..07964f1bdd07a77e58a60a970b1c375cd96dfb71 --- /dev/null +++ b/build/config/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("complier_defaults") { + if (current_os == "linux") { + cflags = [ + "-fPIC", + "-pthread", + "-fno-rtti", + ] + } +} + +config("executable_ldconfig") { + if (!is_mac) { + ldflags = [ + "-Wl,-rpath=\$ORIGIN/", + "-Wl,-rpath-link=", + "-fPIE", + "-ldl", + "-lpthread", + "-lrt", + "-lc++", + "-latomic", + ] + } +} diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn new file mode 100644 index 0000000000000000000000000000000000000000..10a7d3f884c23c6838eb653cfa06ac3cec6be758 --- /dev/null +++ b/build/config/BUILDCONFIG.gn @@ -0,0 +1,140 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + another_path = true + ark_standalone_build = true + use_musl = false + build_root = "//toolchain/build" +} + +if (target_os == "") { + target_os = "ohos" #host_os# +} + +if (target_cpu == "") { + if (target_os == "ohos") { + target_cpu = "x64" + } else { + target_cpu = host_cpu + } +} + +if (current_cpu == "") { + current_cpu = host_cpu +} +if (current_os == "") { + current_os = host_os +} + +# different host platform tools directory. +if (host_os == "linux") { + host_platform_dir = "linux-x86_64" +} else { + assert(false, "Unsupported host_os: $host_os") +} + +declare_args() { + # Debug build. Enabling official builds automatically sets is_debug to false. + is_debug = false +} + +declare_args() { + host_toolchain = "" + custom_toolchain = "" + is_standard_system = false + + is_clang = current_os != "linux" || + (current_cpu != "s390x" && current_cpu != "s390" && + current_cpu != "ppc64" && current_cpu != "ppc" && + current_cpu != "mips" && current_cpu != "mips64") +} + +if (current_os == "ohos") { + is_ohos = true + is_linux = false + is_mac = false + is_posix = true + is_win = false + is_mingw = false +} else if (current_os == "linux") { + is_ohos = false + is_linux = true + is_mac = false + is_posix = true + is_win = false + is_mingw = false +} + +if (host_toolchain == "") { + # This should only happen in the top-level context. + # In a specific toolchain context, the toolchain_args() + # block should have propagated a value down. + + if (host_os == "linux") { + if (target_os != "linux") { + host_toolchain = "$build_root/toolchain/linux:clang_$host_cpu" + } else if (is_clang) { + host_toolchain = "$build_root/toolchain/linux:clang_$host_cpu" + } else { + host_toolchain = "$build_root/toolchain/linux:$host_cpu" + } + } else { + assert(false, "Unsupported host_os: $host_os") + } +} + +_default_toolchain = "" + +if (target_os == "ohos") { + assert(host_os == "linux" || host_os == "mac", + "ohos builds are only supported on Linux and Mac hosts.") + _default_toolchain = "$build_root/toolchain/ark:ark_clang_$target_cpu" +} else if (target_os == "linux") { + if (is_clang) { + _default_toolchain = "$build_root/toolchain/linux:clang_$target_cpu" + } else { + _default_toolchain = "$build_root/toolchain/linux:$target_cpu" + } +} else { + assert(false, "Unsupported target_os: $target_os") +} + +# If a custom toolchain has been set in the args, set it as default. Otherwise, +# set the default toolchain for the platform (if any). +if (custom_toolchain != "") { + set_default_toolchain(custom_toolchain) +} else if (_default_toolchain != "") { + set_default_toolchain(_default_toolchain) +} + +_shared_binary_target_configs = [ "$build_root/config:complier_defaults" ] + +default_compiler_configs = [] + +set_defaults("executable") { + configs = _shared_binary_target_configs + configs += [ "$build_root/config:executable_ldconfig" ] +} + +set_defaults("static_library") { + configs = _shared_binary_target_configs +} + +set_defaults("shared_library") { + configs = _shared_binary_target_configs +} + +set_defaults("source_set") { + configs = default_compiler_configs +} \ No newline at end of file diff --git a/build/config/clang/clang.gni b/build/config/clang/clang.gni new file mode 100644 index 0000000000000000000000000000000000000000..5871b3d08328fe609d437ad980cfa2278b09492d --- /dev/null +++ b/build/config/clang/clang.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/toolchain/toolchain.gni") + +default_clang_base_path = "//prebuilts/clang/ohos/${host_platform_dir}/llvm" + +declare_args() { + clang_base_path = default_clang_base_path +} diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..aeaaa73d4c50738f5641d812bea301960d78bd8a --- /dev/null +++ b/build/config/compiler/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("rtti") { + if (is_win) { + cflags_cc = [ "/GR" ] + } else { + cflags_cc = [ "-frtti" ] + } +} + +config("exceptions") { + if (is_win) { + # Enables exceptions in the STL. + if (!use_custom_libcxx) { + defines = [ "_HAS_EXCEPTIONS=1" ] + } + cflags_cc = [ "/EHsc" ] + } else { + cflags_cc = [ "-fexceptions" ] + } +} + +config("no_exceptions") { + if (is_win) { + # Disables exceptions in the STL. + # libc++ uses the __has_feature macro to control whether to use exceptions, + # so defining this macro is unnecessary. Defining _HAS_EXCEPTIONS to 0 also + # breaks libc++ because it depends on MSVC headers that only provide certain + # declarations if _HAS_EXCEPTIONS is 1. Those MSVC headers do not use + # exceptions, despite being conditional on _HAS_EXCEPTIONS. + if (!use_custom_libcxx) { + defines = [ "_HAS_EXCEPTIONS=0" ] + } + } else { + cflags_cc = [ "-fno-exceptions" ] + } +} diff --git a/build/config/sanitizers/sanitizers.gni b/build/config/sanitizers/sanitizers.gni new file mode 100644 index 0000000000000000000000000000000000000000..fb193d91e8dee07b4bc9566f80f063aacccdf9ff --- /dev/null +++ b/build/config/sanitizers/sanitizers.gni @@ -0,0 +1,312 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/toolchain/toolchain.gni") + +declare_args() { + # Enable Clang's Source-based Code Coverage. + use_clang_coverage = false +} + +declare_args() { + # Compile for Address Sanitizer to find memory bugs. + is_asan = false + + # Compile for Leak Sanitizer to find leaks. + is_lsan = false + + # Compile for Memory Sanitizer to find uninitialized reads. + is_msan = false + + # Compile for Thread Sanitizer to find threading bugs. + is_tsan = false + + # Compile for Undefined Behavior Sanitizer to find various types of + # undefined behavior (excludes vptr checks). + is_ubsan = false + + # Halt the program if a problem is detected. + is_ubsan_no_recover = false + + # Compile for Undefined Behavior Sanitizer's null pointer checks. + is_ubsan_null = false + + # Compile for Undefined Behavior Sanitizer's vptr checks. + is_ubsan_vptr = false + + # Compile with SafeStack shadow stack support. + is_safestack = false + + # Track where uninitialized memory originates from. From fastest to slowest: + # 0 - no tracking, 1 - track only the initial allocation site, 2 - track the + # chain of stores leading from allocation site to use site. + msan_track_origins = 2 + + # Use dynamic libraries instrumented by one of the sanitizers instead of the + # standard system libraries. Set this flag to download prebuilt binaries from + # GCS. + use_prebuilt_instrumented_libraries = false + + # Use dynamic libraries instrumented by one of the sanitizers instead of the + # standard system libraries. Set this flag to build the libraries from source. + use_locally_built_instrumented_libraries = false + + # Compile with Control Flow Integrity to protect virtual calls and casts. + # See http://clang.llvm.org/docs/ControlFlowIntegrity.html + is_cfi = target_os == "linux" && !is_chromeos && target_cpu == "x64" && + is_official_build + + # Enable checks for bad casts: derived cast and unrelated cast. + use_cfi_cast = false + + # Enable checks for indirect function calls via a function pointer. + use_cfi_icall = target_os == "linux" && !is_chromeos && target_cpu == "x64" && + is_official_build + + # Print detailed diagnostics when Control Flow Integrity detects a violation. + use_cfi_diag = false + + # Let Control Flow Integrity continue execution instead of crashing when + # printing diagnostics (use_cfi_diag = true). + use_cfi_recover = false + + # Compile for fuzzing with LLVM LibFuzzer. + # See http://www.chromium.org/developers/testing/libfuzzer + use_libfuzzer = false + + # Compile for fuzzing with AFL. + use_afl = false + + # Enables core ubsan security features. Will later be removed once it matches + # is_ubsan. + is_ubsan_security = false + + # Compile for fuzzing with Dr. Fuzz + # See http://www.chromium.org/developers/testing/dr-fuzz + use_drfuzz = false + + # Helper variable for testing builds with disabled libfuzzer. + # Not for client use. + disable_libfuzzer = false + + # Optimize for coverage guided fuzzing (balance between speed and number of + # branches). Can be also used to remove non-determinism and other issues. + optimize_for_fuzzing = false + + # Value for -fsanitize-coverage flag. Setting this causes + # use_sanitizer_coverage to be enabled. + # This flag is not used for libFuzzer (use_libfuzzer=true) unless we are on + # Mac. Instead, we use: + # -fsanitize=fuzzer-no-link + # Default value when unset and use_fuzzing_engine=true: + # trace-pc-guard + # Default value when unset and use_sanitizer_coverage=true: + # trace-pc-guard,indirect-calls + sanitizer_coverage_flags = "" +} + +is_v8_host_toolchain = + current_toolchain == "$build_root/toolchain/linux:clang_x64_v8_arm64" || + current_toolchain == "$build_root/toolchain/linux:clang_x86_v8_arm" + +# Disable sanitizers for non-default toolchains. +if (current_toolchain == host_toolchain || is_v8_host_toolchain) { + is_asan = false + is_cfi = false + is_lsan = false + is_msan = false + is_tsan = false + is_ubsan = false + is_ubsan_null = false + is_ubsan_no_recover = false + is_ubsan_security = false + is_ubsan_vptr = false + msan_track_origins = 0 + sanitizer_coverage_flags = "" + use_afl = false + use_cfi_diag = false + use_cfi_recover = false + use_drfuzz = false + use_libfuzzer = false + use_prebuilt_instrumented_libraries = false + use_locally_built_instrumented_libraries = false + use_sanitizer_coverage = false +} + +# Whether we are doing a fuzzer build. Normally this should be checked instead +# of checking "use_libfuzzer || use_afl" because often developers forget to +# check for "use_afl". +use_fuzzing_engine = use_libfuzzer || use_afl + +# Args that are in turn dependent on other args must be in a separate +# declare_args block. User overrides are only applied at the end of a +# declare_args block. +declare_args() { + use_sanitizer_coverage = + !use_clang_coverage && + (use_fuzzing_engine || sanitizer_coverage_flags != "") + + # Detect overflow/underflow for global objects. + # + # Mac: http://crbug.com/352073 + asan_globals = !is_mac +} + +if (use_fuzzing_engine && sanitizer_coverage_flags == "") { + sanitizer_coverage_flags = "trace-pc-guard" +} else if (use_sanitizer_coverage && sanitizer_coverage_flags == "") { + sanitizer_coverage_flags = "trace-pc-guard,indirect-calls" +} + +# Whether we are linking against a debugging sanitizer runtime library. Among +# other things, this changes the default symbol level and other settings in +# order to prepare to create stack traces "live" using the sanitizer runtime. +using_sanitizer = + is_asan || is_lsan || is_tsan || is_msan || is_ubsan || is_ubsan_null || + is_ubsan_vptr || is_ubsan_security || use_sanitizer_coverage || use_cfi_diag + +if (!is_ohos) { + using_sanitizer = false +} + +assert(!using_sanitizer || is_clang, + "Sanitizers (is_*san) require setting is_clang = true in 'gn args'") + +assert(!is_cfi || is_clang, + "is_cfi requires setting is_clang = true in 'gn args'") + +assert(!is_safestack || is_clang, + "is_safestack requires setting is_clang = true in 'gn args'") + +prebuilt_instrumented_libraries_available = + is_msan && (msan_track_origins == 0 || msan_track_origins == 2) + +if (use_libfuzzer && is_linux) { + if (is_asan) { + # We do leak checking with libFuzzer on Linux. Set is_lsan for code that + # relies on LEAK_SANITIZER define to avoid false positives. + is_lsan = true + } + if (is_msan) { + use_prebuilt_instrumented_libraries = true + } +} + +# MSan only links Chrome properly in release builds (brettw -- 9/1/2015). The +# same is possibly true for the other non-ASan sanitizers. But regardless of +# whether it links, one would normally never run a sanitizer in debug mode. +# Running in debug mode probably indicates you forgot to set the "is_debug = +# false" flag in the build args. ASan seems to run fine in debug mode. +# +# If you find a use-case where you want to compile a sanitizer in debug mode +# and have verified it works, ask brettw and we can consider removing it from +# this condition. We may also be able to find another way to enable your case +# without having people accidentally get broken builds by compiling an +# unsupported or unadvisable configurations. +# +# For one-off testing, just comment this assertion out. +assert(!is_debug || !(is_msan || is_ubsan || is_ubsan_null || is_ubsan_vptr), + "Sanitizers should generally be used in release (set is_debug=false).") + +assert(!is_msan || (is_linux && current_cpu == "x64"), + "MSan currently only works on 64-bit Linux and ChromeOS builds.") + +assert(!is_lsan || is_asan, "is_lsan = true requires is_asan = true also.") + +# ASAN build on Windows is not working in debug mode. Intercepting memory +# allocation functions is hard on Windows and not yet implemented in LLVM. +assert(!is_win || !is_debug || !is_asan, + "ASan on Windows doesn't work in debug (set is_debug=false).") + +# Make sure that if we recover on detection (i.e. not crash), diagnostics are +# printed. +assert(!use_cfi_recover || use_cfi_diag, + "Only use CFI recovery together with diagnostics.") + +assert( + !(use_sanitizer_coverage && is_mac && target_os == "ios"), + "crbug.com/753445: use_sanitizer_coverage=true is not supported by the " + + "Chromium mac_clang_x64 toolchain on iOS distribution. Please set " + + "the argument value to false.") + +# Use these lists of configs to disable instrumenting code that is part of a +# fuzzer, but which isn't being targeted (such as libprotobuf-mutator, *.pb.cc +# and libprotobuf when they are built as part of a proto fuzzer). Adding or +# removing these lists does not have any effect if use_libfuzzer or use_afl are +# not passed as arguments to gn. +not_fuzzed_remove_configs = [] +not_fuzzed_remove_nonasan_configs = [] + +if (use_fuzzing_engine) { + # Removing coverage should always just work. + not_fuzzed_remove_configs += + [ "$build_root/config/coverage:default_coverage" ] + not_fuzzed_remove_nonasan_configs += + [ "$build_root/config/coverage:default_coverage" ] + + if (!is_msan) { + # Allow sanitizer instrumentation to be removed if we are not using MSan + # since binaries cannot be partially instrumented with MSan. + not_fuzzed_remove_configs += + [ "$build_root/config/sanitizers:default_sanitizer_flags" ] + + # Certain parts of binaries must be instrumented with ASan if the rest of + # the binary is. For these, only remove non-ASan sanitizer instrumentation. + if (!is_asan) { + not_fuzzed_remove_nonasan_configs += + [ "$build_root/config/sanitizers:default_sanitizer_flags" ] + assert(not_fuzzed_remove_nonasan_configs == not_fuzzed_remove_configs) + } + } +} + +template("ohos_sanitizer_config") { + config(target_name) { + forward_variables_from(invoker, + [ + "cfi", + "scs", + "scudo", + "ubsan", + "boundary_sanitize", + "integer_overflow_sanitize", + ]) + configs = [] + _cfi = defined(cfi) && cfi + if (_cfi) { + configs += [ "$build_root/config/sanitizers:cfi_config" ] + } + _scudo = defined(scudo) && scudo + if (_scudo) { + configs += [ "$build_root/config/sanitizers:scudo_config" ] + } + _ubsan = defined(ubsan) && ubsan + if (_ubsan) { + configs += + [ "$build_root/config/sanitizers:undefined_behavior_sanitize_config" ] + } + _integer_sanitize = + defined(integer_overflow_sanitize) && integer_overflow_sanitize + if (_integer_sanitize) { + configs += [ "$build_root/config/sanitizers:integer_overflow_config" ] + } + _scs = defined(scs) && scs + if (_scs) { + configs += [ "$build_root/config/sanitizers:shadow_call_stack_config" ] + } + _boundary_sanitize = defined(boundary_sanitize) && boundary_sanitize + if (_boundary_sanitize) { + configs += [ "$build_root/config/sanitizers:boundary_sanitize_config" ] + } + } +} diff --git a/build/core/gn/BUILD.gn b/build/core/gn/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fcf776fcec5b5e089ded3f02c0611d0479679013 --- /dev/null +++ b/build/core/gn/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ets_frontend/ts2panda/ts2abc_config.gni") +import("//ets_runtime/js_runtime_config.gni") + +print("root_out_dir=$root_out_dir") +print("root_build_dir=$root_build_dir") +print("root_gen_dir=$root_gen_dir") +print("current_toolchain=$current_toolchain") +print("host_toolchain=$host_toolchain") +print("current_os=$current_os, current_cpu=$current_cpu") +print("host_os=$host_os, host_cpu=$host_cpu") +print("target_os=$target_os, target_cpu=$target_cpu") + +print() + +group("ark_js_packages") { + deps = [ "//ets_runtime/ecmascript/js_vm:ark_js_vm" ] +} + +group("ark_es2abc") { + deps = [ "//ets_frontend/es2panda:es2panda" ] +} diff --git a/build/prebuilts_download/prebuilts_download.py b/build/prebuilts_download/prebuilts_download.py new file mode 100644 index 0000000000000000000000000000000000000000..179d265c02a2c6d0b78b10004c8d491d68e2b4d8 --- /dev/null +++ b/build/prebuilts_download/prebuilts_download.py @@ -0,0 +1,257 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import argparse +import subprocess +import tarfile +import zipfile +import ssl +import shutil +from multiprocessing import cpu_count +from concurrent.futures import ThreadPoolExecutor, as_completed +from functools import partial +from urllib.request import urlopen +import urllib.error +from rich.progress import ( + BarColumn, + DownloadColumn, + Progress, + TaskID, + TextColumn, + TimeRemainingColumn, + TransferSpeedColumn, +) +from util import read_json_file + +progress = Progress( + TextColumn("[bold blue]{task.fields[filename]}", justify="right"), + BarColumn(bar_width=None), + "[progress.percentage]{task.percentage:>3.1f}%", + "•", + DownloadColumn(), + "•", + TransferSpeedColumn(), + "•", + TimeRemainingColumn(), +) + +def _run_cmd(cmd): + res = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + sout, serr = res.communicate() + return sout.rstrip().decode('utf-8'), serr, res.returncode + +def _check_sha256(check_url, local_file): + check_sha256_cmd = ''.join(['curl -s -k ', check_url, '.sha256']) + local_sha256_cmd = ''.join(['sha256sum ', local_file, "|cut -d ' ' -f1"]) + check_sha256, err, returncode = _run_cmd(check_sha256_cmd) + local_sha256, err, returncode = _run_cmd(local_sha256_cmd) + return check_sha256 == local_sha256 + +def _check_sha256_by_mark(args, check_url, code_dir, unzip_dir, unzip_filename): + check_sha256_cmd = ''.join(['curl -s -k ', check_url, '.sha256']) + check_sha256, err, returncode = _run_cmd(check_sha256_cmd) + mark_file_dir = os.path.join(code_dir, unzip_dir) + mark_file_name = ''.join([check_sha256, '.', unzip_filename, '.mark']) + mark_file_path = os.path.join(mark_file_dir, mark_file_name) + args.mark_file_path = mark_file_path + return os.path.exists(mark_file_path) + +def _config_parse(config, tool_repo): + unzip_dir = config.get('unzip_dir') + huaweicloud_url = ''.join([tool_repo, config.get('file_path')]) + unzip_filename = config.get('unzip_filename') + md5_huaweicloud_url_cmd = ''.join(['echo ', huaweicloud_url, "|md5sum|cut -d ' ' -f1"]) + md5_huaweicloud_url, err, returncode = _run_cmd(md5_huaweicloud_url_cmd) + bin_file = os.path.basename(huaweicloud_url) + return unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file + +def _uncompress(args, src_file, code_dir, unzip_dir, unzip_filename, mark_file_path): + dest_dir = os.path.join(code_dir, unzip_dir) + if src_file[-3:] == 'zip': + cmd = 'unzip -o {} -d {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) + elif src_file[-6:] == 'tar.gz': + cmd = 'tar -xvzf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) + else: + cmd = 'tar -xvf {} -C {};echo 0 > {}'.format(src_file, dest_dir, mark_file_path) + _run_cmd(cmd) + + # npm install + if os.path.basename(unzip_dir) == 'nodejs': + _npm_install(args, code_dir, unzip_dir, unzip_filename) + +def _copy_url(args, task_id, url, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path): + # download files + download_buffer_size = 32768 + progress.console.log('Requesting {}'.format(url)) + try: + response = urlopen(url) + except urllib.error.HTTPError as e: + progress.console.log("Failed to open {}, HTTPError: {}".format(url, e.code), style='red') + progress.update(task_id, total=int(response.info()["Content-length"])) + with open(local_file, "wb") as dest_file: + progress.start_task(task_id) + for data in iter(partial(response.read, download_buffer_size), b""): + dest_file.write(data) + progress.update(task_id, advance=len(data)) + progress.console.log("Downloaded {}".format(local_file)) + + # decompressing files + progress.console.log("Decompressing {}".format(local_file)) + _uncompress(args, local_file, code_dir, unzip_dir, unzip_filename, mark_file_path) + progress.console.log("Decompressed {}".format(local_file)) + +def _hwcloud_download(args, config, bin_dir, code_dir): + try: + cnt = cpu_count() + except: + cnt = 1 + with progress: + with ThreadPoolExecutor(max_workers=cnt) as pool: + tasks = dict() + for config_info in config: + unzip_dir, huaweicloud_url, unzip_filename, md5_huaweicloud_url, bin_file = _config_parse(config_info, + args.tool_repo) + abs_unzip_dir = os.path.join(code_dir, unzip_dir) + if not os.path.exists(abs_unzip_dir): + os.makedirs(abs_unzip_dir) + if _check_sha256_by_mark(args, huaweicloud_url, code_dir, unzip_dir, unzip_filename): + progress.console.log('{}, Sha256 markword check OK.'.format(huaweicloud_url), style='green') + if os.path.basename(abs_unzip_dir) == 'nodejs': + _npm_install(args, code_dir, unzip_dir, unzip_filename) + else: + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/*.', unzip_filename, '.mark'])) + _run_cmd(''.join(['rm -rf ', code_dir, '/', unzip_dir, '/', unzip_filename])) + local_file = os.path.join(bin_dir, ''.join([md5_huaweicloud_url, '.', bin_file])) + if os.path.exists(local_file): + if _check_sha256(huaweicloud_url, local_file): + progress.console.log('{}, Sha256 check download OK.'.format(local_file), style='green') + task = pool.submit(_uncompress, args, local_file, code_dir, unzip_dir, unzip_filename, + args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + else: + os.remove(local_file) + else: + filename = huaweicloud_url.split("/")[-1] + task_id = progress.add_task("download", filename=filename, start=False) + task = pool.submit(_copy_url, args, task_id, huaweicloud_url, local_file, code_dir, unzip_dir, + unzip_filename, args.mark_file_path) + tasks[task] = os.path.basename(huaweicloud_url) + for task in as_completed(tasks): + progress.console.log('{}, download and decompress completed'.format(tasks.get(task)), style='green') + +def _npm_install(args, code_dir, unzip_dir, unzip_filename): + procs = [] + skip_ssl_cmd = '' + unsafe_perm_cmd = '' + os.environ['PATH'] = '{}/{}/{}/bin:{}'.format(code_dir, unzip_dir, unzip_filename, os.environ.get('PATH')) + for install_info in args.npm_install_config: + full_code_path = os.path.join(code_dir, install_info) + full_code_path = os.path.join(install_info) + if os.path.exists(full_code_path): + npm = '{}/{}/{}/bin/npm'.format(code_dir, unzip_dir, unzip_filename) + if args.skip_ssl: + skip_ssl_cmd = '{} config set strict-ssl false;'.format(npm) + if args.unsafe_perm: + unsafe_perm_cmd = '--unsafe-perm;' + cmd = 'cd {};{} config set registry {};{}{} cache clean -f;{} install {}'.format( + full_code_path, npm, args.npm_registry, skip_ssl_cmd, npm, npm, unsafe_perm_cmd) + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + procs.append(proc) + else: + raise Exception("{} not exist, it shouldn't happen, pls check...".format(full_code_path)) + for proc in procs: + out, err = proc.communicate() + if proc.returncode: + raise Exception(err.decode()) + +def _node_modules_copy(config, code_dir): + for config_info in config: + src_dir = os.path.join(code_dir, config_info.get('src')) + dest_dir = os.path.join(code_dir, config_info.get('dest')) + use_symlink = config_info.get('use_symlink') + if os.path.exists(os.path.dirname(dest_dir)): + shutil.rmtree(os.path.dirname(dest_dir)) + if use_symlink == 'True': + os.makedirs(os.path.dirname(dest_dir)) + os.symlink(src_dir, dest_dir) + else: + shutil.copytree(src_dir, dest_dir, symlinks=True) + +def _file_handle(config, code_dir): + for config_info in config: + src_dir = ''.join([code_dir, config_info.get('src')]) + dest_dir = ''.join([code_dir, config_info.get('dest')]) + tmp_dir = config_info.get('tmp') + symlink_src = config_info.get('symlink_src') + symlink_dest = config_info.get('symlink_dest') + if os.path.exists(src_dir): + if tmp_dir: + tmp_dir = ''.join([code_dir, tmp_dir]) + shutil.move(src_dir, tmp_dir) + cmd = 'mv {}/*.mark {}'.format(dest_dir, tmp_dir) + _run_cmd(cmd) + if os.path.exists(dest_dir): + shutil.rmtree(dest_dir) + shutil.move(tmp_dir, dest_dir) + elif symlink_src and symlink_dest: + if os.path.exists(dest_dir): + shutil.rmtree(dest_dir) + shutil.move(src_dir, dest_dir) + os.symlink(''.join([dest_dir, symlink_src]), ''.join([dest_dir, symlink_dest])) + else: + _run_cmd('chmod 755 {} -R'.format(dest_dir)) + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--skip-ssl', action='store_true', help='skip ssl authentication') + parser.add_argument('--unsafe-perm', action='store_true', help='add "--unsafe-perm" for npm install') + parser.add_argument('--tool-repo', default='https://repo.huaweicloud.com', help='prebuilt file download source') + parser.add_argument('--npm-registry', default='https://repo.huaweicloud.com/repository/npm/', + help='npm download source') + parser.add_argument('--host-cpu', help='host cpu', required=True) + parser.add_argument('--host-platform', help='host platform', required=True) + args = parser.parse_args() + args.code_dir = os.path.abspath(os.path.join(os.getcwd())) + if args.skip_ssl: + ssl._create_default_https_context = ssl._create_unverified_context + + host_platform = args.host_platform + host_cpu = args.host_cpu + tool_repo = args.tool_repo + config_file = os.path.join(args.code_dir, 'toolchain/build/prebuilts_download/prebuilts_download_config.json') + config_info = read_json_file(config_file) + args.npm_install_config = config_info.get('npm_install_path') + node_modules_copy_config = config_info.get('node_modules_copy') + file_handle_config = config_info.get('file_handle_config') + + args.bin_dir = os.path.join(args.code_dir, config_info.get('prebuilts_download_dir')) + if not os.path.exists(args.bin_dir): + os.makedirs(args.bin_dir) + copy_config = config_info.get(host_platform).get(host_cpu).get('copy_config') + if host_platform == 'linux': + linux_copy_config = config_info.get(host_platform).get(host_cpu).get('linux_copy_config') + copy_config.extend(linux_copy_config) + elif host_platform == 'darwin': + darwin_copy_config = config_info.get(host_platform).get(host_cpu).get('darwin_copy_config') + copy_config.extend(darwin_copy_config) + _hwcloud_download(args, copy_config, args.bin_dir, args.code_dir) + _file_handle(file_handle_config, args.code_dir) + _node_modules_copy(node_modules_copy_config, args.code_dir) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/prebuilts_download/prebuilts_download.sh b/build/prebuilts_download/prebuilts_download.sh new file mode 100644 index 0000000000000000000000000000000000000000..a64070cae75492862efa5bbc3efe9bd3e6c21085 --- /dev/null +++ b/build/prebuilts_download/prebuilts_download.sh @@ -0,0 +1,136 @@ +#!/bin/bash +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -e +while [ $# -gt 0 ]; do + case "$1" in + -skip-ssl|--skip-ssl) # wget、npm skip ssl check, which will allow + # hacker to get and modify data stream between server and client! + SKIP_SSL=YES + ;; + -h|--help) + HELP=YES + ;; + --tool-repo) + TOOL_REPO="$2" + shift + ;; + --tool-repo=*) + TOOL_REPO="${1#--tool-repo=}" + ;; + --npm-registry) + NPM_REGISTRY="$2" + shift + ;; + --npm-registry=*) + NPM_REGISTRY="${1#--npm-registry=}" + ;; + --trusted-host) + TRUSTED_HOST="$2" + shift + ;; + --trusted-host=*) + TRUSTED_HOST="${1#--trusted-host=}" + ;; + --pypi-url) # python package index url + PYPI_URL="$2" + shift + ;; + --pypi-url=*) + PYPI_URL="${1#--pypi-url=}" + ;; + *) + echo "$0: Warning: unsupported parameter: $1" >&2 + ;; + esac + shift +done + +case $(uname -s) in + Linux) + + host_platform=linux + ;; + Darwin) + host_platform=darwin + ;; + *) + echo "Unsupported host platform: $(uname -s)" + exit 1 +esac + +case $(uname -m) in + arm64) + + host_cpu=arm64 + ;; + *) + host_cpu=x86_64 +esac + +if [ "X${SKIP_SSL}" == "XYES" ];then + wget_ssl_check="--skip-ssl" +else + wget_ssl_check='' +fi + +if [ "X${HELP}" == "XYES" ];then + help="-h" +else + help='' +fi + +if [ ! -z "$TOOL_REPO" ];then + tool_repo="--tool-repo $TOOL_REPO" +else + tool_repo='' +fi + +if [ ! -z "$NPM_REGISTRY" ];then + npm_registry="--npm-registry $NPM_REGISTRY" +else + npm_registry='' +fi + +if [ ! -z "$TRUSTED_HOST" ];then + trusted_host=$TRUSTED_HOST +elif [ ! -z "$PYPI_URL" ];then + trusted_host=${PYPI_URL/#*:\/\//} # remove prefix part such as http:// https:// etc. + trusted_host=${trusted_host/%[:\/]*/} # remove suffix part including the port number +else + trusted_host='repo.huaweicloud.com' +fi + +if [ ! -z "$PYPI_URL" ];then + pypi_url=$PYPI_URL +else + pypi_url='http://repo.huaweicloud.com/repository/pypi/simple' +fi + +if [ $UID -ne 0 ]; then + npm_para='' +else + npm_para='--unsafe-perm' +fi + +cpu="--host-cpu $host_cpu" +platform="--host-platform $host_platform" + +script_path=$(cd $(dirname $0);pwd) +code_dir=$(dirname ${script_path}) +pip3 install --trusted-host $trusted_host -i $pypi_url rich +echo "prebuilts_download start" +python3 "${code_dir}/prebuilts_download/prebuilts_download.py" $wget_ssl_check $tool_repo $npm_registry $help $cpu $platform $npm_para +echo "prebuilts_download end" + +echo -e "\n" diff --git a/build/prebuilts_download/prebuilts_download_config.json b/build/prebuilts_download/prebuilts_download_config.json new file mode 100644 index 0000000000000000000000000000000000000000..83c57a34770e915fdff7a2b3027db38d6b1d23a7 --- /dev/null +++ b/build/prebuilts_download/prebuilts_download_config.json @@ -0,0 +1,53 @@ +{ + "prebuilts_download_dir": "../../OpenHarmony_canary_prebuilts", + "npm_install_path": ["ets_frontend/ts2panda"], + "node_modules_copy": [ + { + "src": "ets_frontend/ts2panda/node_modules", + "dest": "prebuilts/build-tools/common/ts2abc/node_modules", + "use_symlink": "True" + } + ], + "file_handle_config": [ + { + "src": "/prebuilts/clang/ohos/linux-x86_64/clang-971024-20220827", + "dest": "/prebuilts/clang/ohos/linux-x86_64/llvm", + "symlink_src": "/lib/clang/12.0.1", + "symlink_dest": "/lib/clang/current" + } + ], + "linux": { + "x86_64": { + "copy_config": [ + { + "unzip_dir": "prebuilts/build-tools/linux-x86/bin", + "file_path": "/openharmony/compiler/gn/1717/linux/gn-linux-x86-1717.tar.gz", + "unzip_filename": "gn" + }, + { + "unzip_dir": "prebuilts/build-tools/linux-x86/bin", + "file_path": "/openharmony/compiler/ninja/1.10.1/linux/ninja-linux-x86-1.10.1.tar.gz", + "unzip_filename": "ninja" + }, + { + "unzip_dir": "prebuilts/ark_tools", + "file_path": "/openharmony/compiler/llvm_prebuilt_libs/ark_js_prebuilts_20220815.tar.gz", + "unzip_filename": "ark_js_prebuilts" + }, + { + "unzip_dir": "prebuilts/build-tools/common/nodejs", + "file_path": "/nodejs/v12.18.4/node-v12.18.4-linux-x64.tar.gz", + "unzip_filename": "node-v12.18.4-linux-x64" + } + ], + "linux_copy_config": [ + { + "unzip_dir": "prebuilts/clang/ohos/linux-x86_64", + "file_path": "/openharmony/compiler/clang/12.0.1-971024/linux/clang-971024-linux-x86_64-20220827.tar.bz2", + "unzip_filename": "llvm" + } + ] + } + } +} + diff --git a/build/prebuilts_download/util.py b/build/prebuilts_download/util.py new file mode 100644 index 0000000000000000000000000000000000000000..7f76be108eb8367b0ac9f84ca20a8b8dbe2be084 --- /dev/null +++ b/build/prebuilts_download/util.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import os +import subprocess +import hashlib + + +# Read json file data +def read_json_file(input_file): + if not os.path.exists(input_file): + print("file '{}' doesn't exist.".format(input_file)) + return None + + data = None + try: + with open(input_file, 'r') as input_f: + data = json.load(input_f) + except json.decoder.JSONDecodeError: + print("The file '{}' format is incorrect.".format(input_file)) + raise + except: # noqa E722 + print("read file '{}' failed.".format(input_file)) + raise + return data + + +# Read file by line +def read_file(input_file): + if not os.path.exists(input_file): + print("file '{}' doesn't exist.".format(input_file)) + return None + + data = [] + try: + with open(input_file, 'r') as file_obj: + for line in file_obj.readlines(): + data.append(line.rstrip('\n')) + except: # noqa E722 + print("read file '{}' failed".format(input_file)) + raise + return data + + +# Write json file data +def write_json_file(output_file, content, check_changes=False): + file_dir = os.path.dirname(os.path.abspath(output_file)) + if not os.path.exists(file_dir): + os.makedirs(file_dir, exist_ok=True) + + if check_changes is True: + changed = __check_changes(output_file, content) + else: + changed = True + if changed is True: + with open(output_file, 'w') as output_f: + json.dump(content, output_f, sort_keys=True, indent=2) + + +def __check_changes(output_file, content): + if os.path.exists(output_file) and os.path.isfile(output_file): + # file content md5 val + sha256_obj = hashlib.sha256() + sha256_obj.update(str(read_json_file(output_file)).encode()) + hash_value = sha256_obj.hexdigest() + # new content md5 val + sha256_obj_new = hashlib.sha256() + sha256_obj_new.update(str(content).encode()) + hash_value_new = sha256_obj_new.hexdigest() + if hash_value_new == hash_value: + return False + return True + + +# Write file data +def write_file(output_file, content): + file_dir = os.path.dirname(os.path.abspath(output_file)) + if not os.path.exists(file_dir): + os.makedirs(file_dir, exist_ok=True) + + with open(output_file, 'w') as output_f: + output_f.write(content) + if output_file.endswith('.gni') or output_file.endswith('.gn'): + # Call gn format to make the output gn file prettier. + cmd = ['gn', 'format'] + cmd.append(output_file) + subprocess.check_output(cmd) diff --git a/build/preconfig_ubuntu.md b/build/preconfig_ubuntu.md new file mode 100644 index 0000000000000000000000000000000000000000..726135880ef9398d6436772baa2979883f7f28d2 --- /dev/null +++ b/build/preconfig_ubuntu.md @@ -0,0 +1,32 @@ +# 获取源码及安装依赖工具 +## 推荐操作系统Ubuntu18及以上 +## 安装repo工具 + +安装码云repo工具,由于权限可切换到root用户下安装,安装后再切换个人用户目录操作 + +``` +curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo +chmod a+x /usr/local/bin/repo +pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests +``` + +## 下载源码 +``` +repo init -u https://gitee.com/lordwithcc/manifest.git -b Ark_Standalone_Build +repo sync -c +repo forall -c 'git lfs pull' +``` + +## 编译环境准备 + +安装依赖工具 +``` +sudo apt-get update && sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev genext2fs liblz4-tool libssl-dev libtinfo5 lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby default-jdk u-boot-tools mtools mtd-utils scons gcc-arm-none-eabi gcc-arm-linux-gnueabi +``` + +安装编译器及二进制工具 +``` +cd arkcompiler +./toolchain/build/compile_script/gen.sh ark +./toolchain/build/prebuilts_download/prebuilts_download.sh +``` diff --git a/build/templates/cxx/cxx.gni b/build/templates/cxx/cxx.gni new file mode 100755 index 0000000000000000000000000000000000000000..5c232d0a23497c6d885536f5bcf8b16861d5018d --- /dev/null +++ b/build/templates/cxx/cxx.gni @@ -0,0 +1,135 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +template("ohos_executable") { + executable(target_name) { + forward_variables_from(invoker, + "*", + [ + "configs", + "remove_configs", + "subsystem_name", + "install_enable", + "part_name", + "use_exceptions", + "static_link", + "output_dir", + ]) + if (defined(invoker.subsystem_name) && defined(invoker.part_name)) { + subsystem_name = invoker.subsystem_name + part_name = invoker.part_name + } else if (defined(invoker.part_name)) { + part_name = invoker.part_name + _part_subsystem_info_file = + "$root_build_dir/build_configs/parts_info/part_subsystem.json" + _arguments = [ + "--part-name", + part_name, + "--part-subsystem-info-file", + rebase_path(_part_subsystem_info_file, root_build_dir), + ] + get_subsystem_script = "//build/templates/common/get_subsystem_name.py" + subsystem_name = + exec_script(get_subsystem_script, _arguments, "trim string") + } else if (defined(invoker.subsystem_name)) { + subsystem_name = invoker.subsystem_name + part_name = subsystem_name + } else { + subsystem_name = "common" + part_name = subsystem_name + } + if (is_standard_system) { + output_dir = "${root_out_dir}/${subsystem_name}/${part_name}" + } else { + output_dir = "${root_out_dir}" + } + if (defined(invoker.configs)) { + configs += invoker.configs + } + + if (defined(invoker.remove_configs)) { + configs -= invoker.remove_configs + } + + if (defined(invoker.use_exceptions) && invoker.use_exceptions) { + configs += [ "//toolchain/build/config/compiler:exceptions" ] + } + } +} +template("ohos_static_library") { + static_library(target_name) { + forward_variables_from(invoker, + "*", + [ + "configs", + "remove_configs", + "subsystem_name", + "part_name", + "use_exceptions", + "external_deps", + ]) + if (defined(invoker.configs)) { + configs += invoker.configs + } + + if (defined(invoker.remove_configs)) { + configs -= invoker.remove_configs + } + + if (defined(invoker.use_exceptions) && invoker.use_exceptions) { + configs += [ "//toolchain/build/config/compiler:exceptions" ] + } + } +} +template("ohos_shared_library") { + shared_library(target_name) { + forward_variables_from(invoker, + "*", + [ + "relative_install_dir", + "subsystem_name", + "install_enable", + "part_name", + "install_images", + "use_exceptions", + "external_deps", + ]) + } +} + +template("ohos_copy") { + copy(target_name) { + forward_variables_from(invoker, + "*", + [ + "module_source_dir", + "module_install_name", + ]) + } +} + +template("ohos_source_set") { + source_set(target_name) { + forward_variables_from(invoker, + "*", + [ + "configs", + "remove_configs", + "no_default_deps", + "external_deps", + "license_file", + "license_as_sources", + "use_exceptions", + ]) + } +} diff --git a/build/third_party_gn/bounds_checking_function/BUILD.gn b/build/third_party_gn/bounds_checking_function/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8c26a0d4e3518e0253c910a55bc59c60d8a761c9 --- /dev/null +++ b/build/third_party_gn/bounds_checking_function/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//third_party/bounds_checking_function/libsec_src.gni") +import("$build_root/ark.gni") + +config("libsec_public_config") { + include_dirs = [ "//third_party/bounds_checking_function/include" ] + cflags_cc = [ "-fPIC" ] +} + +ohos_static_library("libsec_static") { + sources = libsec_sources + public_configs = [ ":libsec_public_config" ] + cflags = [ + "-D_INC_STRING_S", + "-D_INC_WCHAR_S", + "-D_SECIMP=//", + "-D_STDIO_S_DEFINED", + "-D_INC_STDIO_S", + "-D_INC_STDLIB_S", + "-D_INC_MEMORY_S", + ] +} diff --git a/build/third_party_gn/icu/icu4c/BUILD.gn b/build/third_party_gn/icu/icu4c/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2dcdd60fd08120b90823ffa52e1abbbe9b084477 --- /dev/null +++ b/build/third_party_gn/icu/icu4c/BUILD.gn @@ -0,0 +1,659 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/ark.gni") +config("icu_config") { + visibility = [ ":*" ] + include_dirs = [ + "//third_party/icu/icu4c/source/common", + "//third_party/icu/icu4c/source/i18n", + "//third_party/icu/icu4c/source", + ] + cflags_cc = [ "-fPIC" ] +} + +ohos_static_library("static_icustubdata") { + configs = [ + ":icu_config", + "$build_root/config/compiler:rtti", + ] + sources = [ "//third_party/icu/icu4c/source/stubdata/stubdata.cpp" ] + + cflags_cc = [ + "-O3", + "-W", + "-Wall", + "-pedantic", + "-Wpointer-arith", + "-Wwrite-strings", + "-std=c++11", + "-Wno-ignored-attributes", + ] + output_dir = "${root_out_dir}/third_party/icu/stubdata" + output_name = "stubdata" +} + +icu_common_source = [ + "//third_party/icu/icu4c/source/common/ubiditransform.cpp", + "//third_party/icu/icu4c/source/common/locutil.cpp", + "//third_party/icu/icu4c/source/common/cstring.cpp", + "//third_party/icu/icu4c/source/common/rbbiscan.cpp", + "//third_party/icu/icu4c/source/common/utrie.cpp", + "//third_party/icu/icu4c/source/common/cwchar.cpp", + "//third_party/icu/icu4c/source/common/bytestriebuilder.cpp", + "//third_party/icu/icu4c/source/common/umapfile.cpp", + "//third_party/icu/icu4c/source/common/uenum.cpp", + "//third_party/icu/icu4c/source/common/putil.cpp", + "//third_party/icu/icu4c/source/common/bytestrieiterator.cpp", + "//third_party/icu/icu4c/source/common/unifunct.cpp", + "//third_party/icu/icu4c/source/common/rbbistbl.cpp", + "//third_party/icu/icu4c/source/common/bytestrie.cpp", + "//third_party/icu/icu4c/source/common/ucptrie.cpp", + "//third_party/icu/icu4c/source/common/errorcode.cpp", + "//third_party/icu/icu4c/source/common/unames.cpp", + "//third_party/icu/icu4c/source/common/restrace.cpp", + "//third_party/icu/icu4c/source/common/util.cpp", + "//third_party/icu/icu4c/source/common/sharedobject.cpp", + "//third_party/icu/icu4c/source/common/bmpset.cpp", + "//third_party/icu/icu4c/source/common/servlk.cpp", + "//third_party/icu/icu4c/source/common/ustrcase_locale.cpp", + "//third_party/icu/icu4c/source/common/localeprioritylist.cpp", + "//third_party/icu/icu4c/source/common/ucnvbocu.cpp", + "//third_party/icu/icu4c/source/common/ucharstrieiterator.cpp", + "//third_party/icu/icu4c/source/common/unisetspan.cpp", + "//third_party/icu/icu4c/source/common/locavailable.cpp", + "//third_party/icu/icu4c/source/common/unistr.cpp", + "//third_party/icu/icu4c/source/common/ustr_wcs.cpp", + "//third_party/icu/icu4c/source/common/ucnv_err.cpp", + "//third_party/icu/icu4c/source/common/ucnv_lmb.cpp", + "//third_party/icu/icu4c/source/common/rbbidata.cpp", + "//third_party/icu/icu4c/source/common/uarrsort.cpp", + "//third_party/icu/icu4c/source/common/ucnv2022.cpp", + "//third_party/icu/icu4c/source/common/uresbund.cpp", + "//third_party/icu/icu4c/source/common/ucnvsel.cpp", + "//third_party/icu/icu4c/source/common/unistr_titlecase_brkiter.cpp", + "//third_party/icu/icu4c/source/common/loadednormalizer2impl.cpp", + "//third_party/icu/icu4c/source/common/ustring.cpp", + "//third_party/icu/icu4c/source/common/unifilt.cpp", + "//third_party/icu/icu4c/source/common/ubrk.cpp", + "//third_party/icu/icu4c/source/common/bytesinkutil.cpp", + "//third_party/icu/icu4c/source/common/localebuilder.cpp", + "//third_party/icu/icu4c/source/common/rbbi_cache.cpp", + "//third_party/icu/icu4c/source/common/ucnvhz.cpp", + "//third_party/icu/icu4c/source/common/uniset_closure.cpp", + "//third_party/icu/icu4c/source/common/uloc.cpp", + "//third_party/icu/icu4c/source/common/utypes.cpp", + "//third_party/icu/icu4c/source/common/ucnv_u16.cpp", + "//third_party/icu/icu4c/source/common/uniset_props.cpp", + "//third_party/icu/icu4c/source/common/locbased.cpp", + "//third_party/icu/icu4c/source/common/unistr_cnv.cpp", + "//third_party/icu/icu4c/source/common/ucnv_ct.cpp", + "//third_party/icu/icu4c/source/common/unormcmp.cpp", + "//third_party/icu/icu4c/source/common/wintz.cpp", + "//third_party/icu/icu4c/source/common/ruleiter.cpp", + "//third_party/icu/icu4c/source/common/utrie2.cpp", + "//third_party/icu/icu4c/source/common/locresdata.cpp", + "//third_party/icu/icu4c/source/common/ucnv_u8.cpp", + "//third_party/icu/icu4c/source/common/uscript_props.cpp", + "//third_party/icu/icu4c/source/common/locdspnm.cpp", + "//third_party/icu/icu4c/source/common/locid.cpp", + "//third_party/icu/icu4c/source/common/rbbitblb.cpp", + "//third_party/icu/icu4c/source/common/icudataver.cpp", + "//third_party/icu/icu4c/source/common/ubidi.cpp", + "//third_party/icu/icu4c/source/common/brkiter.cpp", + "//third_party/icu/icu4c/source/common/uvectr32.cpp", + "//third_party/icu/icu4c/source/common/usc_impl.cpp", + "//third_party/icu/icu4c/source/common/normlzr.cpp", + "//third_party/icu/icu4c/source/common/icuplug.cpp", + "//third_party/icu/icu4c/source/common/uvector.cpp", + "//third_party/icu/icu4c/source/common/ucnv_set.cpp", + "//third_party/icu/icu4c/source/common/udataswp.cpp", + "//third_party/icu/icu4c/source/common/uhash_us.cpp", + "//third_party/icu/icu4c/source/common/rbbisetb.cpp", + "//third_party/icu/icu4c/source/common/ubidi_props.cpp", + "//third_party/icu/icu4c/source/common/ucmndata.cpp", + "//third_party/icu/icu4c/source/common/locdistance.cpp", + "//third_party/icu/icu4c/source/common/serv.cpp", + "//third_party/icu/icu4c/source/common/utrie_swap.cpp", + "//third_party/icu/icu4c/source/common/uchar.cpp", + "//third_party/icu/icu4c/source/common/uloc_tag.cpp", + "//third_party/icu/icu4c/source/common/ustr_titlecase_brkiter.cpp", + "//third_party/icu/icu4c/source/common/pluralmap.cpp", + "//third_party/icu/icu4c/source/common/lsr.cpp", + "//third_party/icu/icu4c/source/common/uhash.cpp", + "//third_party/icu/icu4c/source/common/propname.cpp", + "//third_party/icu/icu4c/source/common/ucnvlat1.cpp", + "//third_party/icu/icu4c/source/common/ucnv_ext.cpp", + "//third_party/icu/icu4c/source/common/ubidiln.cpp", + "//third_party/icu/icu4c/source/common/ucnv_cb.cpp", + "//third_party/icu/icu4c/source/common/static_unicode_sets.cpp", + "//third_party/icu/icu4c/source/common/dictbe.cpp", + "//third_party/icu/icu4c/source/common/stringtriebuilder.cpp", + "//third_party/icu/icu4c/source/common/uvectr64.cpp", + "//third_party/icu/icu4c/source/common/patternprops.cpp", + "//third_party/icu/icu4c/source/common/propsvec.cpp", + "//third_party/icu/icu4c/source/common/ustrenum.cpp", + "//third_party/icu/icu4c/source/common/ucnv_u32.cpp", + "//third_party/icu/icu4c/source/common/ustr_cnv.cpp", + "//third_party/icu/icu4c/source/common/edits.cpp", + "//third_party/icu/icu4c/source/common/loclikely.cpp", + "//third_party/icu/icu4c/source/common/parsepos.cpp", + "//third_party/icu/icu4c/source/common/loclikelysubtags.cpp", + "//third_party/icu/icu4c/source/common/uloc_keytype.cpp", + "//third_party/icu/icu4c/source/common/appendable.cpp", + "//third_party/icu/icu4c/source/common/filteredbrk.cpp", + "//third_party/icu/icu4c/source/common/ucharstrie.cpp", + "//third_party/icu/icu4c/source/common/uiter.cpp", + "//third_party/icu/icu4c/source/common/messagepattern.cpp", + "//third_party/icu/icu4c/source/common/servrbf.cpp", + "//third_party/icu/icu4c/source/common/rbbirb.cpp", + "//third_party/icu/icu4c/source/common/uinit.cpp", + "//third_party/icu/icu4c/source/common/stringpiece.cpp", + "//third_party/icu/icu4c/source/common/normalizer2impl.cpp", + "//third_party/icu/icu4c/source/common/ucharstriebuilder.cpp", + "//third_party/icu/icu4c/source/common/uobject.cpp", + "//third_party/icu/icu4c/source/common/ushape.cpp", + "//third_party/icu/icu4c/source/common/ucasemap.cpp", + "//third_party/icu/icu4c/source/common/uinvchar.cpp", + "//third_party/icu/icu4c/source/common/utf_impl.cpp", + "//third_party/icu/icu4c/source/common/ustack.cpp", + "//third_party/icu/icu4c/source/common/characterproperties.cpp", + "//third_party/icu/icu4c/source/common/rbbi.cpp", + "//third_party/icu/icu4c/source/common/ucasemap_titlecase_brkiter.cpp", + "//third_party/icu/icu4c/source/common/caniter.cpp", + "//third_party/icu/icu4c/source/common/ucnv_bld.cpp", + "//third_party/icu/icu4c/source/common/ucln_cmn.cpp", + "//third_party/icu/icu4c/source/common/chariter.cpp", + "//third_party/icu/icu4c/source/common/punycode.cpp", + "//third_party/icu/icu4c/source/common/ustrtrns.cpp", + "//third_party/icu/icu4c/source/common/ucnvmbcs.cpp", + "//third_party/icu/icu4c/source/common/bytestream.cpp", + "//third_party/icu/icu4c/source/common/servlkf.cpp", + "//third_party/icu/icu4c/source/common/udatamem.cpp", + "//third_party/icu/icu4c/source/common/ucnv_io.cpp", + "//third_party/icu/icu4c/source/common/dtintrv.cpp", + "//third_party/icu/icu4c/source/common/cstr.cpp", + "//third_party/icu/icu4c/source/common/ulist.cpp", + "//third_party/icu/icu4c/source/common/ucnvisci.cpp", + "//third_party/icu/icu4c/source/common/brkeng.cpp", + "//third_party/icu/icu4c/source/common/localematcher.cpp", + "//third_party/icu/icu4c/source/common/umutablecptrie.cpp", + "//third_party/icu/icu4c/source/common/locdispnames.cpp", + "//third_party/icu/icu4c/source/common/uchriter.cpp", + "//third_party/icu/icu4c/source/common/uresdata.cpp", + "//third_party/icu/icu4c/source/common/unifiedcache.cpp", + "//third_party/icu/icu4c/source/common/dictionarydata.cpp", + "//third_party/icu/icu4c/source/common/uscript.cpp", + "//third_party/icu/icu4c/source/common/ucnv_u7.cpp", + "//third_party/icu/icu4c/source/common/unistr_case.cpp", + "//third_party/icu/icu4c/source/common/ucat.cpp", + "//third_party/icu/icu4c/source/common/resource.cpp", + "//third_party/icu/icu4c/source/common/usprep.cpp", + "//third_party/icu/icu4c/source/common/ucnvdisp.cpp", + "//third_party/icu/icu4c/source/common/uniset.cpp", + "//third_party/icu/icu4c/source/common/ucnv.cpp", + "//third_party/icu/icu4c/source/common/ucnvscsu.cpp", + "//third_party/icu/icu4c/source/common/uset_props.cpp", + "//third_party/icu/icu4c/source/common/umutex.cpp", + "//third_party/icu/icu4c/source/common/ucnv_cnv.cpp", + "//third_party/icu/icu4c/source/common/locmap.cpp", + "//third_party/icu/icu4c/source/common/resbund.cpp", + "//third_party/icu/icu4c/source/common/filterednormalizer2.cpp", + "//third_party/icu/icu4c/source/common/uprops.cpp", + "//third_party/icu/icu4c/source/common/schriter.cpp", + "//third_party/icu/icu4c/source/common/simpleformatter.cpp", + "//third_party/icu/icu4c/source/common/uts46.cpp", + "//third_party/icu/icu4c/source/common/ucol_swp.cpp", + "//third_party/icu/icu4c/source/common/udata.cpp", + "//third_party/icu/icu4c/source/common/ustrfmt.cpp", + "//third_party/icu/icu4c/source/common/servslkf.cpp", + "//third_party/icu/icu4c/source/common/servls.cpp", + "//third_party/icu/icu4c/source/common/unistr_props.cpp", + "//third_party/icu/icu4c/source/common/utrace.cpp", + "//third_party/icu/icu4c/source/common/utrie2_builder.cpp", + "//third_party/icu/icu4c/source/common/ucase.cpp", + "//third_party/icu/icu4c/source/common/cmemory.cpp", + "//third_party/icu/icu4c/source/common/uset.cpp", + "//third_party/icu/icu4c/source/common/unistr_case_locale.cpp", + "//third_party/icu/icu4c/source/common/ures_cnv.cpp", + "//third_party/icu/icu4c/source/common/charstr.cpp", + "//third_party/icu/icu4c/source/common/uidna.cpp", + "//third_party/icu/icu4c/source/common/normalizer2.cpp", + "//third_party/icu/icu4c/source/common/resbund_cnv.cpp", + "//third_party/icu/icu4c/source/common/umath.cpp", + "//third_party/icu/icu4c/source/common/utext.cpp", + "//third_party/icu/icu4c/source/common/ucurr.cpp", + "//third_party/icu/icu4c/source/common/util_props.cpp", + "//third_party/icu/icu4c/source/common/unorm.cpp", + "//third_party/icu/icu4c/source/common/ubidiwrt.cpp", + "//third_party/icu/icu4c/source/common/usetiter.cpp", + "//third_party/icu/icu4c/source/common/rbbinode.cpp", + "//third_party/icu/icu4c/source/common/ustrcase.cpp", + "//third_party/icu/icu4c/source/common/servnotf.cpp", + "//third_party/icu/icu4c/source/ohos/init_data.cpp", +] + +icu_i18n_source = [ + "//third_party/icu/icu4c/source/i18n/number_capi.cpp", + "//third_party/icu/icu4c/source/i18n/upluralrules.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_currency.cpp", + "//third_party/icu/icu4c/source/i18n/ufieldpositer.cpp", + "//third_party/icu/icu4c/source/i18n/number_output.cpp", + "//third_party/icu/icu4c/source/i18n/number_currencysymbols.cpp", + "//third_party/icu/icu4c/source/i18n/curramt.cpp", + "//third_party/icu/icu4c/source/i18n/alphaindex.cpp", + "//third_party/icu/icu4c/source/i18n/indiancal.cpp", + "//third_party/icu/icu4c/source/i18n/dayperiodrules.cpp", + "//third_party/icu/icu4c/source/i18n/quantityformatter.cpp", + "//third_party/icu/icu4c/source/i18n/collationfastlatinbuilder.cpp", + "//third_party/icu/icu4c/source/i18n/csrucode.cpp", + "//third_party/icu/icu4c/source/i18n/measunit_extra.cpp", + "//third_party/icu/icu4c/source/i18n/ethpccal.cpp", + "//third_party/icu/icu4c/source/i18n/anytrans.cpp", + "//third_party/icu/icu4c/source/i18n/number_scientific.cpp", + "//third_party/icu/icu4c/source/i18n/cpdtrans.cpp", + "//third_party/icu/icu4c/source/i18n/regexst.cpp", + "//third_party/icu/icu4c/source/i18n/numfmt.cpp", + "//third_party/icu/icu4c/source/i18n/formattedvalue.cpp", + "//third_party/icu/icu4c/source/i18n/unesctrn.cpp", + "//third_party/icu/icu4c/source/i18n/ucoleitr.cpp", + "//third_party/icu/icu4c/source/i18n/tmutamt.cpp", + "//third_party/icu/icu4c/source/i18n/transreg.cpp", + "//third_party/icu/icu4c/source/i18n/unum.cpp", + "//third_party/icu/icu4c/source/i18n/number_longnames.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_affixes.cpp", + "//third_party/icu/icu4c/source/i18n/plurrule.cpp", + "//third_party/icu/icu4c/source/i18n/zrule.cpp", + "//third_party/icu/icu4c/source/i18n/collationrootelements.cpp", + "//third_party/icu/icu4c/source/i18n/currunit.cpp", + "//third_party/icu/icu4c/source/i18n/funcrepl.cpp", + "//third_party/icu/icu4c/source/i18n/collationdatareader.cpp", + "//third_party/icu/icu4c/source/i18n/buddhcal.cpp", + "//third_party/icu/icu4c/source/i18n/number_decimalquantity.cpp", + "//third_party/icu/icu4c/source/i18n/scriptset.cpp", + "//third_party/icu/icu4c/source/i18n/fmtable.cpp", + "//third_party/icu/icu4c/source/i18n/regextxt.cpp", + "//third_party/icu/icu4c/source/i18n/bocsu.cpp", + "//third_party/icu/icu4c/source/i18n/olsontz.cpp", + "//third_party/icu/icu4c/source/i18n/utmscale.cpp", + "//third_party/icu/icu4c/source/i18n/ucol.cpp", + "//third_party/icu/icu4c/source/i18n/currfmt.cpp", + "//third_party/icu/icu4c/source/i18n/hebrwcal.cpp", + "//third_party/icu/icu4c/source/i18n/ucol_sit.cpp", + "//third_party/icu/icu4c/source/i18n/rbnf.cpp", + "//third_party/icu/icu4c/source/i18n/decContext.cpp", + "//third_party/icu/icu4c/source/i18n/collationdatawriter.cpp", + "//third_party/icu/icu4c/source/i18n/csr2022.cpp", + "//third_party/icu/icu4c/source/i18n/dtrule.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_validators.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_parsednumber.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-fast-dtoa.cpp", + "//third_party/icu/icu4c/source/i18n/choicfmt.cpp", + "//third_party/icu/icu4c/source/i18n/format.cpp", + "//third_party/icu/icu4c/source/i18n/reldatefmt.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-double-to-string.cpp", + "//third_party/icu/icu4c/source/i18n/rbt_data.cpp", + "//third_party/icu/icu4c/source/i18n/smpdtfmt.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-bignum-dtoa.cpp", + "//third_party/icu/icu4c/source/i18n/number_padding.cpp", + "//third_party/icu/icu4c/source/i18n/vtzone.cpp", + "//third_party/icu/icu4c/source/i18n/region.cpp", + "//third_party/icu/icu4c/source/i18n/coptccal.cpp", + "//third_party/icu/icu4c/source/i18n/datefmt.cpp", + "//third_party/icu/icu4c/source/i18n/formatted_string_builder.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_impl.cpp", + "//third_party/icu/icu4c/source/i18n/plurfmt.cpp", + "//third_party/icu/icu4c/source/i18n/rematch.cpp", + "//third_party/icu/icu4c/source/i18n/simpletz.cpp", + "//third_party/icu/icu4c/source/i18n/search.cpp", + "//third_party/icu/icu4c/source/i18n/number_mapper.cpp", + "//third_party/icu/icu4c/source/i18n/inputext.cpp", + "//third_party/icu/icu4c/source/i18n/dtptngen.cpp", + "//third_party/icu/icu4c/source/i18n/coleitr.cpp", + "//third_party/icu/icu4c/source/i18n/collationweights.cpp", + "//third_party/icu/icu4c/source/i18n/number_modifiers.cpp", + "//third_party/icu/icu4c/source/i18n/scientificnumberformatter.cpp", + "//third_party/icu/icu4c/source/i18n/vzone.cpp", + "//third_party/icu/icu4c/source/i18n/fphdlimp.cpp", + "//third_party/icu/icu4c/source/i18n/udatpg.cpp", + "//third_party/icu/icu4c/source/i18n/collationfcd.cpp", + "//third_party/icu/icu4c/source/i18n/tridpars.cpp", + "//third_party/icu/icu4c/source/i18n/csmatch.cpp", + "//third_party/icu/icu4c/source/i18n/dangical.cpp", + "//third_party/icu/icu4c/source/i18n/ulocdata.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-strtod.cpp", + "//third_party/icu/icu4c/source/i18n/erarules.cpp", + "//third_party/icu/icu4c/source/i18n/numsys.cpp", + "//third_party/icu/icu4c/source/i18n/csdetect.cpp", + "//third_party/icu/icu4c/source/i18n/japancal.cpp", + "//third_party/icu/icu4c/source/i18n/collation.cpp", + "//third_party/icu/icu4c/source/i18n/uregex.cpp", + "//third_party/icu/icu4c/source/i18n/timezone.cpp", + "//third_party/icu/icu4c/source/i18n/strmatch.cpp", + "//third_party/icu/icu4c/source/i18n/decNumber.cpp", + "//third_party/icu/icu4c/source/i18n/nortrans.cpp", + "//third_party/icu/icu4c/source/i18n/sortkey.cpp", + "//third_party/icu/icu4c/source/i18n/ulistformatter.cpp", + "//third_party/icu/icu4c/source/i18n/tzgnames.cpp", + "//third_party/icu/icu4c/source/i18n/number_multiplier.cpp", + "//third_party/icu/icu4c/source/i18n/ztrans.cpp", + "//third_party/icu/icu4c/source/i18n/persncal.cpp", + "//third_party/icu/icu4c/source/i18n/number_utils.cpp", + "//third_party/icu/icu4c/source/i18n/csrmbcs.cpp", + "//third_party/icu/icu4c/source/i18n/taiwncal.cpp", + "//third_party/icu/icu4c/source/i18n/dtitvinf.cpp", + "//third_party/icu/icu4c/source/i18n/astro.cpp", + "//third_party/icu/icu4c/source/i18n/number_patternmodifier.cpp", + "//third_party/icu/icu4c/source/i18n/rulebasedcollator.cpp", + "//third_party/icu/icu4c/source/i18n/msgfmt.cpp", + "//third_party/icu/icu4c/source/i18n/stsearch.cpp", + "//third_party/icu/icu4c/source/i18n/number_affixutils.cpp", + "//third_party/icu/icu4c/source/i18n/quant.cpp", + "//third_party/icu/icu4c/source/i18n/calendar.cpp", + "//third_party/icu/icu4c/source/i18n/collationroot.cpp", + "//third_party/icu/icu4c/source/i18n/rbt_rule.cpp", + "//third_party/icu/icu4c/source/i18n/number_compact.cpp", + "//third_party/icu/icu4c/source/i18n/name2uni.cpp", + "//third_party/icu/icu4c/source/i18n/chnsecal.cpp", + "//third_party/icu/icu4c/source/i18n/csrutf8.cpp", + "//third_party/icu/icu4c/source/i18n/basictz.cpp", + "//third_party/icu/icu4c/source/i18n/reldtfmt.cpp", + "//third_party/icu/icu4c/source/i18n/nultrans.cpp", + "//third_party/icu/icu4c/source/i18n/number_grouping.cpp", + "//third_party/icu/icu4c/source/i18n/rbt_pars.cpp", + "//third_party/icu/icu4c/source/i18n/nounit.cpp", + "//third_party/icu/icu4c/source/i18n/winnmfmt.cpp", + "//third_party/icu/icu4c/source/i18n/uregexc.cpp", + "//third_party/icu/icu4c/source/i18n/fpositer.cpp", + "//third_party/icu/icu4c/source/i18n/tmutfmt.cpp", + "//third_party/icu/icu4c/source/i18n/compactdecimalformat.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_decimal.cpp", + "//third_party/icu/icu4c/source/i18n/number_notation.cpp", + "//third_party/icu/icu4c/source/i18n/uspoof_conf.cpp", + "//third_party/icu/icu4c/source/i18n/utf16collationiterator.cpp", + "//third_party/icu/icu4c/source/i18n/udat.cpp", + "//third_party/icu/icu4c/source/i18n/number_skeletons.cpp", + "//third_party/icu/icu4c/source/i18n/utrans.cpp", + "//third_party/icu/icu4c/source/i18n/number_rounding.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-bignum.cpp", + "//third_party/icu/icu4c/source/i18n/number_asformat.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-string-to-double.cpp", + "//third_party/icu/icu4c/source/i18n/rbtz.cpp", + "//third_party/icu/icu4c/source/i18n/csrsbcs.cpp", + "//third_party/icu/icu4c/source/i18n/selfmt.cpp", + "//third_party/icu/icu4c/source/i18n/tztrans.cpp", + "//third_party/icu/icu4c/source/i18n/uspoof_impl.cpp", + "//third_party/icu/icu4c/source/i18n/regeximp.cpp", + "//third_party/icu/icu4c/source/i18n/measure.cpp", + "//third_party/icu/icu4c/source/i18n/fmtable_cnv.cpp", + "//third_party/icu/icu4c/source/i18n/uspoof.cpp", + "//third_party/icu/icu4c/source/i18n/gregoimp.cpp", + "//third_party/icu/icu4c/source/i18n/umsg.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_symbols.cpp", + "//third_party/icu/icu4c/source/i18n/numrange_impl.cpp", + "//third_party/icu/icu4c/source/i18n/collationtailoring.cpp", + "//third_party/icu/icu4c/source/i18n/double-conversion-cached-powers.cpp", + "//third_party/icu/icu4c/source/i18n/udateintervalformat.cpp", + "//third_party/icu/icu4c/source/i18n/uni2name.cpp", + "//third_party/icu/icu4c/source/i18n/casetrn.cpp", + "//third_party/icu/icu4c/source/i18n/windtfmt.cpp", + "//third_party/icu/icu4c/source/i18n/listformatter.cpp", + "//third_party/icu/icu4c/source/i18n/uregion.cpp", + "//third_party/icu/icu4c/source/i18n/usearch.cpp", + "//third_party/icu/icu4c/source/i18n/brktrans.cpp", + "//third_party/icu/icu4c/source/i18n/gender.cpp", + "//third_party/icu/icu4c/source/i18n/collationruleparser.cpp", + "//third_party/icu/icu4c/source/i18n/rbt.cpp", + "//third_party/icu/icu4c/source/i18n/tzfmt.cpp", + "//third_party/icu/icu4c/source/i18n/dtfmtsym.cpp", + "//third_party/icu/icu4c/source/i18n/tolowtrn.cpp", + "//third_party/icu/icu4c/source/i18n/collationdatabuilder.cpp", + "//third_party/icu/icu4c/source/i18n/unumsys.cpp", + "//third_party/icu/icu4c/source/i18n/csrecog.cpp", + "//third_party/icu/icu4c/source/i18n/collationfastlatin.cpp", + "//third_party/icu/icu4c/source/i18n/esctrn.cpp", + "//third_party/icu/icu4c/source/i18n/collationdata.cpp", + "//third_party/icu/icu4c/source/i18n/titletrn.cpp", + "//third_party/icu/icu4c/source/i18n/ucal.cpp", + "//third_party/icu/icu4c/source/i18n/regexcmp.cpp", + "//third_party/icu/icu4c/source/i18n/wintzimpl.cpp", + "//third_party/icu/icu4c/source/i18n/decimfmt.cpp", + "//third_party/icu/icu4c/source/i18n/tmunit.cpp", + "//third_party/icu/icu4c/source/i18n/number_integerwidth.cpp", + "//third_party/icu/icu4c/source/i18n/ucsdet.cpp", + "//third_party/icu/icu4c/source/i18n/uspoof_build.cpp", + "//third_party/icu/icu4c/source/i18n/ucln_in.cpp", + "//third_party/icu/icu4c/source/i18n/measfmt.cpp", + "//third_party/icu/icu4c/source/i18n/formattedval_iterimpl.cpp", + "//third_party/icu/icu4c/source/i18n/toupptrn.cpp", + "//third_party/icu/icu4c/source/i18n/translit.cpp", + "//third_party/icu/icu4c/source/i18n/dtitvfmt.cpp", + "//third_party/icu/icu4c/source/i18n/dcfmtsym.cpp", + "//third_party/icu/icu4c/source/i18n/islamcal.cpp", + "//third_party/icu/icu4c/source/i18n/numrange_fluent.cpp", + "//third_party/icu/icu4c/source/i18n/gregocal.cpp", + "//third_party/icu/icu4c/source/i18n/zonemeta.cpp", + "//third_party/icu/icu4c/source/i18n/collationbuilder.cpp", + "//third_party/icu/icu4c/source/i18n/string_segment.cpp", + "//third_party/icu/icu4c/source/i18n/collationkeys.cpp", + "//third_party/icu/icu4c/source/i18n/coll.cpp", + "//third_party/icu/icu4c/source/i18n/uitercollationiterator.cpp", + "//third_party/icu/icu4c/source/i18n/nfsubs.cpp", + "//third_party/icu/icu4c/source/i18n/smpdtfst.cpp", + "//third_party/icu/icu4c/source/i18n/collationsettings.cpp", + "//third_party/icu/icu4c/source/i18n/formattedval_sbimpl.cpp", + "//third_party/icu/icu4c/source/i18n/strrepl.cpp", + "//third_party/icu/icu4c/source/i18n/standardplural.cpp", + "//third_party/icu/icu4c/source/i18n/ucol_res.cpp", + "//third_party/icu/icu4c/source/i18n/repattrn.cpp", + "//third_party/icu/icu4c/source/i18n/tznames_impl.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_compositions.cpp", + "//third_party/icu/icu4c/source/i18n/rbt_set.cpp", + "//third_party/icu/icu4c/source/i18n/currpinf.cpp", + "//third_party/icu/icu4c/source/i18n/collationsets.cpp", + "//third_party/icu/icu4c/source/i18n/cecal.cpp", + "//third_party/icu/icu4c/source/i18n/tzrule.cpp", + "//third_party/icu/icu4c/source/i18n/collationiterator.cpp", + "//third_party/icu/icu4c/source/i18n/numparse_scientific.cpp", + "//third_party/icu/icu4c/source/i18n/number_patternstring.cpp", + "//third_party/icu/icu4c/source/i18n/utf8collationiterator.cpp", + "//third_party/icu/icu4c/source/i18n/sharedbreakiterator.cpp", + "//third_party/icu/icu4c/source/i18n/number_fluent.cpp", + "//third_party/icu/icu4c/source/i18n/measunit.cpp", + "//third_party/icu/icu4c/source/i18n/collationcompare.cpp", + "//third_party/icu/icu4c/source/i18n/number_formatimpl.cpp", + "//third_party/icu/icu4c/source/i18n/number_decimfmtprops.cpp", + "//third_party/icu/icu4c/source/i18n/nfrs.cpp", + "//third_party/icu/icu4c/source/i18n/tznames.cpp", + "//third_party/icu/icu4c/source/i18n/remtrans.cpp", + "//third_party/icu/icu4c/source/i18n/nfrule.cpp", +] + +ohos_shared_library("shared_icuuc") { + configs = [ + ":icu_config", + "$build_root/config/compiler:rtti", + ] + deps = [ ":static_icustubdata" ] + defines = [ + "U_ATTRIBUTE_DEPRECATED=", + "U_COMMON_IMPLEMENTATION", + "UPRV_BLOCK_MACRO_BEGIN=", + "UPRV_BLOCK_MACRO_END=", + "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0", + "_REENTRANT", + ] + sources = icu_common_source + cflags_cc = [ + "-O3", + "-W", + "-Wall", + "-pedantic", + "-Wpointer-arith", + "-Wwrite-strings", + "-Wno-error=unused-parameter", + "-Wno-error=unused-const-variable", + "-Wno-error=unneeded-internal-declaration", + "-std=c++11", + "-Wno-ignored-attributes", + ] + ldflags = [ + "-shared", + "-lm", + ] + output_name = "hmicuuc" +} + +ohos_shared_library("shared_icui18n") { + sources = icu_i18n_source + configs = [ + ":icu_config", + "$build_root/config/compiler:rtti", + ] + deps = [ ":shared_icuuc" ] + defines = [ + "U_ATTRIBUTE_DEPRECATED=", + "U_I18N_IMPLEMENTATION", + "UPRV_BLOCK_MACRO_BEGIN=", + "UPRV_BLOCK_MACRO_END=", + "_REENTRANT", + "PIC", + ] + cflags_cc = [ + "-O3", + "-W", + "-Wall", + "-pedantic", + "-Wpointer-arith", + "-Wno-error=unused-parameter", + "-Wno-error=unused-const-variable", + "-Wno-error=implicit-float-conversion", + "-Wno-error=unneeded-internal-declaration", + "-Wwrite-strings", + "-std=c++11", + "-Wno-ignored-attributes", + ] + ldflags = [ + "-shared", + "-lm", + ] + if (!is_mingw) { + cflags_cc += [ "-fPIC" ] + ldflags += [ "-ldl" ] + } + output_name = "hmicui18n" +} + +ohos_static_library("static_icuuc") { + configs = [ + ":icu_config", + "$build_root/config/compiler:rtti", + ] + deps = [ ":static_icustubdata" ] + defines = [ + "U_ATTRIBUTE_DEPRECATED=", + "U_COMMON_IMPLEMENTATION", + "U_STATIC_IMPLEMENTATION", + "UPRV_BLOCK_MACRO_BEGIN=", + "UPRV_BLOCK_MACRO_END=", + "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0", + "_REENTRANT", + ] + sources = icu_common_source + cflags_cc = [ + "-Os", + "-W", + "-Wall", + "-pedantic", + "-Wpointer-arith", + "-Wwrite-strings", + "-std=c++11", + "-Wno-error=unused-parameter", + "-Wno-error=unused-const-variable", + "-Wno-error=unneeded-internal-declaration", + "-fvisibility-inlines-hidden", + "-Wno-unused-function", + "-Wno-ignored-attributes", + ] + + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Os", + "-Wno-unused-function", + ] + + ldflags = [ + "-static", + "-ldl", + "-lm", + ] + + output_name = "hmicuuc" +} + +ohos_static_library("static_icui18n") { + sources = icu_i18n_source + configs = [ + ":icu_config", + "$build_root/config/compiler:rtti", + ] + deps = [ ":static_icuuc" ] + defines = [ + "U_ATTRIBUTE_DEPRECATED=", + "U_I18N_IMPLEMENTATION", + "U_STATIC_IMPLEMENTATION", + "UPRV_BLOCK_MACRO_BEGIN=", + "UPRV_BLOCK_MACRO_END=", + "_REENTRANT", + "PIC", + ] + + cflags_cc = [ + "-Os", + "-W", + "-Wall", + "-pedantic", + "-Wpointer-arith", + "-Wwrite-strings", + "-Wno-error=unused-parameter", + "-Wno-error=unused-const-variable", + "-Wno-error=implicit-float-conversion", + "-Wno-error=unneeded-internal-declaration", + "-std=c++11", + "-fvisibility-inlines-hidden", + "-fno-exceptions", + "-Wno-ignored-attributes", + ] + + if (is_mingw) { + cflags_cc += [ "-DWINVER=0x0601" ] + } else { + cflags_cc += [ "-fPIC" ] + } + + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Os", + ] + + ldflags = [ + "-static", + "-ldl", + "-lm", + ] + output_name = "hmicui18n" +} diff --git a/build/third_party_gn/protobuf/BUILD.gn b/build/third_party_gn/protobuf/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6c263fbc29c76b957295d73b5adc85c1177c3f3c --- /dev/null +++ b/build/third_party_gn/protobuf/BUILD.gn @@ -0,0 +1,416 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(ark_standalone_build)) { + import("//profiler//build/config.gni") + import("$build_root/ark.gni") +} else { + import("//build/ohos.gni") + import("//developtools/profiler/build/config.gni") +} + +protobuf_src_root = "//third_party/protobuf/src/" + +config("protobuf_config") { + include_dirs = [ "$protobuf_src_root" ] +} + +ohos_shared_library("protobuf_lite") { + sources = [ + "$protobuf_src_root/google/protobuf/any_lite.cc", + "$protobuf_src_root/google/protobuf/arena.cc", + "$protobuf_src_root/google/protobuf/extension_set.cc", + "$protobuf_src_root/google/protobuf/generated_enum_util.cc", + "$protobuf_src_root/google/protobuf/generated_message_table_driven_lite.cc", + "$protobuf_src_root/google/protobuf/generated_message_util.cc", + "$protobuf_src_root/google/protobuf/implicit_weak_message.cc", + "$protobuf_src_root/google/protobuf/io/coded_stream.cc", + "$protobuf_src_root/google/protobuf/io/io_win32.cc", + "$protobuf_src_root/google/protobuf/io/strtod.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream_impl.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream_impl_lite.cc", + "$protobuf_src_root/google/protobuf/message_lite.cc", + "$protobuf_src_root/google/protobuf/parse_context.cc", + "$protobuf_src_root/google/protobuf/repeated_field.cc", + "$protobuf_src_root/google/protobuf/stubs/bytestream.cc", + "$protobuf_src_root/google/protobuf/stubs/common.cc", + "$protobuf_src_root/google/protobuf/stubs/int128.cc", + "$protobuf_src_root/google/protobuf/stubs/status.cc", + "$protobuf_src_root/google/protobuf/stubs/statusor.cc", + "$protobuf_src_root/google/protobuf/stubs/stringpiece.cc", + "$protobuf_src_root/google/protobuf/stubs/stringprintf.cc", + "$protobuf_src_root/google/protobuf/stubs/structurally_valid.cc", + "$protobuf_src_root/google/protobuf/stubs/strutil.cc", + "$protobuf_src_root/google/protobuf/stubs/time.cc", + "$protobuf_src_root/google/protobuf/wire_format_lite.cc", + ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + if (!is_mingw) { + if (current_toolchain != host_toolchain) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } + } else { + defines = [ "_FILE_OFFSET_BITS_SET_LSEEK" ] + } + + cflags_cc = [ "-Wno-sign-compare" ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + ] + + public_configs = [ ":protobuf_config" ] + install_enable = true + subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" + part_name = "${OHOS_PROFILER_PART_NAME}" +} + +ohos_static_library("protobuf_lite_static") { + sources = [ + "$protobuf_src_root/google/protobuf/any_lite.cc", + "$protobuf_src_root/google/protobuf/arena.cc", + "$protobuf_src_root/google/protobuf/extension_set.cc", + "$protobuf_src_root/google/protobuf/generated_enum_util.cc", + "$protobuf_src_root/google/protobuf/generated_message_table_driven_lite.cc", + "$protobuf_src_root/google/protobuf/generated_message_util.cc", + "$protobuf_src_root/google/protobuf/implicit_weak_message.cc", + "$protobuf_src_root/google/protobuf/io/coded_stream.cc", + "$protobuf_src_root/google/protobuf/io/io_win32.cc", + "$protobuf_src_root/google/protobuf/io/strtod.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream_impl.cc", + "$protobuf_src_root/google/protobuf/io/zero_copy_stream_impl_lite.cc", + "$protobuf_src_root/google/protobuf/message_lite.cc", + "$protobuf_src_root/google/protobuf/parse_context.cc", + "$protobuf_src_root/google/protobuf/repeated_field.cc", + "$protobuf_src_root/google/protobuf/stubs/bytestream.cc", + "$protobuf_src_root/google/protobuf/stubs/common.cc", + "$protobuf_src_root/google/protobuf/stubs/int128.cc", + "$protobuf_src_root/google/protobuf/stubs/status.cc", + "$protobuf_src_root/google/protobuf/stubs/statusor.cc", + "$protobuf_src_root/google/protobuf/stubs/stringpiece.cc", + "$protobuf_src_root/google/protobuf/stubs/stringprintf.cc", + "$protobuf_src_root/google/protobuf/stubs/structurally_valid.cc", + "$protobuf_src_root/google/protobuf/stubs/strutil.cc", + "$protobuf_src_root/google/protobuf/stubs/time.cc", + "$protobuf_src_root/google/protobuf/wire_format_lite.cc", + ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + if (!is_mingw) { + if (default_toolchain == current_toolchain) { + # target build, not host build + defines = [ "HAVE_HILOG" ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } + } else { + defines = [ "_FILE_OFFSET_BITS_SET_LSEEK" ] + } + + cflags_cc = [ "-Wno-sign-compare" ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + ] + if (is_mingw) { + # ../../third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc:60:9: error: 'lseek' macro redefined [-Werror,-Wmacro-redefined] + cflags += [ "-Wno-macro-redefined" ] + } + public_configs = [ ":protobuf_config" ] +} + +ohos_shared_library("protobuf") { + sources = [ + "$protobuf_src_root/google/protobuf/any.cc", + "$protobuf_src_root/google/protobuf/any.pb.cc", + "$protobuf_src_root/google/protobuf/api.pb.cc", + "$protobuf_src_root/google/protobuf/compiler/importer.cc", + "$protobuf_src_root/google/protobuf/compiler/parser.cc", + "$protobuf_src_root/google/protobuf/descriptor.cc", + "$protobuf_src_root/google/protobuf/descriptor.pb.cc", + "$protobuf_src_root/google/protobuf/descriptor_database.cc", + "$protobuf_src_root/google/protobuf/duration.pb.cc", + "$protobuf_src_root/google/protobuf/dynamic_message.cc", + "$protobuf_src_root/google/protobuf/empty.pb.cc", + "$protobuf_src_root/google/protobuf/extension_set_heavy.cc", + "$protobuf_src_root/google/protobuf/field_mask.pb.cc", + "$protobuf_src_root/google/protobuf/generated_message_reflection.cc", + "$protobuf_src_root/google/protobuf/generated_message_table_driven.cc", + "$protobuf_src_root/google/protobuf/io/gzip_stream.cc", + "$protobuf_src_root/google/protobuf/io/printer.cc", + "$protobuf_src_root/google/protobuf/io/tokenizer.cc", + "$protobuf_src_root/google/protobuf/map_field.cc", + "$protobuf_src_root/google/protobuf/message.cc", + "$protobuf_src_root/google/protobuf/reflection_ops.cc", + "$protobuf_src_root/google/protobuf/service.cc", + "$protobuf_src_root/google/protobuf/source_context.pb.cc", + "$protobuf_src_root/google/protobuf/struct.pb.cc", + "$protobuf_src_root/google/protobuf/stubs/substitute.cc", + "$protobuf_src_root/google/protobuf/text_format.cc", + "$protobuf_src_root/google/protobuf/timestamp.pb.cc", + "$protobuf_src_root/google/protobuf/type.pb.cc", + "$protobuf_src_root/google/protobuf/unknown_field_set.cc", + "$protobuf_src_root/google/protobuf/util/delimited_message_util.cc", + "$protobuf_src_root/google/protobuf/util/field_comparator.cc", + "$protobuf_src_root/google/protobuf/util/field_mask_util.cc", + "$protobuf_src_root/google/protobuf/util/internal/datapiece.cc", + "$protobuf_src_root/google/protobuf/util/internal/default_value_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/error_listener.cc", + "$protobuf_src_root/google/protobuf/util/internal/field_mask_utility.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_escaping.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_stream_parser.cc", + "$protobuf_src_root/google/protobuf/util/internal/object_writer.cc", + "$protobuf_src_root/google/protobuf/util/internal/proto_writer.cc", + "$protobuf_src_root/google/protobuf/util/internal/protostream_objectsource.cc", + "$protobuf_src_root/google/protobuf/util/internal/protostream_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/type_info.cc", + "$protobuf_src_root/google/protobuf/util/internal/type_info_test_helper.cc", + "$protobuf_src_root/google/protobuf/util/internal/utility.cc", + "$protobuf_src_root/google/protobuf/util/json_util.cc", + "$protobuf_src_root/google/protobuf/util/message_differencer.cc", + "$protobuf_src_root/google/protobuf/util/time_util.cc", + "$protobuf_src_root/google/protobuf/util/type_resolver_util.cc", + "$protobuf_src_root/google/protobuf/wire_format.cc", + "$protobuf_src_root/google/protobuf/wrappers.pb.cc", + ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + cflags_cc = [ "-Wno-sign-compare" ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + ] + + deps = [ ":protobuf_lite" ] + + public_configs = [ ":protobuf_config" ] + install_enable = true + subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" + part_name = "${OHOS_PROFILER_PART_NAME}" +} + +ohos_static_library("protobuf_static") { + sources = [ + "$protobuf_src_root/google/protobuf/any.cc", + "$protobuf_src_root/google/protobuf/any.pb.cc", + "$protobuf_src_root/google/protobuf/api.pb.cc", + "$protobuf_src_root/google/protobuf/compiler/importer.cc", + "$protobuf_src_root/google/protobuf/compiler/parser.cc", + "$protobuf_src_root/google/protobuf/descriptor.cc", + "$protobuf_src_root/google/protobuf/descriptor.pb.cc", + "$protobuf_src_root/google/protobuf/descriptor_database.cc", + "$protobuf_src_root/google/protobuf/duration.pb.cc", + "$protobuf_src_root/google/protobuf/dynamic_message.cc", + "$protobuf_src_root/google/protobuf/empty.pb.cc", + "$protobuf_src_root/google/protobuf/extension_set_heavy.cc", + "$protobuf_src_root/google/protobuf/field_mask.pb.cc", + "$protobuf_src_root/google/protobuf/generated_message_reflection.cc", + "$protobuf_src_root/google/protobuf/generated_message_table_driven.cc", + "$protobuf_src_root/google/protobuf/io/gzip_stream.cc", + "$protobuf_src_root/google/protobuf/io/printer.cc", + "$protobuf_src_root/google/protobuf/io/tokenizer.cc", + "$protobuf_src_root/google/protobuf/map_field.cc", + "$protobuf_src_root/google/protobuf/message.cc", + "$protobuf_src_root/google/protobuf/reflection_ops.cc", + "$protobuf_src_root/google/protobuf/service.cc", + "$protobuf_src_root/google/protobuf/source_context.pb.cc", + "$protobuf_src_root/google/protobuf/struct.pb.cc", + "$protobuf_src_root/google/protobuf/stubs/substitute.cc", + "$protobuf_src_root/google/protobuf/text_format.cc", + "$protobuf_src_root/google/protobuf/timestamp.pb.cc", + "$protobuf_src_root/google/protobuf/type.pb.cc", + "$protobuf_src_root/google/protobuf/unknown_field_set.cc", + "$protobuf_src_root/google/protobuf/util/delimited_message_util.cc", + "$protobuf_src_root/google/protobuf/util/field_comparator.cc", + "$protobuf_src_root/google/protobuf/util/field_mask_util.cc", + "$protobuf_src_root/google/protobuf/util/internal/datapiece.cc", + "$protobuf_src_root/google/protobuf/util/internal/default_value_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/error_listener.cc", + "$protobuf_src_root/google/protobuf/util/internal/field_mask_utility.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_escaping.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/json_stream_parser.cc", + "$protobuf_src_root/google/protobuf/util/internal/object_writer.cc", + "$protobuf_src_root/google/protobuf/util/internal/proto_writer.cc", + "$protobuf_src_root/google/protobuf/util/internal/protostream_objectsource.cc", + "$protobuf_src_root/google/protobuf/util/internal/protostream_objectwriter.cc", + "$protobuf_src_root/google/protobuf/util/internal/type_info.cc", + "$protobuf_src_root/google/protobuf/util/internal/type_info_test_helper.cc", + "$protobuf_src_root/google/protobuf/util/internal/utility.cc", + "$protobuf_src_root/google/protobuf/util/json_util.cc", + "$protobuf_src_root/google/protobuf/util/message_differencer.cc", + "$protobuf_src_root/google/protobuf/util/time_util.cc", + "$protobuf_src_root/google/protobuf/util/type_resolver_util.cc", + "$protobuf_src_root/google/protobuf/wire_format.cc", + "$protobuf_src_root/google/protobuf/wrappers.pb.cc", + ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + cflags_cc = [ "-Wno-sign-compare" ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + ] + + deps = [ ":protobuf_lite_static" ] + + public_configs = [ ":protobuf_config" ] +} + +if (current_toolchain == host_toolchain) { + ohos_shared_library("protoc_lib") { + sources = [ + "$protobuf_src_root/google/protobuf/compiler/code_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/command_line_interface.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_enum.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_enum_field.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_extension.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_field.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_file.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_helpers.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_map_field.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_message.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_message_field.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_padding_optimizer.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_primitive_field.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_service.cc", + "$protobuf_src_root/google/protobuf/compiler/cpp/cpp_string_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_doc_comment.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_enum.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_enum_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_field_base.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_helpers.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_map_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_message.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_message_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_primitive_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_reflection_class.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_source_generator_base.cc", + "$protobuf_src_root/google/protobuf/compiler/csharp/csharp_wrapper_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_context.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_doc_comment.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_enum.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_enum_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_enum_field_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_enum_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_extension.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_extension_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_file.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_generator_factory.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_helpers.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_map_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_map_field_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message_builder.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message_builder_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message_field_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_message_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_name_resolver.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_primitive_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_primitive_field_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_service.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_shared_code_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_string_field.cc", + "$protobuf_src_root/google/protobuf/compiler/java/java_string_field_lite.cc", + "$protobuf_src_root/google/protobuf/compiler/js/js_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/js/well_known_types_embed.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_enum.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_enum_field.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_extension.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_field.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_file.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_helpers.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_map_field.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_message.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_message_field.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_oneof.cc", + "$protobuf_src_root/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc", + "$protobuf_src_root/google/protobuf/compiler/php/php_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/plugin.cc", + "$protobuf_src_root/google/protobuf/compiler/plugin.pb.cc", + "$protobuf_src_root/google/protobuf/compiler/python/python_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/ruby/ruby_generator.cc", + "$protobuf_src_root/google/protobuf/compiler/subprocess.cc", + "$protobuf_src_root/google/protobuf/compiler/zip_writer.cc", + ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + cflags_cc = [ + "-Wno-sign-compare", + "-Wno-unused-function", + "-Wno-unused-private-field", + ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + "-Wno-unused-function", + ] + + deps = [ + ":protobuf", + ":protobuf_lite", + ] + + public_configs = [ ":protobuf_config" ] + subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" + part_name = "${OHOS_PROFILER_PART_NAME}" + } +} + +# Only compile the plugin for the host architecture. +if (current_toolchain == host_toolchain) { + ohos_executable("protoc") { + sources = [ "$protobuf_src_root/google/protobuf/compiler/main.cc" ] + include_dirs = [ + "$protobuf_src_root/google/protobuf/**/*.h", + "$protobuf_src_root/google/protobuf/**/*.inc", + "$protobuf_src_root", + ] + deps = [ ":protoc_lib" ] + cflags_cc = [ "-Wno-sign-compare" ] + cflags = [ + "-Wno-sign-compare", + "-D HAVE_PTHREAD", + ] + + subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" + part_name = "${OHOS_PROFILER_PART_NAME}" + } +} diff --git a/build/third_party_gn/zlib/BUILD.gn b/build/third_party_gn/zlib/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f0b9f1918d225364512ccfdead3619b7339e5c10 --- /dev/null +++ b/build/third_party_gn/zlib/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/ark.gni") + +config("zlib_config") { + cflags = [ + "-Wno-incompatible-pointer-types", + "-Werror", + "-Wimplicit-function-declaration", + "-fPIC", + ] +} + +config("zlib_public_config") { + include_dirs = [ "." ] +} + +ohos_static_library("libz") { + sources = [ + "//third_party/zlib/adler32.c", + "//third_party/zlib/compress.c", + "//third_party/zlib/contrib/minizip/ioapi.c", + "//third_party/zlib/contrib/minizip/unzip.c", + "//third_party/zlib/contrib/minizip/zip.c", + "//third_party/zlib/crc32.c", + "//third_party/zlib/crc32.h", + "//third_party/zlib/deflate.c", + "//third_party/zlib/deflate.h", + "//third_party/zlib/gzclose.c", + "//third_party/zlib/gzguts.h", + "//third_party/zlib/gzlib.c", + "//third_party/zlib/gzread.c", + "//third_party/zlib/gzwrite.c", + "//third_party/zlib/infback.c", + "//third_party/zlib/inffast.c", + "//third_party/zlib/inffast.h", + "//third_party/zlib/inffixed.h", + "//third_party/zlib/inflate.c", + "//third_party/zlib/inflate.h", + "//third_party/zlib/inftrees.c", + "//third_party/zlib/inftrees.h", + "//third_party/zlib/trees.c", + "//third_party/zlib/trees.h", + "//third_party/zlib/uncompr.c", + "//third_party/zlib/zconf.h", + "//third_party/zlib/zlib.h", + "//third_party/zlib/zutil.c", + "//third_party/zlib/zutil.h", + ] + configs = [ ":zlib_config" ] + public_configs = [ ":zlib_public_config" ] +} diff --git a/build/toolchain/ark/BUILD.gn b/build/toolchain/ark/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..05a6241319d070de3f4e76527c4bb37edf87e5c4 --- /dev/null +++ b/build/toolchain/ark/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/toolchain/ark/ark_toolchain.gni") + +ark_clang_toolchain("ark_clang_arm") { + toolchain_args = { + current_cpu = "arm" + current_os = "ohos" + } +} + +ark_clang_toolchain("ark_clang_x64") { + toolchain_args = { + current_cpu = "x64" + current_os = "ohos" + } +} + +ark_clang_toolchain("ark_clang_android_arm") { + toolchain_args = { + current_cpu = "arm" + current_os = "android" + } +} + +ark_clang_toolchain("ark_clang_android_arm64") { + toolchain_args = { + current_cpu = "arm64" + current_os = "android" + } +} + +ark_clang_toolchain("ark_clang_ios_arm") { + toolchain_args = { + current_cpu = "arm64" + current_os = "ios" + } +} + +ark_clang_toolchain("ark_clang_arm64") { + toolchain_args = { + current_cpu = "arm64" + current_os = "ohos" + } +} diff --git a/build/toolchain/ark/ark_toolchain.gni b/build/toolchain/ark/ark_toolchain.gni new file mode 100755 index 0000000000000000000000000000000000000000..56d707e16577d5689e87b53bcb5b6ec61ec10e78 --- /dev/null +++ b/build/toolchain/ark/ark_toolchain.gni @@ -0,0 +1,45 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/toolchain/gcc_toolchain.gni") + +template("ark_clang_toolchain") { + gcc_toolchain(target_name) { + prefix = rebase_path("$clang_base_path/bin", root_build_dir) + cc = "$prefix/clang" + cxx = "$prefix/clang++" + ld = cxx + readelf = "$prefix/llvm-readobj" + ar = "${prefix}/llvm-ar" + nm = "$prefix/llvm-nm" + + forward_variables_from(invoker, + [ + "strip", + "is_clang_analysis_supported", + "enable_linker_map", + "use_unstripped_as_runtime_outputs", + ]) + + toolchain_args = { + if (defined(invoker.toolchain_args)) { + forward_variables_from(invoker.toolchain_args, "*") + } + is_clang = true + } + + if (defined(invoker.shlib_extension) && invoker.shlib_extension != "") { + shlib_extension = invoker.shlib_extension + } + } +} diff --git a/build/toolchain/cc_wrapper.gni b/build/toolchain/cc_wrapper.gni new file mode 100755 index 0000000000000000000000000000000000000000..0c682700778df6302a05f6bdf1a7edc0a3ca5d69 --- /dev/null +++ b/build/toolchain/cc_wrapper.gni @@ -0,0 +1,51 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Defines the configuration of cc wrapper +# ccache: a c/c++ compiler cache which can greatly reduce recompilation times. +# icecc, distcc: it takes compile jobs from a build and distributes them among +# remote machines allowing a parallel build. +# +# TIPS +# +# 1) ccache +# Set clang_use_chrome_plugins=false if using ccache 3.1.9 or earlier, since +# these versions don't support -Xclang. (3.1.10 and later will silently +# ignore -Xclang, so it doesn't matter if you disable clang_use_chrome_plugins +# or not). +# +# Use ccache 3.2 or later to avoid clang unused argument warnings: +# https://bugzilla.samba.org/show_bug.cgi?id=8118 +# +# To avoid -Wparentheses-equality clang warnings, at some cost in terms of +# speed, you can do: +# export CCACHE_CPP2=yes +# +# 2) icecc +# Set clang_use_chrome_plugins=false because icecc cannot distribute custom +# clang libraries. +# +# To use icecc and ccache together, set cc_wrapper = "ccache" with +# export CCACHE_PREFIX=icecc + +_cc_wrapper = "" +_ccache_exec = getenv("CCACHE_EXEC") +_use_ccache = getenv("USE_CCACHE") +if (_use_ccache == "1" && _ccache_exec != "") { + _cc_wrapper = rebase_path(_ccache_exec) +} + +declare_args() { + # Set to "ccache", "icecc" or "distcc". Probably doesn't work on windows. + cc_wrapper = _cc_wrapper +} diff --git a/build/toolchain/clang_static_analyzer.gni b/build/toolchain/clang_static_analyzer.gni new file mode 100755 index 0000000000000000000000000000000000000000..c92b4903dc94c4f14c784af00988e08d8fe67112 --- /dev/null +++ b/build/toolchain/clang_static_analyzer.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Defines the configuration of Clang static analysis tools. +# See docs/clang_static_analyzer.md for more information. + +declare_args() { + # Uses the Clang static analysis tools during compilation. + use_clang_static_analyzer = false +} diff --git a/build/toolchain/gcc_link_wrapper.py b/build/toolchain/gcc_link_wrapper.py new file mode 100755 index 0000000000000000000000000000000000000000..0a248d42c7c73cbaac35c3372caa71256b8e7a4a --- /dev/null +++ b/build/toolchain/gcc_link_wrapper.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright 2015 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. +"""Runs a linking command and optionally a strip command. + +This script exists to avoid using complex shell commands in +gcc_toolchain.gni's tool("link"), in case the host running the compiler +does not have a POSIX-like shell (e.g. Windows). +""" + +import argparse +import os +import subprocess +import sys + +import wrapper_utils + +# When running on a Windows host and using a toolchain whose tools are +# actually wrapper scripts (i.e. .bat files on Windows) rather than binary +# executables, the "command" to run has to be prefixed with this magic. +# The GN toolchain definitions take care of that for when GN/Ninja is +# running the tool directly. When that command is passed in to this +# script, it appears as a unitary string but needs to be split up so that +# just 'cmd' is the actual command given to Python's subprocess module. +BAT_PREFIX = 'cmd /c call ' + + +def command_to_run(command): + if command[0].startswith(BAT_PREFIX): + command = command[0].split(None, 3) + command[1:] + return command + + +def is_static_link(command): + if "-static" in command: + return True + else: + return False + + +""" since static link and dynamic link have different CRT files on ohos, +and we use dynamic link CRT files as default, so when link statically, +we need change the CRT files +""" + + +def update_crt(command): + for item in command: + if str(item).find("crtbegin_dynamic.o") >= 0: + index = command.index(item) + new_crtbegin = str(item).replace("crtbegin_dynamic.o", + "crtbegin_static.o") + command[index] = new_crtbegin + return command + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--strip', + help='The strip binary to run', + metavar='PATH') + parser.add_argument('--unstripped-file', + help='Executable file produced by linking command', + metavar='FILE') + parser.add_argument('--map-file', + help=('Use --Wl,-Map to generate a map file. Will be ' + 'gzipped if extension ends with .gz'), + metavar='FILE') + parser.add_argument('--output', + required=True, + help='Final output executable file', + metavar='FILE') + parser.add_argument('--clang_rt_dso_path', + help=('Clang asan runtime shared library')) + parser.add_argument('command', nargs='+', help='Linking command') + args = parser.parse_args() + + # Work-around for gold being slow-by-default. http://crbug.com/632230 + fast_env = dict(os.environ) + fast_env['LC_ALL'] = 'C' + if is_static_link(args.command): + command = update_crt(args.command) + if args.clang_rt_dso_path is not None: + return 0 + else: + command = args.command + result = wrapper_utils.run_link_with_optional_map_file( + command, env=fast_env, map_file=args.map_file) + if result != 0: + return result + + # Finally, strip the linked executable (if desired). + if args.strip: + result = subprocess.call( + command_to_run( + [args.strip, '-o', args.output, args.unstripped_file])) + + return result + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/build/toolchain/gcc_solink_wrapper.py b/build/toolchain/gcc_solink_wrapper.py new file mode 100755 index 0000000000000000000000000000000000000000..7bf117981498d883fd18038c4d43636a54f8e521 --- /dev/null +++ b/build/toolchain/gcc_solink_wrapper.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright 2015 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. +"""Runs 'ld -shared' and generates a .TOC file that's untouched when unchanged. + +This script exists to avoid using complex shell commands in +gcc_toolchain.gni's tool("solink"), in case the host running the compiler +does not have a POSIX-like shell (e.g. Windows). +""" + +import argparse +import os +import subprocess +import sys +import shutil + +import wrapper_utils + + +def collect_soname(args): + """Replaces: readelf -d $sofile | grep SONAME""" + toc = '' + readelf = subprocess.Popen(wrapper_utils.command_to_run( + [args.readelf, '-d', args.sofile]), + stdout=subprocess.PIPE, + bufsize=-1) + for line in readelf.stdout: + if b'SONAME' in line: + toc += line.decode() + return readelf.wait(), toc + + +def collect_dyn_sym(args): + """Replaces: nm --format=posix -g -D $sofile | cut -f1-2 -d' '""" + toc = '' + _command = [args.nm] + if args.sofile.endswith('.dll'): + _command.append('--extern-only') + else: + _command.extend(['--format=posix', '-g', '-D']) + _command.append(args.sofile) + nm = subprocess.Popen(wrapper_utils.command_to_run(_command), + stdout=subprocess.PIPE, + bufsize=-1) + for line in nm.stdout: + toc += '{}\n'.format(' '.join(line.decode().split(' ', 2)[:2])) + return nm.wait(), toc + + +def collect_toc(args): + result, toc = collect_soname(args) + if result == 0: + result, dynsym = collect_dyn_sym(args) + toc += dynsym + return result, toc + + +def update_toc(tocfile, toc): + if os.path.exists(tocfile): + with open(tocfile, 'r') as f: + old_toc = f.read() + else: + old_toc = None + if toc != old_toc: + with open(tocfile, 'w') as fp: + fp.write(toc) + + +def reformat_rsp_file(rspfile): + """ Move all implibs from --whole-archive section""" + with open(rspfile, "r") as fi: + rspcontent = fi.read() + result = [] + implibs = [] + naflag = False + for arg in rspcontent.split(" "): + if naflag and arg.endswith(".lib"): + implibs.append(arg) + continue + result.append(arg) + if arg == "-Wl,--whole-archive": + naflag = True + continue + if arg == "-Wl,--no-whole-archive": + naflag = False + result.extend(implibs) + + with open(rspfile, "w") as fo: + fo.write(" ".join(result)) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--readelf', + required=True, + help='The readelf binary to run', + metavar='PATH') + parser.add_argument('--nm', + required=True, + help='The nm binary to run', + metavar='PATH') + parser.add_argument('--strip', + help='The strip binary to run', + metavar='PATH') + parser.add_argument('--sofile', + required=True, + help='Shared object file produced by linking command', + metavar='FILE') + parser.add_argument('--tocfile', + required=False, + help='Output table-of-contents file', + metavar='FILE') + parser.add_argument('--map-file', + help=('Use --Wl,-Map to generate a map file. Will be ' + 'gzipped if extension ends with .gz'), + metavar='FILE') + parser.add_argument('--output', + required=True, + help='Final output shared object file', + metavar='FILE') + parser.add_argument('--libfile', required=False, metavar='FILE') + parser.add_argument('command', nargs='+', help='Linking command') + args = parser.parse_args() + + if args.sofile.endswith(".dll"): + rspfile = None + for a in args.command: + if a[0] == "@": + rspfile = a[1:] + break + if rspfile: + reformat_rsp_file(rspfile) + # Work-around for gold being slow-by-default. http://crbug.com/632230 + fast_env = dict(os.environ) + fast_env['LC_ALL'] = 'C' + + # First, run the actual link. + command = wrapper_utils.command_to_run(args.command) + result = wrapper_utils.run_link_with_optional_map_file( + command, env=fast_env, map_file=args.map_file) + + if result != 0: + return result + + # Next, generate the contents of the TOC file. + result, toc = collect_toc(args) + if result != 0: + return result + + # If there is an existing TOC file with identical contents, leave it alone. + # Otherwise, write out the TOC file. + if args.tocfile: + update_toc(args.tocfile, toc) + + # Finally, strip the linked shared object file (if desired). + if args.strip: + result = subprocess.call( + wrapper_utils.command_to_run( + [args.strip, '-o', args.output, args.sofile])) + if args.libfile: + libfile_name = os.path.basename(args.libfile) + sofile_output_dir = os.path.dirname(args.sofile) + unstripped_libfile = os.path.join(sofile_output_dir, libfile_name) + shutil.copy2(unstripped_libfile, args.libfile) + + return result + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni new file mode 100755 index 0000000000000000000000000000000000000000..ff75a5077f9e3c2ddaa859e1ba3c0ea66151da07 --- /dev/null +++ b/build/toolchain/gcc_toolchain.gni @@ -0,0 +1,499 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/config/clang/clang.gni") +import("$build_root/config/sanitizers/sanitizers.gni") +import("$build_root/toolchain/cc_wrapper.gni") +import("$build_root/toolchain/clang_static_analyzer.gni") +import("$build_root/toolchain/toolchain.gni") +template("gcc_toolchain") { + toolchain(target_name) { + assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") + assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") + assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") + assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") + + # This define changes when the toolchain changes, forcing a rebuild. + # Nothing should ever use this define. + if (defined(invoker.rebuild_define)) { + rebuild_string = "-D" + invoker.rebuild_define + " " + } else { + rebuild_string = "" + } + + # GN's syntax can't handle more than one scope dereference at once, like + # "invoker.toolchain_args.foo", so make a temporary to hold the toolchain + # args so we can do "invoker_toolchain_args.foo". + assert(defined(invoker.toolchain_args), + "Toolchains must specify toolchain_args") + invoker_toolchain_args = invoker.toolchain_args + assert(defined(invoker_toolchain_args.current_cpu), + "toolchain_args must specify a current_cpu") + assert(defined(invoker_toolchain_args.current_os), + "toolchain_args must specify a current_os") + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args = { + # Populate toolchain args from the invoker. + forward_variables_from(invoker_toolchain_args, "*") + # The host toolchain value computed by the default toolchain's setup + # needs to be passed through unchanged to all secondary toolchains to + # ensure that it's always the same, regardless of the values that may be + # set on those toolchains. + } + + if (defined(toolchain_args.cc_wrapper)) { + toolchain_cc_wrapper = toolchain_args.cc_wrapper + } else { + toolchain_cc_wrapper = cc_wrapper + } + + if (is_clang && use_clang_static_analyzer && + (!defined(invoker.is_clang_analysis_supported) || + invoker.is_clang_analysis_supported)) { + compiler_prefix = "${analyzer_wrapper} " + asm = invoker.cc + } else { + compiler_prefix = "${toolchain_cc_wrapper} " + } + + cc = compiler_prefix + invoker.cc + cxx = compiler_prefix + invoker.cxx + ar = invoker.ar + ld = invoker.ld + if (!defined(asm)) { + asm = cc + } + if (defined(invoker.readelf)) { + readelf = invoker.readelf + } else { + readelf = "readelf" + } + if (defined(invoker.nm)) { + nm = invoker.nm + } else { + nm = "nm" + } + + if (defined(invoker.shlib_extension)) { + default_shlib_extension = invoker.shlib_extension + } else { + default_shlib_extension = shlib_extension + } + + if (defined(invoker.executable_extension)) { + default_executable_extension = invoker.executable_extension + } else { + default_executable_extension = "" + } + + # Bring these into our scope for string interpolation with default values. + if (defined(invoker.libs_section_prefix)) { + libs_section_prefix = invoker.libs_section_prefix + } else { + libs_section_prefix = "" + } + + if (defined(invoker.libs_section_postfix)) { + libs_section_postfix = invoker.libs_section_postfix + } else { + libs_section_postfix = "" + } + + if (defined(invoker.solink_libs_section_prefix)) { + solink_libs_section_prefix = invoker.solink_libs_section_prefix + } else { + solink_libs_section_prefix = "" + } + + if (defined(invoker.solink_libs_section_postfix)) { + solink_libs_section_postfix = invoker.solink_libs_section_postfix + } else { + solink_libs_section_postfix = "" + } + + if (defined(invoker.extra_cflags) && invoker.extra_cflags != "") { + extra_cflags = " " + invoker.extra_cflags + } else { + extra_cflags = "" + } + + if (defined(invoker.extra_cppflags) && invoker.extra_cppflags != "") { + extra_cppflags = " " + invoker.extra_cppflags + } else { + extra_cppflags = "" + } + + if (defined(invoker.extra_cxxflags) && invoker.extra_cxxflags != "") { + extra_cxxflags = " " + invoker.extra_cxxflags + } else { + extra_cxxflags = "" + } + + if (defined(invoker.extra_asmflags) && invoker.extra_asmflags != "") { + extra_asmflags = " " + invoker.extra_asmflags + } else { + extra_asmflags = "" + } + + if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") { + extra_ldflags = " " + invoker.extra_ldflags + } else { + extra_ldflags = "" + } + + enable_linker_map = defined(invoker.enable_linker_map) && + invoker.enable_linker_map && generate_linker_map + + # These library switches can apply to all tools below. + lib_switch = "-l" + lib_dir_switch = "-L" + + # Object files go in this directory. + object_subdir = "{{source_out_dir}}/{{label_name}}" + + tool("cc") { + depfile = "{{output}}.d" + command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CC {{output}}" + outputs = [ "$object_subdir/{{source_name_part}}.o" ] + } + + tool("cxx") { + depfile = "{{output}}.d" + command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CXX {{output}}" + outputs = [ "$object_subdir/{{source_name_part}}.o" ] + } + + tool("asm") { + # For GCC we can just use the C compiler to compile assembly. + depfile = "{{output}}.d" + command = "$asm -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{asmflags}}${extra_asmflags} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "ASM {{output}}" + outputs = [ "$object_subdir/{{source_name_part}}.o" ] + } + + tool("alink") { + if (current_os == "aix") { + # AIX does not support either -D (deterministic output) or response + # files. + command = "$ar -X64 {{arflags}} -r -c -s {{output}} {{inputs}}" + } else { + rspfile = "{{output}}.rsp" + rspfile_content = "{{inputs}}" + command = "\"$ar\" {{arflags}} -r -c -s -D {{output}} @\"$rspfile\"" + } + + # Remove the output file first so that ar doesn't try to modify the + # existing file. + if (host_os == "win") { + tool_wrapper_path = + rebase_path("$build_root/toolchain/win/tool_wrapper.py", + root_build_dir) + command = "cmd /c $python_path $tool_wrapper_path delete-file {{output}} && $command" + } else { + command = "rm -f {{output}} && $command" + } + + # Almost all targets build with //build/config/compiler:thin_archive which + # adds -T to arflags. + description = "AR {{output}}" + outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ] + + # Shared libraries go in the target out directory by default so we can + # generate different targets with the same name and not have them collide. + default_output_dir = "{{target_out_dir}}" + default_output_extension = ".a" + output_prefix = "lib" + } + + tool("solink") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" # Possibly including toolchain dir. + rspfile = sofile + ".rsp" + + is_mingw_link = false + if (invoker_toolchain_args.current_os == "mingw") { + is_mingw_link = true + libname = "{{target_output_name}}.lib" + libfile = "{{output_dir}}/$libname" + } + + if (defined(invoker.strip)) { + unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$sofile" + } else { + unstripped_sofile = sofile + } + + link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" @\"$rspfile\"" + if (!is_mingw_link) { + link_command = "$link_command -Wl,-soname=\"$soname\"" + } else { + link_command = "$link_command -Wl,--out-implib,{{root_out_dir}}/lib.unstripped/$libfile" + } + + # Generate a map file to be used for binary size analysis. + # Map file adds ~10% to the link time on a z620. + map_switch = "" + if (enable_linker_map && is_official_build) { + map_file = "$unstripped_sofile.map.gz" + map_switch = " --map-file \"$map_file\"" + } + + assert(defined(readelf), "to solink you must have a readelf") + assert(defined(nm), "to solink you must have an nm") + strip_switch = "" + if (defined(invoker.strip)) { + strip_switch = "--strip=${invoker.strip} " + } + + # This needs a Python script to avoid using a complex shell command + # requiring sh control structures, pipelines, and POSIX utilities. + # The host might not have a POSIX shell and utilities (e.g. Windows). + solink_wrapper = + rebase_path("$build_root/toolchain/gcc_solink_wrapper.py", + root_build_dir) + command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"$nm\" $strip_switch --sofile=\"$unstripped_sofile\" $map_switch --output=\"$sofile\"" + if (is_mingw_link) { + command = "$command --libfile=\"$libfile\"" + } + command = "$command -- $link_command" + + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" + + description = "SOLINK $sofile" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = default_shlib_extension + + default_output_dir = "{{root_out_dir}}" + + output_prefix = "lib" + + # Since the above commands only updates the .TOC file when it changes, ask + # Ninja to check if the timestamp actually changed to know if downstream + # dependencies should be recompiled. + restat = true + + # Tell GN about the output files. It will link to the sofile + outputs = [ sofile ] + if (sofile != unstripped_sofile) { + outputs += [ unstripped_sofile ] + if (defined(invoker.use_unstripped_as_runtime_outputs) && + invoker.use_unstripped_as_runtime_outputs) { + runtime_outputs = [ unstripped_sofile ] + } + } + if (defined(map_file)) { + outputs += [ map_file ] + } + + if (is_mingw_link) { + outputs += [ libfile ] + link_output = libfile + depend_output = libfile + } else { + link_output = sofile + depend_output = sofile + } + } + + tool("solink_module") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" + rspfile = sofile + ".rsp" + + if (defined(invoker.strip)) { + unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$sofile" + } else { + unstripped_sofile = sofile + } + + command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" + + if (defined(invoker.strip)) { + strip_command = "${invoker.strip} -o \"$sofile\" \"$unstripped_sofile\"" + command += " && " + strip_command + } + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" + + description = "SOLINK_MODULE $sofile" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + if (defined(invoker.loadable_module_extension)) { + default_output_extension = invoker.loadable_module_extension + } else { + default_output_extension = default_shlib_extension + } + + default_output_dir = "{{root_out_dir}}" + + output_prefix = "lib" + + outputs = [ sofile ] + if (sofile != unstripped_sofile) { + outputs += [ unstripped_sofile ] + if (defined(invoker.use_unstripped_as_runtime_outputs) && + invoker.use_unstripped_as_runtime_outputs) { + runtime_outputs = [ unstripped_sofile ] + } + } + } + + tool("link") { + exename = "{{target_output_name}}{{output_extension}}" + outfile = "{{output_dir}}/$exename" + rspfile = "$outfile.rsp" + unstripped_outfile = outfile + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = default_executable_extension + + default_output_dir = "{{root_out_dir}}" + + if (defined(invoker.strip)) { + unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$outfile" + } + + # Generate a map file to be used for binary size analysis. + # Map file adds ~10% to the link time on a z620. + map_switch = "" + if (enable_linker_map && is_official_build) { + map_file = "$unstripped_outfile.map.gz" + map_switch = " --map-file \"$map_file\"" + } + + start_group_flag = "" + end_group_flag = "" + if (current_os != "aix") { + # the "--start-group .. --end-group" feature isn't available on the aix ld. + start_group_flag = "-Wl,--start-group" + end_group_flag = "-Wl,--end-group " + } + _clang_rt_dso_full_path = "" + if (is_asan && invoker_toolchain_args.current_os == "ohos") { + if (invoker_toolchain_args.current_cpu == "arm64") { + _clang_rt_dso_full_path = rebase_path( + "$clang_base_path/lib/clang/$clang_version/lib/aarch64-linux-ohos/libclang_rt.asan.so", + root_build_dir) + } else { + _clang_rt_dso_full_path = rebase_path( + "$clang_base_path/lib/clang/$clang_version/lib/arm-linux-ohos/libclang_rt.asan.so", + root_build_dir) + } + } + link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" $libs_section_prefix $start_group_flag $_clang_rt_dso_full_path @\"$rspfile\" {{solibs}} {{libs}} $end_group_flag $libs_section_postfix" + + strip_switch = "" + + if (defined(invoker.strip)) { + strip_switch = " --strip=\"${invoker.strip}\" --unstripped-file=\"$unstripped_outfile\"" + } + if (is_asan && invoker_toolchain_args.current_os == "ohos") { + strip_switch = + "$strip_switch --clang_rt_dso_path=\"$_clang_rt_dso_full_path\"" + } + + link_wrapper = rebase_path("$build_root/toolchain/gcc_link_wrapper.py", + root_build_dir) + command = "$python_path \"$link_wrapper\" --output=\"$outfile\"$strip_switch$map_switch -- $link_command" + description = "LINK $outfile" + rspfile_content = "{{inputs}}" + outputs = [ outfile ] + if (outfile != unstripped_outfile) { + outputs += [ unstripped_outfile ] + if (defined(invoker.use_unstripped_as_runtime_outputs) && + invoker.use_unstripped_as_runtime_outputs) { + runtime_outputs = [ unstripped_outfile ] + } + } + if (defined(invoker.link_outputs)) { + outputs += invoker.link_outputs + } + if (defined(map_file)) { + outputs += [ map_file ] + } + } + + # These two are really entirely generic, but have to be repeated in + # each toolchain because GN doesn't allow a template to be used here. + # See //build/toolchain/toolchain.gni for details. + tool("stamp") { + command = stamp_command + description = stamp_description + } + tool("copy") { + command = copy_command + description = copy_description + } + + forward_variables_from(invoker, [ "deps" ]) + } +} + +# This is a shorthand for gcc_toolchain instances based on the Chromium-built +# version of Clang. Only the toolchain_cpu and toolchain_os variables need to +# be specified by the invoker, and optionally toolprefix if it's a +# cross-compile case. Note that for a cross-compile case this toolchain +# requires a config to pass the appropriate -target option, or else it will +# actually just be doing a native compile. The invoker can optionally override +# use_gold too. +template("clang_toolchain") { + if (defined(invoker.toolprefix)) { + toolprefix = invoker.toolprefix + } else { + toolprefix = "" + } + + gcc_toolchain(target_name) { + prefix = rebase_path("$clang_base_path/bin", root_build_dir) + cc = "$prefix/clang" + cxx = "$prefix/clang++" + ld = cxx + readelf = "${toolprefix}readelf" + ar = "${prefix}/llvm-ar" + nm = "${toolprefix}nm" + + forward_variables_from(invoker, + [ + "strip", + "is_clang_analysis_supported", + "enable_linker_map", + "use_unstripped_as_runtime_outputs", + ]) + + toolchain_args = { + if (defined(invoker.toolchain_args)) { + forward_variables_from(invoker.toolchain_args, "*") + } + is_clang = true + } + + if (defined(invoker.shlib_extension) && invoker.shlib_extension != "") { + shlib_extension = invoker.shlib_extension + } + } +} diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..c38b3082db7a2e32d52d6ef79da544703a7bfa33 --- /dev/null +++ b/build/toolchain/linux/BUILD.gn @@ -0,0 +1,125 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("$build_root/toolchain/gcc_toolchain.gni") +clang_toolchain("clang_arm") { + toolprefix = "arm-linux-gnueabihf-" + toolchain_args = { + current_cpu = "arm" + current_os = "linux" + } +} + +clang_toolchain("clang_arm64") { + toolprefix = "aarch64-linux-gnu-" + toolchain_args = { + current_cpu = "arm64" + current_os = "linux" + } +} + +gcc_toolchain("arm64") { + toolprefix = "aarch64-linux-gnu-" + + cc = "${toolprefix}gcc" + cxx = "${toolprefix}g++" + + ar = "${toolprefix}ar" + ld = cxx + readelf = "${toolprefix}readelf" + nm = "${toolprefix}nm" + + toolchain_args = { + current_cpu = "arm64" + current_os = "linux" + is_clang = false + } +} + +gcc_toolchain("arm") { + toolprefix = "arm-linux-gnueabihf-" + + cc = "${toolprefix}gcc" + cxx = "${toolprefix}g++" + + ar = "${toolprefix}ar" + ld = cxx + readelf = "${toolprefix}readelf" + nm = "${toolprefix}nm" + + toolchain_args = { + current_cpu = "arm" + current_os = "linux" + is_clang = false + } +} + +clang_toolchain("clang_x86") { + # Output linker map files for binary size analysis. + enable_linker_map = true + + toolchain_args = { + current_cpu = "x86" + current_os = "linux" + } +} + +gcc_toolchain("x86") { + cc = "gcc" + cxx = "g++" + + readelf = "readelf" + nm = "nm" + ar = "ar" + ld = cxx + + # Output linker map files for binary size analysis. + enable_linker_map = true + + toolchain_args = { + current_cpu = "x86" + current_os = "linux" + is_clang = false + } +} + +clang_toolchain("clang_x64") { + # Output linker map files for binary size analysis. + enable_linker_map = true + + strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir) + toolchain_args = { + current_cpu = "x64" + current_os = "linux" + } + shlib_extension = ".so" +} + +gcc_toolchain("x64") { + cc = "gcc" + cxx = "g++" + + readelf = "readelf" + nm = "nm" + ar = "ar" + ld = cxx + + # Output linker map files for binary size analysis. + enable_linker_map = true + + toolchain_args = { + current_cpu = "x64" + current_os = "linux" + is_clang = false + } +} diff --git a/build/toolchain/toolchain.gni b/build/toolchain/toolchain.gni new file mode 100755 index 0000000000000000000000000000000000000000..0f051224fa66f413dc91403ede2d75cbc938f592 --- /dev/null +++ b/build/toolchain/toolchain.gni @@ -0,0 +1,111 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Toolchain-related configuration that may be needed outside the context of the +# toolchain() rules themselves. + +#import("//build/misc/overrides/build.gni") + +declare_args() { + # If this is set to true, or if LLVM_FORCE_HEAD_REVISION is set to 1 + # in the environment, we use the revision in the llvm repo to determine + # the CLANG_REVISION to use, instead of the version hard-coded into + # //tools/clang/scripts/update.py. This should only be used in + # conjunction with setting LLVM_FORCE_HEAD_REVISION in the + # environment when `gclient runhooks` is run as well. + llvm_force_head_revision = false + + # Compile with Xcode version of clang instead of hermetic version shipped + # with the build. Used on iOS to ship official builds (as they are built + # with the version of clang shipped with Xcode). + use_xcode_clang = false + + # Used for binary size analysis. + # Currently disabled on LLD because of a bug (fixed upstream). + # See https://crbug.com/716209. + generate_linker_map = is_ohos && is_official_build + + # Use absolute file paths in the compiler diagnostics and __FILE__ macro + # if needed. + msvc_use_absolute_paths = false +} + +if (generate_linker_map) { + assert( + is_official_build, + "Linker map files should only be generated when is_official_build = true") + assert(current_os == "ohos" || target_os == "linux", + "Linker map files should only be generated for ohos and Linux") +} + +# The path to the hermetic install of Xcode. Only relevant when +hermetic_xcode_path = + rebase_path("//build/${target_os}_files/Xcode.app", "", root_build_dir) + +declare_args() { + if (is_clang) { + # Clang compiler version. Clang files are placed at version-dependent paths. + clang_version = "10.0.1" + } + use_custom_clang = true +} + +# Check target_os here instead of is_ios as this file is loaded for secondary +# toolchain (host toolchain in particular) but the argument is the same for +# all toolchains. +assert(!use_xcode_clang || target_os == "ios", + "Using Xcode's clang is only supported in iOS builds") + +# Extension for shared library files (including leading dot). +executable_extension = "" +if (is_mac) { + shlib_extension = ".dylib" +} else if (is_ohos && is_component_build) { + # By appending .z, we prevent name collisions with libraries already loaded by the ohos. + shlib_extension = ".z.so" +} else if (is_mingw) { + shlib_extension = ".dll" + executable_extension = ".exe" +} else if (is_posix) { + shlib_extension = ".so" +} else if (is_win) { + shlib_extension = ".dll" +} else { + assert(false, "Platform not supported") +} + +# Prefix for shared library files. +if (is_posix) { + shlib_prefix = "lib" +} else { + shlib_prefix = "" +} + +# While other "tool"s in a toolchain are specific to the target of that +# toolchain, the "stamp" and "copy" tools are really generic to the host; +# but each toolchain must define them separately. GN doesn't allow a +# template instantiation inside a toolchain definition, so some boilerplate +# has to be repeated in each toolchain to define these two tools. These +# four variables reduce the duplication in that boilerplate. +stamp_description = "STAMP {{output}}" +copy_description = "COPY {{source}} {{output}}" +if (host_os == "win") { + _tool_wrapper_path = + rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir) + stamp_command = "cmd /c type nul > \"{{output}}\"" + copy_command = + "$python_path $_tool_wrapper_path recursive-mirror {{source}} {{output}}" +} else { + stamp_command = "touch {{output}}" + copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" +} diff --git a/figures/zh-cn_image_arkcompiler.png b/figures/zh-cn_image_arkcompiler.png new file mode 100644 index 0000000000000000000000000000000000000000..4e34094c9c82cd80881078df9b5e5904dbe98a61 Binary files /dev/null and b/figures/zh-cn_image_arkcompiler.png differ