1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/gn_internal/build_target.gni") 18 19# Note: In general, prefer to import target_types.gni rather than this file. 20# 21# This template wraps a configurable target type specified by the current 22# toolchain to be used for all pw_rust_executable targets. This allows projects 23# to stamp out unique build logic for each pw_rust_executable target. 24# This wrapper is analogous to pw_executable with additions to support rust 25# specific parameters such as rust edition and cargo config features. 26# 27# Default configs, default visibility, and link deps are applied to the target 28# before forwarding to the underlying type as specified by 29# pw_build_EXECUTABLE_TARGET_TYPE. 30# 31# For more information on the features provided by this template, see the full 32# docs at https://pigweed.dev/pw_build/?highlight=pw_rust_executable. 33template("pw_rust_executable") { 34 pw_internal_build_target(target_name) { 35 forward_variables_from(invoker, "*") 36 37 _edition = "2021" 38 if (defined(invoker.edition)) { 39 _edition = invoker.edition 40 } 41 assert(_edition == "2015" || _edition == "2018" || _edition == "2021", 42 "edition ${_edition} is not supported") 43 44 if (defined(invoker.configs)) { 45 configs = invoker.configs 46 } else { 47 configs = [] 48 } 49 configs += [ "$dir_pw_build:rust_edition_${_edition}" ] 50 51 underlying_target_type = pw_build_EXECUTABLE_TARGET_TYPE 52 target_type_file = pw_build_EXECUTABLE_TARGET_TYPE_FILE 53 output_dir = "${target_out_dir}/bin" 54 add_global_link_deps = true 55 } 56} 57