1# Protocol Buffers - Google's data interchange format 2# Copyright 2008 Google Inc. All rights reserved. 3# 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file or at 6# https://developers.google.com/open-source/licenses/bsd 7""" 8A helper rule that reads a native boolean flag. 9""" 10 11load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") 12 13def _impl(ctx): 14 return [BuildSettingInfo(value = ctx.attr.value)] 15 16_native_bool_flag_rule = rule( 17 implementation = _impl, 18 attrs = {"value": attr.bool()}, 19) 20 21def native_bool_flag(*, name, flag, match_value = "true", result = True, **kwargs): 22 _native_bool_flag_rule( 23 name = name, 24 value = select({ 25 name + "_setting": result, 26 "//conditions:default": not result, 27 }), 28 **kwargs 29 ) 30 31 native.config_setting( 32 name = name + "_setting", 33 values = {flag: match_value}, 34 visibility = ["//visibility:private"], 35 ) 36