@@ -351,6 +351,7 @@ def _compile_as_objects(
351351 defines = [],
352352 deps = [],
353353 features = [],
354+ genfiles_dir = None ,
354355 objc_fragment = None ):
355356 """Compiles Swift source files into object files (and optionally a module).
356357
@@ -389,6 +390,10 @@ def _compile_as_objects(
389390 propagate one of the following providers: `SwiftClangModuleInfo`,
390391 `SwiftInfo`, `"cc"`, or `apple_common.Objc`.
391392 features: Features that are enabled on the target being compiled.
393+ genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its path
394+ is added to ClangImporter's header search paths for compatibility with
395+ Bazel's C++ and Objective-C rules which support inclusions of generated
396+ headers from that location.
392397 objc_fragment: The `objc` configuration fragment from Bazel. This must be
393398 provided if the toolchain supports Objective-C interop; if it does not,
394399 then this argument may be omitted.
@@ -453,6 +458,7 @@ def _compile_as_objects(
453458 defines = defines ,
454459 deps = deps ,
455460 features = features ,
461+ genfiles_dir = genfiles_dir ,
456462 objc_fragment = objc_fragment ,
457463 )
458464
@@ -531,6 +537,7 @@ def _compile_as_library(
531537 defines = [],
532538 deps = [],
533539 features = [],
540+ genfiles_dir = None ,
534541 library_name = None ,
535542 linkopts = [],
536543 objc_fragment = None ):
@@ -574,6 +581,10 @@ def _compile_as_library(
574581 propagate one of the following providers: `SwiftClangModuleInfo`,
575582 `SwiftInfo`, `"cc"`, or `apple_common.Objc`.
576583 features: Features that are enabled on the target being compiled.
584+ genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its path
585+ is added to ClangImporter's header search paths for compatibility with
586+ Bazel's C++ and Objective-C rules which support inclusions of generated
587+ headers from that location.
577588 library_name: The name that should be substituted for the string `{name}` in
578589 `lib{name}.a`, which will be the output of this compilation. If this is
579590 not specified or is falsy, then the default behavior is to simply use
@@ -686,6 +697,7 @@ def _compile_as_library(
686697 allow_testing = allow_testing ,
687698 configuration = configuration ,
688699 deps = deps ,
700+ genfiles_dir = genfiles_dir ,
689701 objc_fragment = objc_fragment ,
690702 )
691703
@@ -960,6 +972,7 @@ def _swiftc_command_line_and_inputs(
960972 defines = [],
961973 deps = [],
962974 features = [],
975+ genfiles_dir = None ,
963976 objc_fragment = None ):
964977 """Computes command line arguments and inputs needed to invoke `swiftc`.
965978
@@ -1001,6 +1014,10 @@ def _swiftc_command_line_and_inputs(
10011014 propagate one of the following providers: `SwiftClangModuleInfo`,
10021015 `SwiftInfo`, `"cc"`, or `apple_common.Objc`.
10031016 features: Features that are enabled on the target being compiled.
1017+ genfiles_dir: The Bazel `*-genfiles` directory root. If provided, its path
1018+ is added to ClangImporter's header search paths for compatibility with
1019+ Bazel's C++ and Objective-C rules which support inclusions of generated
1020+ headers from that location.
10041021 objc_fragment: The `objc` configuration fragment from Bazel. This must be
10051022 provided if the toolchain supports Objective-C interop; if it does not,
10061023 then this argument may be omitted.
@@ -1023,6 +1040,11 @@ def _swiftc_command_line_and_inputs(
10231040 args .add_all (_coverage_copts (configuration = configuration ))
10241041 args .add_all (_sanitizer_copts (features = features ))
10251042
1043+ # Add the genfiles directory to ClangImporter's header search paths for
1044+ # compatibility with rules that generate headers there.
1045+ if genfiles_dir :
1046+ args .add_all (["-iquote" , genfiles_dir .path ], before_each = "-Xcc" )
1047+
10261048 input_depsets = list (additional_input_depsets )
10271049 transitive_inputs = collect_transitive_compile_inputs (
10281050 args = args ,
0 commit comments