@@ -96,87 +96,101 @@ def cc_toolchain_config(
96
96
97
97
is_xcompile = not (host_os == target_os and host_arch == target_arch )
98
98
99
+ # Default compiler flags:
100
+ compile_flags = [
101
+ "--target=" + target_system_name ,
102
+ # Security
103
+ "-U_FORTIFY_SOURCE" , # https://github.com/google/sanitizers/issues/247
104
+ "-fstack-protector" ,
105
+ "-fno-omit-frame-pointer" ,
106
+ # Diagnostics
107
+ "-fcolor-diagnostics" ,
108
+ "-Wall" ,
109
+ "-Wthread-safety" ,
110
+ "-Wself-assign" ,
111
+ ]
112
+
113
+ dbg_compile_flags = ["-g" , "-fstandalone-debug" ]
114
+
115
+ opt_compile_flags = [
116
+ "-g0" ,
117
+ "-O2" ,
118
+ "-D_FORTIFY_SOURCE=1" ,
119
+ "-DNDEBUG" ,
120
+ "-ffunction-sections" ,
121
+ "-fdata-sections" ,
122
+ ]
123
+
124
+ link_flags = [
125
+ "--target=" + target_system_name ,
126
+ "-lm" ,
127
+ "-no-canonical-prefixes" ,
128
+ ]
129
+
99
130
# Linker flags:
100
131
if host_os == "darwin" and not is_xcompile :
101
132
# lld is experimental for Mach-O, so we use the native ld64 linker.
102
133
use_lld = False
103
- linker_flags = [
134
+ link_flags . extend ( [
104
135
"-headerpad_max_install_names" ,
105
136
"-undefined" ,
106
137
"dynamic_lookup" ,
107
- ]
138
+ ])
108
139
else :
109
140
# We prefer the lld linker.
110
141
# Note that for xcompiling from darwin to linux, the native ld64 is
111
142
# not an option because it is not a cross-linker, so lld is the
112
143
# only option.
113
144
use_lld = True
114
- linker_flags = [
145
+ link_flags . extend ( [
115
146
"-fuse-ld=lld" ,
116
147
"-Wl,--build-id=md5" ,
117
148
"-Wl,--hash-style=gnu" ,
118
149
"-Wl,-z,relro,-z,now" ,
119
- ]
150
+ ])
120
151
152
+ # Flags related to C++ standard.
121
153
# The linker has no way of knowing if there are C++ objects; so we
122
154
# always link C++ libraries.
123
- if host_os == "linux" and not is_xcompile :
124
- # For single-platform linux builds, we can statically link the bundled
125
- # libraries.
126
- linker_flags .extend ([
127
- "-L{}lib" .format (toolchain_path_prefix ),
128
- "-l:libc++.a" ,
129
- "-l:libc++abi.a" ,
130
- "-l:libunwind.a" ,
131
- # Compiler runtime features.
132
- "-rtlib=compiler-rt" ,
133
- # To support libunwind.
134
- "-lpthread" ,
135
- "-ldl" ,
136
- ])
155
+ if not is_xcompile :
156
+ cxx_flags = [
157
+ "-std=c++17" ,
158
+ "-stdlib=libc++" ,
159
+ ]
160
+ if use_lld :
161
+ # For single-platform builds, we can statically link the bundled
162
+ # libraries.
163
+ link_flags .extend ([
164
+ "-L{}lib" .format (toolchain_path_prefix ),
165
+ "-l:libc++.a" ,
166
+ "-l:libc++abi.a" ,
167
+ "-l:libunwind.a" ,
168
+ # Compiler runtime features.
169
+ "-rtlib=compiler-rt" ,
170
+ # To support libunwind.
171
+ "-lpthread" ,
172
+ "-ldl" ,
173
+ ])
174
+ else :
175
+ # TODO: Not sure how to achieve static linking of bundled libraries
176
+ # with ld64; maybe we don't really need it.
177
+ link_flags .extend ([
178
+ "-lc++" ,
179
+ "-lc++abi" ,
180
+ ])
137
181
else :
182
+ cxx_flags = [
183
+ "-std=c++17" ,
184
+ "-stdlib=libstdc++" ,
185
+ ]
186
+
138
187
# For xcompile, we expect to pick up these libraries from the sysroot.
139
- # TODO: For single-platform darwin builds, we can statically link the
140
- # bundled libraries but I do not know the right flags to make it
141
- # happen.
142
- linker_flags .extend ([
143
- "-lc++" ,
144
- "-lc++abi" ,
188
+ link_flags .extend ([
189
+ "-l:libstdc++.a" ,
145
190
])
146
191
147
- link_flags = [
148
- "-lm" ,
149
- "-no-canonical-prefixes" ,
150
- ] + linker_flags
151
-
152
192
opt_link_flags = ["-Wl,--gc-sections" ] if target_os == "linux" else []
153
193
154
- # Default compiler flags:
155
- compile_flags = [
156
- # Security
157
- "-U_FORTIFY_SOURCE" , # https://github.com/google/sanitizers/issues/247
158
- "-fstack-protector" ,
159
- "-fno-omit-frame-pointer" ,
160
- # Diagnostics
161
- "-fcolor-diagnostics" ,
162
- "-Wall" ,
163
- "-Wthread-safety" ,
164
- "-Wself-assign" ,
165
- ]
166
-
167
- dbg_compile_flags = ["-g" , "-fstandalone-debug" ]
168
-
169
- opt_compile_flags = [
170
- "-g0" ,
171
- "-O2" ,
172
- "-D_FORTIFY_SOURCE=1" ,
173
- "-DNDEBUG" ,
174
- "-ffunction-sections" ,
175
- "-fdata-sections" ,
176
- ]
177
-
178
- cxx_flags = ["-std=c++17" , "-stdlib=libc++" ]
179
-
180
194
# Coverage flags:
181
195
coverage_compile_flags = ["-fprofile-instr-generate" , "-fcoverage-mapping" ]
182
196
coverage_link_flags = ["-fprofile-instr-generate" ]
0 commit comments