1# Copyright (c) 2024-2025 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/config/clang/clang.gni") 15import("//build/ohos.gni") 16 17is_ohos_standard_system = is_standard_system && !is_arkui_x 18use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64" 19use_mac = "${current_os}_${current_cpu}" == "mac_x64" || 20 "${current_os}_${current_cpu}" == "mac_arm64" 21use_ios = "${current_os}_${current_cpu}" == "ios_x64" || 22 "${current_os}_${current_cpu}" == "ios_arm64" 23use_linux = "${current_os}_${current_cpu}" == "linux_x64" 24windows_buildtool = "//build/toolchain/mingw:mingw_x86_64" 25 26if (!defined(default_phone_source_dir)) { 27 default_phone_source_dir = "/" 28} 29objcopy_default = "${default_phone_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy" 30objcopy_mingw = "${default_phone_source_dir}/prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8/x86_64-w64-mingw32/bin/objcopy" 31objcopy_x86_64 = "${default_clang_base_path}/bin/llvm-objcopy" 32if ("${current_os}_${current_cpu}" == "mac_arm64") { 33 mac_buildtool = "//build/toolchain/mac:clang_arm64" 34} else if ("${current_os}_${current_cpu}" == "mac_x64") { 35 mac_buildtool = "//build/toolchain/mac:clang_x64" 36} 37objcopy_clang = "$clang_base_path/bin/llvm-objcopy" 38if (is_ohos_standard_system) { 39 objcopy_default = "//prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy" 40} else if (is_arkui_x) { 41 if (host_os == "mac") { 42 objcopy_default = objcopy_clang 43 } else if (defined(phone_objcopy)) { 44 objcopy_default = phone_objcopy 45 } 46} 47 48template("gen_obj") { 49 name = target_name 50 action("gen_obj_" + name) { 51 visibility = [ ":*" ] # Only targets in this file can depend on this. 52 53 if (use_mingw_win) { 54 objcopy_tool = objcopy_mingw 55 script = "//build/config/components/ace_engine/build_resource_to_bytecode.py" 56 } else if (use_mac || target_os == "ios") { 57 objcopy_tool = objcopy_clang 58 script = "//build/config/components/ace_engine/build_resource_to_bytecode.py" 59 } else if (use_linux) { 60 objcopy_tool = objcopy_x86_64 61 script = "//build/config/components/ace_engine/build_resource_to_bytecode.py" 62 } else if (target_cpu == "x86_64") { 63 objcopy_tool = objcopy_x86_64 64 script = "//build/scripts/run_objcopy.py" 65 } else { 66 objcopy_tool = objcopy_default 67 script = "//build/scripts/run_objcopy.py" 68 } 69 70 args = [ 71 "--objcopy", 72 rebase_path(objcopy_tool), 73 "--input", 74 rebase_path(invoker.input), 75 "--output", 76 rebase_path(invoker.output), 77 "--arch", 78 current_cpu, 79 ] 80 81 deps = [] 82 deps += invoker.snapshot_dep 83 84 inputs = [ invoker.input ] 85 outputs = [ invoker.output ] 86 } 87 88 source_set("gen_obj_src_" + name) { 89 sources = [ invoker.output ] 90 deps = [ ":gen_obj_" + name ] 91 } 92} 93