blob: b607cf8994375081fb169a5f8539e4d0265703b7 [file] [log] [blame]
Ben Clayton65625552023-09-11 18:33:43 +00001load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "bool_flag")
2load("@bazel_skylib//lib:selects.bzl", "selects")
3
4def declare_bool_flag(name, default):
5 """Create a boolean flag and two config_settings with the names: <name>_true, <name>_false.
6
7 declare_bool_flag is a Bazel Macro that defines a boolean flag with the given name two
8 config_settings, one for True, one for False. Reminder that Bazel has special syntax for
9 unsetting boolean flags, but this does not work well with aliases.
10 https://docs.bazel.build/versions/main/skylark/config.html#using-build-settings-on-the-command-line
11 Thus it is best to define both an "enabled" alias and a "disabled" alias.
12
13 Args:
14 name: string, the name of the flag to create and use for the config_settings
15 default: boolean, if the flag should default to on or off.
16 """
17
18 bool_flag(name = name, build_setting_default = default)
19
20 native.config_setting(
21 name = name + "_true",
22 flag_values = {
23 ":" + name: "True",
24 },
25 visibility = ["//visibility:public"],
26 )
27
28 native.config_setting(
29 name = name + "_false",
30 flag_values = {
31 ":" + name: "False",
32 },
33 visibility = ["//visibility:public"],
34 )
35
36def declare_os_flag():
37 """Creates the 'os' string flag that specifies the OS to target, and a pair of
Ben Clayton5c69ff42023-11-23 13:32:36 +000038 'tint_build_is_<os>_true' and 'tint_build_is_<os>_false' targets.
Ben Clayton65625552023-09-11 18:33:43 +000039
40 The OS flag can be specified on the command line with '--//src/tint:os=<os>'
41 """
42
43 OSes = [
44 "win",
45 "linux",
46 "mac",
47 "other"
48 ]
49
50 string_flag(
51 name = "os",
52 build_setting_default = "other",
53 values = OSes,
54 )
55
56 for os in OSes:
57 native.config_setting(
Ben Clayton5c69ff42023-11-23 13:32:36 +000058 name = "tint_build_is_{}_true".format(os),
Ben Clayton65625552023-09-11 18:33:43 +000059 flag_values = { ":os": os },
60 visibility = ["//visibility:public"],
61 )
62 selects.config_setting_group(
Ben Clayton5c69ff42023-11-23 13:32:36 +000063 name = "tint_build_is_{}_false".format(os),
André Cruz9aa5b552023-11-23 21:25:31 +000064 match_any = [ "tint_build_is_{}_true".format(other) for other in OSes if other != os],
Ben Clayton65625552023-09-11 18:33:43 +000065 visibility = ["//visibility:public"],
66 )
67
68COPTS = [
69 "-fno-rtti",
70 "-fno-exceptions",
71 "--std=c++17",
72] + select({
73 "//src/tint:tint_build_glsl_writer_true": [ "-DTINT_BUILD_GLSL_WRITER" ],
74 "//conditions:default": [],
75}) + select({
76 "//src/tint:tint_build_hlsl_writer_true": [ "-DTINT_BUILD_HLSL_WRITER" ],
77 "//conditions:default": [],
78}) + select({
79 "//src/tint:tint_build_ir_true": [ "-DTINT_BUILD_IR" ],
80 "//conditions:default": [],
81}) + select({
82 "//src/tint:tint_build_msl_writer_true": [ "-DTINT_BUILD_MSL_WRITER" ],
83 "//conditions:default": [],
84}) + select({
85 "//src/tint:tint_build_spv_reader_true": [ "-DTINT_BUILD_SPV_READER" ],
86 "//conditions:default": [],
87}) + select({
88 "//src/tint:tint_build_spv_writer_true": [ "-DTINT_BUILD_SPV_WRITER" ],
89 "//conditions:default": [],
90}) + select({
91 "//src/tint:tint_build_wgsl_reader_true": [ "-DTINT_BUILD_WGSL_READER" ],
92 "//conditions:default": [],
93}) + select({
94 "//src/tint:tint_build_wgsl_writer_true": [ "-DTINT_BUILD_WGSL_WRITER" ],
95 "//conditions:default": [],
96})