Skip to content

Commit 4a78528

Browse files
authored
bazel: roll compiler/linker options to toolchains (#15)
1 parent 9ab0609 commit 4a78528

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

.bazelrc

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
build --cxxopt=-std=c++17
2-
build --cxxopt=-O3
3-
build --cxxopt=-no-canonical-prefixes
4-
build --cxxopt=-DEMSCRIPTEN_PROTOBUF_LITE=1
5-
6-
# try to optimize un-used code
7-
build --cxxopt=-fdata-sections
8-
build --cxxopt=-ffunction-sections
9-
10-
build --linkopt=-Wl,--gc-sections
11-
121
# https://github.com/bazelbuild/bazel/issues/9451
132
# ideally we want this, but it doesn't work...
143
# build --cxxopt=-fno-canonical-system-headers
@@ -22,4 +11,4 @@ build --cpu=wasm
2211
# Use the default Bazel C++ toolchain to build the tools used during the
2312
# build.
2413

25-
build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
14+
build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

toolchain/cc_toolchain_config.bzl

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,63 @@ def _impl(ctx):
8989
],
9090
)
9191

92+
cxx17_feature = feature(
93+
name = "c++17",
94+
enabled = True,
95+
flag_sets = [
96+
flag_set(
97+
actions = [ACTION_NAMES.cpp_compile],
98+
flag_groups = [flag_group(flags = ["-std=c++17"])],
99+
),
100+
],
101+
)
102+
103+
no_canonical_prefixes_feature = feature(
104+
name = "no-canonical-prefixes",
105+
enabled = True,
106+
flag_sets = [
107+
flag_set(
108+
actions = [
109+
ACTION_NAMES.c_compile,
110+
ACTION_NAMES.cpp_compile,
111+
ACTION_NAMES.cpp_link_executable,
112+
ACTION_NAMES.cpp_link_dynamic_library,
113+
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
114+
],
115+
flag_groups = [
116+
flag_group(
117+
flags = [
118+
"-no-canonical-prefixes",
119+
],
120+
),
121+
],
122+
),
123+
],
124+
)
125+
126+
opt_feature = feature(
127+
name = "opt",
128+
enabled = True,
129+
flag_sets = [
130+
flag_set(
131+
actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile],
132+
flag_groups = [
133+
flag_group(
134+
flags = ["-O3", "-ffunction-sections", "-fdata-sections"],
135+
),
136+
],
137+
),
138+
flag_set(
139+
actions = [
140+
ACTION_NAMES.cpp_link_dynamic_library,
141+
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
142+
ACTION_NAMES.cpp_link_executable,
143+
],
144+
flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
145+
),
146+
],
147+
)
148+
92149
return cc_common.create_cc_toolchain_config_info(
93150
ctx = ctx,
94151
toolchain_identifier = "wasm-toolchain",
@@ -107,7 +164,7 @@ def _impl(ctx):
107164
"external/emscripten_toolchain/upstream/emscripten/system/include/libcxx",
108165
"external/emscripten_toolchain/upstream/emscripten/system/include/libc",
109166
],
110-
# features = [toolchain_include_directories_feature],
167+
features = [cxx17_feature, no_canonical_prefixes_feature, opt_feature],
111168
)
112169

113170
cc_toolchain_config = rule(

0 commit comments

Comments
 (0)