1# Copyright 2024 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"""Bazel transitions for the host device simulator.""" 16 17def _host_device_simulator_transition_impl(settings, attr): 18 # buildifier: disable=unused-variable 19 _ignore = settings, attr 20 return { 21 str(Label("//pw_log:backend")): str(Label("//pw_log_string")), 22 str(Label("//pw_log:backend_impl")): str(Label("//pw_log_string:impl")), 23 str(Label("//pw_log_string:handler_backend")): str(Label("//pw_system:log_backend")), 24 str(Label("//pw_sys_io:backend")): str(Label("//pw_sys_io_stdio")), 25 str(Label("//pw_system:io_backend")): str(Label("//pw_system:socket_target_io")), 26 } 27 28_host_device_simulator_transition = transition( 29 implementation = _host_device_simulator_transition_impl, 30 inputs = [], 31 outputs = [ 32 str(Label("//pw_log:backend")), 33 str(Label("//pw_log:backend_impl")), 34 str(Label("//pw_log_string:handler_backend")), 35 str(Label("//pw_sys_io:backend")), 36 str(Label("//pw_system:io_backend")), 37 ], 38) 39 40def _host_device_simulator_binary_impl(ctx): 41 out = ctx.actions.declare_file(ctx.label.name) 42 ctx.actions.symlink(output = out, is_executable = True, target_file = ctx.executable.binary) 43 return [DefaultInfo(files = depset([out]), executable = out)] 44 45host_device_simulator_binary = rule( 46 _host_device_simulator_binary_impl, 47 attrs = { 48 "binary": attr.label( 49 doc = "cc_binary build for the host_device_simulator", 50 cfg = _host_device_simulator_transition, 51 executable = True, 52 mandatory = True, 53 ), 54 "_allowlist_function_transition": attr.label( 55 default = "@bazel_tools//tools/allowlists/function_transition_allowlist", 56 ), 57 }, 58 doc = "Builds the specified binary for the host_device_simulator platform", 59 executable = True, 60) 61