1# Copyright 2021 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 15# Declares a group that builds a list of dependencies using multiple toolchains. 16# 17# In a multi-toolchain group, each dependency is built with each of the provided 18# toolchains. This results in M x N targets being built, where M is the number 19# of toolchains, and N is the number of targets listed in the `deps` variable. 20# 21# This template is useful for simplifying cases where you have multiple 22# applications you would like to build under different toolchain contexts. 23# 24# Args: 25# deps: (required) List of GN targets to build under each listed toolchain. 26# toolchains: (required) A list of toolchain labels to build the dependencies 27# with. 28template("pw_multi_toolchain_group") { 29 assert(!defined(invoker.public_deps), 30 "Use `deps` for pw_multi_toolchain_group targets") 31 assert(defined(invoker.deps), "`deps` must be defined to use this template") 32 assert(defined(invoker.toolchains), 33 "`toolchains` must be defined to use this template") 34 group(target_name) { 35 deps = [] 36 public_deps = [] 37 foreach(tc, invoker.toolchains) { 38 foreach(item, invoker.deps) { 39 # Make sure targets don't explicitly reference a toolchain in their 40 # target label. If we poison any instances of "(", we can see a mismatch 41 # against the original string, indicating a toolchain was explicitly 42 # specified. 43 _poisioned_label = string_replace(item, "(", "!") 44 assert(item == _poisioned_label, 45 "$item can't explicitly specify a toolchain as part of " + 46 "a multi-toolchain group") 47 deps += [ "$item($tc)" ] 48 } 49 } 50 } 51} 52