1*61c4878aSAndroid Build Coastguard Worker# Copyright 2021 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Worker# Declares a group that builds a list of dependencies using multiple toolchains. 16*61c4878aSAndroid Build Coastguard Worker# 17*61c4878aSAndroid Build Coastguard Worker# In a multi-toolchain group, each dependency is built with each of the provided 18*61c4878aSAndroid Build Coastguard Worker# toolchains. This results in M x N targets being built, where M is the number 19*61c4878aSAndroid Build Coastguard Worker# of toolchains, and N is the number of targets listed in the `deps` variable. 20*61c4878aSAndroid Build Coastguard Worker# 21*61c4878aSAndroid Build Coastguard Worker# This template is useful for simplifying cases where you have multiple 22*61c4878aSAndroid Build Coastguard Worker# applications you would like to build under different toolchain contexts. 23*61c4878aSAndroid Build Coastguard Worker# 24*61c4878aSAndroid Build Coastguard Worker# Args: 25*61c4878aSAndroid Build Coastguard Worker# deps: (required) List of GN targets to build under each listed toolchain. 26*61c4878aSAndroid Build Coastguard Worker# toolchains: (required) A list of toolchain labels to build the dependencies 27*61c4878aSAndroid Build Coastguard Worker# with. 28*61c4878aSAndroid Build Coastguard Workertemplate("pw_multi_toolchain_group") { 29*61c4878aSAndroid Build Coastguard Worker assert(!defined(invoker.public_deps), 30*61c4878aSAndroid Build Coastguard Worker "Use `deps` for pw_multi_toolchain_group targets") 31*61c4878aSAndroid Build Coastguard Worker assert(defined(invoker.deps), "`deps` must be defined to use this template") 32*61c4878aSAndroid Build Coastguard Worker assert(defined(invoker.toolchains), 33*61c4878aSAndroid Build Coastguard Worker "`toolchains` must be defined to use this template") 34*61c4878aSAndroid Build Coastguard Worker group(target_name) { 35*61c4878aSAndroid Build Coastguard Worker deps = [] 36*61c4878aSAndroid Build Coastguard Worker public_deps = [] 37*61c4878aSAndroid Build Coastguard Worker foreach(tc, invoker.toolchains) { 38*61c4878aSAndroid Build Coastguard Worker foreach(item, invoker.deps) { 39*61c4878aSAndroid Build Coastguard Worker # Make sure targets don't explicitly reference a toolchain in their 40*61c4878aSAndroid Build Coastguard Worker # target label. If we poison any instances of "(", we can see a mismatch 41*61c4878aSAndroid Build Coastguard Worker # against the original string, indicating a toolchain was explicitly 42*61c4878aSAndroid Build Coastguard Worker # specified. 43*61c4878aSAndroid Build Coastguard Worker _poisioned_label = string_replace(item, "(", "!") 44*61c4878aSAndroid Build Coastguard Worker assert(item == _poisioned_label, 45*61c4878aSAndroid Build Coastguard Worker "$item can't explicitly specify a toolchain as part of " + 46*61c4878aSAndroid Build Coastguard Worker "a multi-toolchain group") 47*61c4878aSAndroid Build Coastguard Worker deps += [ "$item($tc)" ] 48*61c4878aSAndroid Build Coastguard Worker } 49*61c4878aSAndroid Build Coastguard Worker } 50*61c4878aSAndroid Build Coastguard Worker } 51*61c4878aSAndroid Build Coastguard Worker} 52