blob: 8a72f89eec06c99ee8a756b122cef932aad6222d [file] [log] [blame]
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/dist/renamed_binary.gni")
import("//build/rust/rustc_binary.gni")
import("config.gni") # icu_flavors, icu_fixup_deps
set_defaults("icu_rustc_binary") {
configs = default_executable_configs + default_rust_configs
}
template("_common") {
forward_variables_from(invoker, [ "output_name" ])
not_needed([
"output_name",
"test_deps",
])
_shadow = "${target_name}.original"
if (defined(output_name)) {
original_output_name = output_name
} else {
original_output_name = target_name
}
rustc_binary(_shadow) {
if (defined(invoker.test_configs)) {
test_configs = invoker.test_configs
}
forward_variables_from(invoker,
"*",
[
"target_name", # Workaround for
# https://fxbug.dev/42083609.
"testonly",
"visibility",
"icu_deps",
"icu_public_deps",
"icu_non_rust_deps",
"icu_test_deps",
"icu_data_deps",
])
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
# While rustc_binary must deal with soft migrations, we do not have to,
# hence assert and fail right away.
assert(!defined(invoker.name),
"name is deprecated: use output_name instead")
_flavored_icu_deps = [
get_label_info("//third_party/icu/${icu_flavor.name}:icu",
"label_with_toolchain"),
get_label_info("//third_party/icu/${icu_flavor.name}:icudata",
"label_with_toolchain"),
]
not_needed([
"output_name",
"_flavored_icu_deps",
])
# Fix-up executable naming.
if (defined(output_name)) {
output_name =
"${output_name}_icu_${icu_flavor.name}_${icu_flavor.commit_id}"
} else {
output_name = target_name
}
if (defined(invoker.icu_deps)) {
if (!defined(deps)) {
deps = []
}
foreach(icu_dep, invoker.icu_deps) {
deps += [ "${icu_dep}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
if (defined(invoker.icu_public_deps)) {
if (!defined(deps)) {
public_deps = []
}
foreach(icu_dep, invoker.icu_public_deps) {
public_deps += [ "${icu_dep}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
if (defined(invoker.icu_test_deps)) {
if (!defined(test_deps)) {
test_deps = []
}
foreach(icu_dep, invoker.icu_test_deps) {
_relabel = get_label_info(icu_dep, "label_no_toolchain")
test_deps += [ "${_relabel}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
if (defined(invoker.icu_data_deps)) {
if (!defined(data_deps)) {
data_deps = []
}
foreach(icu_dep, invoker.icu_data_deps) {
_relabel = get_label_info(icu_dep, "label_no_toolchain")
data_deps += [ "${_relabel}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
if (!defined(configs)) {
configs = []
}
configs += [
"//src/lib/icu:version",
"//src/lib/icu:version_${icu_flavor.name}",
]
configs -= [ "//src/lib/icu:version" ]
if (!defined(non_rust_deps)) {
non_rust_deps = []
}
non_rust_deps += icu_fixup_deps + _flavored_icu_deps
non_rust_deps -= icu_fixup_deps
if (defined(invoker.icu_non_rust_deps)) {
foreach(icu_dep, invoker.icu_non_rust_deps) {
non_rust_deps += [ "${icu_dep}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ]
}
}
}
# The shadow binary must be renamed after compilation, because otherwise it
# will have the same name as the binary produced by $target_name.
renamed_binary(target_name) {
forward_variables_from(invoker,
"*",
[
"deps",
"icu_deps",
"icu_public_deps",
"public_deps",
"testonly",
"visibility",
])
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
source = "$root_out_dir/${output_name}_icu_${icu_flavor.name}_${icu_flavor.commit_id}"
dest = "bin/${original_output_name}"
source_deps = [ ":${_shadow}" ]
if (!defined(deps)) {
deps = []
}
deps += [ ":${_shadow}" ]
}
}
# An ICU-aware rustc_binary.
#
# Args:
#
# - icu_deps: list(label): the target labels that need to be fixed up for
# ICU product assembly. Otherwise the same as deps.
# - icu_public_deps: list(label): Same as above, but for public_deps
#
# All other args are forwarded verbatim from the invoker.
template("icu_rustc_binary") {
foreach(flavor, icu_flavors) {
_common("${target_name}.icu_${flavor.name}_${flavor.commit_id}") {
forward_variables_from(invoker, "*")
icu_flavor = flavor
}
}
rustc_binary(target_name) {
if (defined(invoker.test_configs)) {
test_configs = invoker.test_configs
}
forward_variables_from(invoker,
"*",
[
"icu_data_deps",
"icu_deps",
"icu_non_rust_deps",
"icu_public_deps",
"icu_test_deps",
"testonly",
"visibility",
])
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
# For a normal target, just copy to a regular parameter.
if (defined(invoker.icu_deps)) {
if (!defined(deps)) {
deps = []
}
deps += invoker.icu_deps
}
if (defined(invoker.icu_public_deps)) {
if (!defined(public_deps)) {
public_deps = []
}
public_deps += invoker.icu_public_deps
}
if (defined(invoker.icu_test_deps)) {
if (!defined(test_deps)) {
test_deps = []
}
test_deps += invoker.icu_test_deps
}
if (defined(invoker.icu_data_deps)) {
if (!defined(data_deps)) {
data_deps = []
}
data_deps += invoker.icu_data_deps
}
# A binary must be linked against the ICU library here, since deps are
# not guaranteeed to propagate that requirement.
if (!defined(non_rust_deps)) {
non_rust_deps = []
}
# We know that we need ICU libraries to be linked here.
non_rust_deps += icu_fixup_deps_no_testonly
if (defined(invoker.icu_non_rust_deps)) {
non_rust_deps += invoker.icu_non_rust_deps
}
}
}