78 lines
2.4 KiB
Plaintext
78 lines
2.4 KiB
Plaintext
|
# Copyright (c) 2023 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("rust_cxx") {
|
||
|
assert(defined(invoker.sources),
|
||
|
"Must specify the Rust file to use as input.")
|
||
|
|
||
|
action_foreach(target_name) {
|
||
|
sources = invoker.sources
|
||
|
|
||
|
output_h = "{{source_gen_dir}}/{{source_file_part}}.h"
|
||
|
output_cc = "{{source_gen_dir}}/{{source_file_part}}.cc"
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
cxxbridge_target =
|
||
|
"//third_party/rust/crates/cxx/gen/cmd:cxxbridge($host_toolchain)"
|
||
|
|
||
|
cxxbridge_out_dir = get_label_info(cxxbridge_target, "root_out_dir")
|
||
|
cxxbridge_executable = rebase_path(
|
||
|
"${cxxbridge_out_dir}/${subsystem_name}/${part_name}/cxxbridge")
|
||
|
|
||
|
script = "//build/templates/rust/rust_cxxbridge.py"
|
||
|
inputs = [
|
||
|
cxxbridge_executable,
|
||
|
script,
|
||
|
]
|
||
|
deps = [ cxxbridge_target ]
|
||
|
outputs = [
|
||
|
output_h,
|
||
|
output_cc,
|
||
|
]
|
||
|
|
||
|
args = [
|
||
|
"--cxxbridge",
|
||
|
rebase_path(cxxbridge_executable, root_build_dir),
|
||
|
"--cc",
|
||
|
output_cc,
|
||
|
"--header",
|
||
|
output_h,
|
||
|
"--",
|
||
|
"{{source}}",
|
||
|
]
|
||
|
}
|
||
|
}
|