Skip to content

Commit

Permalink
Add Bazel's -bin output directory to the quote include paths search…
Browse files Browse the repository at this point in the history
…ed by ClangImporter.

genfiles_dir is already searched but is deprecated (bazelbuild/bazel#6761) and the C rules have been adding bin_dir to their quote include paths since June 2018, so we should catch up.

RELNOTES: Swift modules that import C modules can now find headers located in the bazel-bin directory.
PiperOrigin-RevId: 264958475
  • Loading branch information
allevato authored and swiple-rules-gardener committed Aug 23, 2019
1 parent 4401374 commit d45a8f6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions swift/internal/api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def _compile(
additional_inputs: A list of `File`s representing additional input files that need to be
passed to the Swift compile action because they are referenced by compiler flags.
bin_dir: The Bazel `*-bin` directory root. If provided, its path is used to store the cache
for modules precompiled by Swift's ClangImporter.
for modules precompiled by Swift's ClangImporter, and it is added to ClangImporter's
header search paths for compatibility with Bazel's C++ and Objective-C rules which
support includes of generated headers from that location.
copts: A list of compiler flags that apply to the target being built. These flags, along
with those from Bazel's Swift configuration fragment (i.e., `--swiftcopt` command line
flags) are scanned to determine whether whole module optimization is being requested,
Expand Down Expand Up @@ -559,6 +561,7 @@ def _compile(
# TODO(allevato): Make this argument a list of files instead.
additional_input_depsets = [depset(additional_inputs)],
args = args,
bin_dir = bin_dir,
copts = copts,
defines = defines,
deps = deps,
Expand Down Expand Up @@ -890,6 +893,7 @@ def _swiftc_command_line_and_inputs(
srcs,
toolchain,
additional_input_depsets = [],
bin_dir = None,
copts = [],
defines = [],
deps = [],
Expand Down Expand Up @@ -917,6 +921,10 @@ def _swiftc_command_line_and_inputs(
additional_input_depsets: A list of `depset`s of `File`s representing
additional input files that need to be passed to the Swift compile
action because they are referenced by compiler flags.
bin_dir: The Bazel `*-bin` directory root. If provided, its path is added
to ClangImporter's header search paths for compatibility with Bazel's
C++ and Objective-C rules which support inclusions of generated
headers from that location.
copts: A list (**not** an `Args` object) of compiler flags that apply to the
target being built. These flags, along with those from Bazel's Swift
configuration fragment (i.e., `--swiftcopt` command line flags) are
Expand Down Expand Up @@ -966,8 +974,10 @@ def _swiftc_command_line_and_inputs(
):
args.add("-enable-batch-mode")

# Add the genfiles directory to ClangImporter's header search paths for
# compatibility with rules that generate headers there.
# Add the bin and genfiles directories to ClangImporter's header search
# paths for compatibility with rules that generate headers there.
if bin_dir:
args.add_all(["-Xcc", "-iquote{}".format(bin_dir.path)])
if genfiles_dir:
args.add_all(["-Xcc", "-iquote{}".format(genfiles_dir.path)])

Expand Down

0 comments on commit d45a8f6

Please sign in to comment.