@@ -73,9 +73,31 @@ def sort_deps(deps):
7373 other_deps = [x for x in deps if not x .startswith (":" )]
7474 return sorted (colon_deps ) + sorted (other_deps )
7575
76- def _clang_generator_flags (cc_ctx , cpp_toolchain , input_files_paths ):
76+ def _clang_generator_flags (ctx , cc_ctx , cpp_toolchain , input_files_paths ):
7777 flags = []
7878
79+ feature_configuration = cc_common .configure_features (
80+ ctx = ctx ,
81+ cc_toolchain = cpp_toolchain ,
82+ requested_features = ctx .features ,
83+ unsupported_features = ctx .disabled_features + ["module_maps" ],
84+ )
85+ compile_variables = cc_common .create_compile_variables (
86+ cc_toolchain = cpp_toolchain ,
87+ feature_configuration = feature_configuration ,
88+ )
89+ default_copts = cc_common .get_memory_inefficient_command_line (
90+ feature_configuration = feature_configuration ,
91+ action_name = "c++-compile" ,
92+ variables = compile_variables ,
93+ )
94+
95+ # Use the defines that would be used by the toolchain normally for C++ compilation.
96+ # Add them first so that they are overridden by the user's copts.
97+ for copt in default_copts :
98+ if copt .startswith ("-D" ):
99+ flags .append ("--extra-arg=" + copt )
100+
79101 # The gnu compiler is what frequently used in practice,
80102 # and it allows to use more langauge extensions (e.g. _Bool type in C).
81103 # However, compiling C code with -std=gnu++ does not work,
@@ -173,7 +195,7 @@ def _sapi_interface_impl(ctx):
173195
174196 if use_clang_generator :
175197 input_files += cpp_toolchain .all_files .to_list ()
176- extra_flags += _clang_generator_flags (cc_ctx , cpp_toolchain , input_files_paths )
198+ extra_flags += _clang_generator_flags (ctx , cc_ctx , cpp_toolchain , input_files_paths )
177199 else :
178200 append_all (extra_flags , "-D" , cc_ctx .defines .to_list ())
179201 append_all (extra_flags , "-isystem" , cc_ctx .system_includes .to_list ())
@@ -200,6 +222,7 @@ def _sapi_interface_impl(ctx):
200222# Build rule that generates SAPI interface.
201223sapi_interface = rule (
202224 implementation = _sapi_interface_impl ,
225+ fragments = ["cpp" ],
203226 attrs = {
204227 "out" : attr .output (mandatory = True ),
205228 "embed_dir" : attr .string (),
@@ -619,7 +642,7 @@ def _sandboxed_library_gen_impl(ctx):
619642 args .append ("--sapi_out={}" .format (ctx .attr .sapi_hdr ))
620643 args .append ("--sapi_limit_scan_depth" )
621644 input_files_paths = _lib_direct_headers (ctx .attr .lib , cc_ctx )
622- args += _clang_generator_flags (cc_ctx , cpp_toolchain , input_files_paths )
645+ args += _clang_generator_flags (ctx , cc_ctx , cpp_toolchain , input_files_paths )
623646 args += input_files_paths
624647
625648 progress_msg = "Generating sandboxed library {}." .format (ctx .attr .lib_name )
@@ -635,6 +658,7 @@ def _sandboxed_library_gen_impl(ctx):
635658# Build rule that generates SAPI interface.
636659_sandboxed_library_gen = rule (
637660 implementation = _sandboxed_library_gen_impl ,
661+ fragments = ["cpp" ],
638662 attrs = {
639663 "lib" : attr .label (providers = [CcInfo ]),
640664 "lib_name" : attr .string (),
0 commit comments