| # 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/rust/rustc_staticlib.gni") |
| import("config.gni") # icu_flavors, icu_fixup_deps |
| |
| # An ICU-aware rustc_staticlib. |
| # |
| # Args: |
| # |
| # - icu_deps: list(label): the target labels that need to be fixed up for |
| # ICU product assembly. Otherwise the same as deps. |
| # - icu_non_rust_deps: list(label): Same as above, but for non_rust_deps. |
| # - icu_test_deps: list(label): Same as above, but for test_deps. |
| # - icu_data_deps: list(label): Same as above, but for data_deps. |
| # - All other args are forwarded verbatim from the invoker. |
| # |
| # Refer to icu_source_set.gni for detailed comments on some constructs below, |
| # the ideas of which are commonly reused in all icu_* templates. |
| template("icu_rustc_staticlib") { |
| foreach(icu_flavor, icu_flavors) { |
| # While we could make do with shorter target labels, we're using a per-ICU |
| # commit ID so that we could possibly use targets from different builds. |
| rustc_staticlib( |
| "${target_name}.icu_${icu_flavor.name}_${icu_flavor.commit_id}") { |
| # Do not forward variables which the template does not support. In addition, |
| # treat "visibility" and "testonly" as special. |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "visibility", |
| "testonly", |
| "icu_deps", |
| "icu_non_rust_deps", |
| "icu_test_deps", |
| "icu_data_deps", |
| ]) |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "testonly", |
| ]) |
| |
| # If the invoker redefines the target output name, we need to append |
| # flavor identification to ensure all targets get separately-named |
| # subtargets. |
| if (defined(invoker.output_name)) { |
| output_name = |
| "${invoker.output_name}_${icu_flavor.name}_${icu_flavor.commit_id}" |
| } else if (defined(invoker.name)) { |
| name = "${invoker.name}_${icu_flavor.name}_${icu_flavor.commit_id}" |
| } |
| |
| _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([ |
| "icu_flavor", |
| "_flavored_icu_deps", |
| ]) |
| |
| if (defined(invoker.icu_deps)) { |
| if (!defined(deps)) { |
| deps = [] |
| } |
| |
| foreach(icu_dep, invoker.icu_deps) { |
| _relabel = get_label_info(icu_dep, "label_no_toolchain") |
| deps += [ "${_relabel}.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 += [ |
| "//src/lib/icu:version", |
| "//src/lib/icu:version_${icu_flavor.name}", |
| ] |
| configs -= [ "//src/lib/icu:version" ] |
| } |
| |
| if (defined(invoker.icu_non_rust_deps)) { |
| if (!defined(non_rust_deps)) { |
| non_rust_deps = [] |
| } |
| |
| non_rust_deps += icu_fixup_deps + _flavored_icu_deps |
| non_rust_deps -= icu_fixup_deps |
| |
| foreach(icu_dep, invoker.icu_non_rust_deps) { |
| _relabel = get_label_info(icu_dep, "label_no_toolchain") |
| non_rust_deps += [ "${_relabel}.icu_${icu_flavor.name}_${icu_flavor.commit_id}(${current_toolchain})" ] |
| } |
| } |
| } |
| } |
| |
| rustc_staticlib(target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "visibility", |
| "testonly", |
| "icu_deps", |
| "icu_non_rust_deps", |
| "icu_test_deps", |
| "icu_data_deps", |
| ]) |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "testonly", |
| ]) |
| |
| if (defined(invoker.icu_deps)) { |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += invoker.icu_deps |
| } |
| if (defined(invoker.icu_non_rust_deps)) { |
| if (!defined(non_rust_deps)) { |
| non_rust_deps = [] |
| } |
| non_rust_deps += invoker.non_rust_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 |
| } |
| } |
| } |