Skip to content

Commit d046ed4

Browse files
authored
Make toolchain selfcontained (#28)
* Make toolchain selfcontained Multiarch builds need --copts and such to not be crutial, or be the same on all platforms. Given we need to support running on Windows, OSX and Linux, those won't work. Instead, push all those flags into the crosstool. If we want to be configurable here, we can take arguments in the WORKSPACE file to tweak the crosstool instead. Signed-off-by: Austin Schuh <[email protected]> * Address comments and add feature for PJ * Really move werror over --------- Signed-off-by: Austin Schuh <[email protected]>
1 parent 48c959a commit d046ed4

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

toolchains/cross_compiler/cc-toolchain-config.bzl

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def _impl(ctx):
2020
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
2121
]
2222

23+
lto_index_actions = [
24+
ACTION_NAMES.lto_index_for_executable,
25+
ACTION_NAMES.lto_index_for_dynamic_library,
26+
ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
27+
]
28+
2329
all_compile_actions = [
2430
ACTION_NAMES.c_compile,
2531
ACTION_NAMES.cpp_compile,
@@ -86,7 +92,7 @@ def _impl(ctx):
8692
enabled = True,
8793
flag_sets = [
8894
flag_set(
89-
actions = all_link_actions,
95+
actions = all_link_actions + lto_index_actions,
9096
flag_groups = ([
9197
flag_group(
9298
flags = ([
@@ -98,6 +104,9 @@ def _impl(ctx):
98104
"-lstdc++",
99105
"-lm",
100106
"-fno-canonical-system-headers",
107+
"-rdynamic",
108+
"-ldl",
109+
"-Wl,-rpath,'$ORIGIN'",
101110
],
102111
),
103112
]),
@@ -137,6 +146,7 @@ def _impl(ctx):
137146
"-fstack-protector",
138147
"-Wall",
139148
"-fno-omit-frame-pointer",
149+
"-Wextra",
140150
],
141151
),
142152
]),
@@ -175,13 +185,34 @@ def _impl(ctx):
175185
),
176186
flag_set(
177187
actions = [ACTION_NAMES.c_compile],
178-
flag_groups = [],
188+
flag_groups = ([
189+
flag_group(
190+
flags = [
191+
"-Wformat=2",
192+
"-pedantic",
193+
"-Wno-psabi",
194+
"-Wno-unused-parameter",
195+
"-fPIC",
196+
"-pthread",
197+
],
198+
),
199+
]),
179200
),
180201
flag_set(
181202
actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend],
182203
flag_groups = ([
183204
flag_group(
184-
flags = ["-std=c++20"],
205+
flags = [
206+
"-std=c++20",
207+
"-Wno-error=deprecated-declarations",
208+
"-Wno-deprecated-enum-enum-conversion",
209+
"-Wformat=2",
210+
"-pedantic",
211+
"-Wno-psabi",
212+
"-Wno-unused-parameter",
213+
"-fPIC",
214+
"-pthread",
215+
],
185216
),
186217
]),
187218
),
@@ -209,6 +240,24 @@ def _impl(ctx):
209240

210241
compiler_param_feature = feature(
211242
name = "compiler_param_file",
243+
enabled = True,
244+
)
245+
246+
treat_warnings_as_errors_feature = feature(
247+
name = "treat_warnings_as_errors",
248+
enabled = True,
249+
flag_sets = [
250+
flag_set(
251+
actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
252+
flag_groups = [flag_group(flags = ["-Werror"])],
253+
),
254+
flag_set(
255+
actions = all_link_actions,
256+
flag_groups = [flag_group(
257+
flags = ["-Wl,-fatal-warnings"],
258+
)],
259+
),
260+
],
212261
)
213262

214263
archive_param_file_feature = feature(
@@ -243,10 +292,31 @@ def _impl(ctx):
243292

244293
opt_feature = feature(name = "opt")
245294

295+
set_install_name_feature = feature(
296+
name = "set_soname",
297+
flag_sets = [
298+
flag_set(
299+
actions = [
300+
ACTION_NAMES.cpp_link_dynamic_library,
301+
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
302+
],
303+
flag_groups = [
304+
flag_group(
305+
flags = [
306+
"-Wl,-soname,%{runtime_solib_name}",
307+
],
308+
expand_if_available = "runtime_solib_name",
309+
),
310+
],
311+
),
312+
],
313+
)
314+
246315
features += [
247316
unfiltered_compile_flags_feature,
248317
default_link_flags_feature,
249318
default_compile_flags_feature,
319+
treat_warnings_as_errors_feature,
250320
sysroot_feature,
251321
dbg_feature,
252322
opt_feature,
@@ -255,6 +325,7 @@ def _impl(ctx):
255325
gcc_quoting_for_param_files_feature,
256326
static_link_cpp_runtimes_feature,
257327
archive_param_file_feature,
328+
set_install_name_feature,
258329
]
259330

260331
return cc_common.create_cc_toolchain_config_info(

0 commit comments

Comments
 (0)