| # 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, |
| "*", |
| [ |
| "testonly", |
| "visibility", |
| "icu_deps", |
| "icu_public_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_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) { |
| 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, |
| "*", |
| [ |
| "testonly", |
| "visibility", |
| "icu_deps", |
| "icu_public_deps", |
| ]) |
| 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, |
| "*", |
| [ |
| "testonly", |
| "visibility", |
| "icu_deps", |
| "icu_public_deps", |
| ]) |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| 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 |
| } |
| } |
| } |