1# Copyright (c) 2023 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 14template("rust_cxx") { 15 assert(defined(invoker.sources), 16 "Must specify the Rust file to use as input.") 17 18 action_foreach(target_name) { 19 sources = invoker.sources 20 21 output_h = "{{source_gen_dir}}/{{source_file_part}}.h" 22 output_cc = "{{source_gen_dir}}/{{source_file_part}}.cc" 23 24 if (ohos_indep_compiler_enable) { 25 cxxbridge_out_dir = "//binarys/third_party/rust/crates/cxx/innerapis/cxxbridge/clang_x64/libs" 26 cxxbridge_executable = rebase_path("${cxxbridge_out_dir}/cxxbridge") 27 } else { 28 cxxbridge_target = 29 "//third_party/rust/crates/cxx/gen/cmd:cxxbridge($host_toolchain)" 30 cxxbridge_out_dir = get_label_info(cxxbridge_target, "root_out_dir") 31 cxxbridge_executable = 32 rebase_path("${cxxbridge_out_dir}/thirdparty/rust_cxx/cxxbridge") 33 } 34 35 script = "//build/templates/rust/rust_cxxbridge.py" 36 inputs = [ 37 cxxbridge_executable, 38 script, 39 ] 40 external_deps = [ "rust_cxx:cxxbridge($host_toolchain)" ] 41 outputs = [ 42 output_h, 43 output_cc, 44 ] 45 46 args = [ 47 "--cxxbridge", 48 rebase_path(cxxbridge_executable, root_build_dir), 49 "--cc", 50 output_cc, 51 "--header", 52 output_h, 53 "--", 54 "{{source}}", 55 ] 56 } 57} 58