1# Copyright 2024 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://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, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Implementation of the cc_sysroot macro.""" 15 16load("//cc/toolchains:args.bzl", "cc_args") 17 18visibility("public") 19 20_DEFAULT_SYSROOT_ACTIONS = [ 21 Label("//cc/toolchains/actions:cpp_compile_actions"), 22 Label("//cc/toolchains/actions:c_compile"), 23 Label("//cc/toolchains/actions:link_actions"), 24] 25 26def cc_sysroot(*, name, sysroot, actions = _DEFAULT_SYSROOT_ACTIONS, args = [], **kwargs): 27 """Creates args for a sysroot. 28 29 Args: 30 name: (str) The name of the target 31 sysroot: (bazel_skylib's directory rule) The directory that should be the 32 sysroot. 33 actions: (List[Label]) Actions the `--sysroot` flag should be applied to. 34 args: (List[str]) Extra command-line args to add. 35 **kwargs: kwargs to pass to cc_args. 36 """ 37 cc_args( 38 name = name, 39 actions = actions, 40 args = ["--sysroot={sysroot}"] + args, 41 format = {"sysroot": sysroot}, 42 **kwargs 43 ) 44