-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBUILD
More file actions
149 lines (132 loc) · 4.33 KB
/
BUILD
File metadata and controls
149 lines (132 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_library")
CODSPEED_VERSION = module_version()
config_setting(
name = "windows",
constraint_values = ["@platforms//os:windows"],
)
# Strict warnings mode
string_flag(
name = "strict_warnings",
build_setting_default = "off",
values = [
"off",
"on",
],
)
config_setting(
name = "strict_warnings_enabled",
flag_values = {":strict_warnings": "on"},
)
config_setting(
name = "windows_strict_warnings",
constraint_values = ["@platforms//os:windows"],
flag_values = {":strict_warnings": "on"},
)
# IMPORTANT: Keep in sync with instrument-hooks/ci.yml (COMMON_CFLAGS)
instrument_hooks_cflags = [
"-Wno-format",
"-Wno-format-security",
"-Wno-unused-but-set-variable",
"-Wno-unused-const-variable",
"-Wno-type-limits",
"-Wno-uninitialized",
# When cross-compiling:
"-Wno-constant-conversion",
"-Wno-incompatible-pointer-types",
"-Wno-unused-function",
]
instrument_hooks_cflags_windows = [
"/wd4101", # unreferenced local variable (equivalent to -Wno-unused-variable)
"/wd4189", # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
"/wd4100", # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
"/wd4245", # signed/unsigned mismatch
"/wd4132", # const object should be initialized
"/wd4146", # unary minus operator applied to unsigned type
]
# Instrument-hooks library with warning suppressions
cc_library(
name = "instrument_hooks",
srcs = ["instrument-hooks/dist/core.c"],
hdrs = glob(["instrument-hooks/includes/*.h"]),
includes = ["instrument-hooks/includes"],
copts = select({
":windows_strict_warnings": ["/W4","/WX"] + instrument_hooks_cflags_windows,
":windows": instrument_hooks_cflags_windows,
":strict_warnings_enabled": ["-Wall", "-Werror"] + instrument_hooks_cflags,
"//conditions:default": instrument_hooks_cflags,
}),
visibility = ["//visibility:public"],
)
# Generate a header with C++ toolchain information
genrule(
name = "toolchain_info_gen",
srcs = ["scripts/detect_toolchain.sh"],
outs = ["toolchain_info.h"],
cmd = """
case "$(COMPILATION_MODE)" in
opt) BUILD_TYPE="Release" ;;
dbg) BUILD_TYPE="Debug" ;;
fastbuild) BUILD_TYPE="FastBuild" ;;
*) BUILD_TYPE="$(COMPILATION_MODE)" ;;
esac
bash $(location scripts/detect_toolchain.sh) "$(CC)" "$$BUILD_TYPE" > $@
""",
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
)
cc_library(
name = "toolchain_info",
hdrs = [":toolchain_info_gen"],
includes = ["."],
)
# Define the codspeed library
cc_library(
name = "codspeed",
srcs = glob(["src/**/*.cpp"] + ["src/**/*.h"]),
hdrs = glob(["include/**/*.h"] + ["include/**/*.hpp"]),
includes = ["include"],
copts = select({
":windows": ["/std:c++17"],
"//conditions:default": ["-std=c++17"],
}),
defines = [
"CODSPEED_VERSION=\\\"{}\\\"".format(CODSPEED_VERSION),
] + select({
":instrumentation_mode": ["CODSPEED_ENABLED", "CODSPEED_ANALYSIS", "CODSPEED_MODE_DISPLAY=\\\"instrumentation\\\""],
":simulation_mode": ["CODSPEED_ENABLED", "CODSPEED_ANALYSIS", "CODSPEED_MODE_DISPLAY=\\\"simulation\\\""],
":memory_mode": ["CODSPEED_ENABLED", "CODSPEED_ANALYSIS", "CODSPEED_MODE_DISPLAY=\\\"memory\\\""],
":walltime_mode": ["CODSPEED_ENABLED", "CODSPEED_WALLTIME", "CODSPEED_MODE_DISPLAY=\\\"walltime\\\""],
"//conditions:default": [],
}),
deps = [":instrument_hooks", ":toolchain_info"],
visibility = ["//visibility:public"],
)
# Codspeed mode
string_flag(
name = "codspeed_mode",
build_setting_default = "off",
values = [
"off",
"instrumentation",
"simulation",
"memory",
"walltime",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "instrumentation_mode",
flag_values = {":codspeed_mode": "instrumentation"},
)
config_setting(
name = "simulation_mode",
flag_values = {":codspeed_mode": "simulation"},
)
config_setting(
name = "memory_mode",
flag_values = {":codspeed_mode": "memory"},
)
config_setting(
name = "walltime_mode",
flag_values = {":codspeed_mode": "walltime"},
)