forked from bazelembedded/bazel-embedded
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcc.bzl
144 lines (136 loc) · 4.04 KB
/
gcc.bzl
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
load(
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
)
load("//toolchains/features/embedded:type.bzl", "all_embedded_features")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
_CPP_ALL_COMPILE_ACTIONS = [
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
ACTION_NAMES.lto_backend,
ACTION_NAMES.clif_match,
]
_C_ALL_COMPILE_ACTIONS = [
ACTION_NAMES.assemble,
ACTION_NAMES.c_compile,
]
_LD_ALL_ACTIONS = [
ACTION_NAMES.cpp_link_executable,
]
# Run time type information is enabled by default
_RUNTIME_TYPE_INFORMATION_FEATURE = feature(
name = "runtime_type_information",
enabled = True,
flag_sets = [
flag_set(
actions = _CPP_ALL_COMPILE_ACTIONS,
flag_groups = [
flag_group(
flags = [
# Disable runtime type information
"-fno-rtti",
],
),
],
),
],
)
_EXCEPTIONS_FEATURE = feature(
name = "exceptions",
enabled = True,
flag_sets = [
flag_set(
actions = _CPP_ALL_COMPILE_ACTIONS,
flag_groups = [
flag_group(
flags = [
# Disable Exceptions
"-fno-exceptions",
"-fno-non-call-exceptions",
],
),
],
),
],
)
_SYS_SPEC_FEATURE = feature(
name = "sys_spec",
enabled = True,
flag_sets = [
flag_set(
actions = _CPP_ALL_COMPILE_ACTIONS,
flag_groups = [
flag_group(
flags = [
"-mabi=aapcs",
"-mthumb",
"-specs=nano.specs",
"-specs=nosys.specs",
],
),
],
),
flag_set(
actions = _LD_ALL_ACTIONS,
flag_groups = [
flag_group(
flags = [
# Disable Exceptions
"-lc",
"-lnosys",
],
),
],
),
],
)
_CC_CONSTRUCTOR_DESTRUCTOR_FEATURE = feature(
name = "cc_constructor_destructor",
enabled = True,
flag_sets = [
flag_set(
actions = _CPP_ALL_COMPILE_ACTIONS + _C_ALL_COMPILE_ACTIONS,
flag_groups = [
flag_group(
flags = [
# Indicate that this program may not neccesarily be able to use standard system calls
"-ffreestanding",
# Instantiate global variables only once
"-fno-common",
# Emits guards against functions that have references to local array definitions
"-fstack-protector-strong",
],
),
],
),
flag_set(
actions = _CPP_ALL_COMPILE_ACTIONS,
flag_groups = [
flag_group(
flags = [
# Disable teardown/destructors for static variables
"-fno-use-cxa-atexit",
# Disable threadsafe statics
"-fno-threadsafe-statics",
],
),
],
),
],
)
def GetGccEmbeddedFeatures():
""" GetGccEmbeddedFeatures returns features relevant to embedded developement
"""
return all_embedded_features(
exceptions = _EXCEPTIONS_FEATURE,
runtime_type_information = _RUNTIME_TYPE_INFORMATION_FEATURE,
sys_spec = _SYS_SPEC_FEATURE,
cc_constructor_destructor = _CC_CONSTRUCTOR_DESTRUCTOR_FEATURE,
)