Allow `includes = ["."]`
For third-party libraries that are brought in via external repositories, includes = ["."] may actually be the desired behavior if they are only exporting a single cc_library target.
For example, see https://bazelbuild.slack.com/archives/CGA9QFQ8H/p1754145239223169 in which I wrote BUILD files for libxslt. The sources in that library import the headers as <libxslt/xslt.h> but also "xslt.h".
I originally had it working with the following target
cc_library(
name = "libxslt",
srcs = [
"config.h",
"libxslt/xsltconfig.h",
] + glob([
"libxslt/*.c",
"libxslt/*.h",
]),
includes = ["."],
deps = [
"@libxml2",
],
visibility = ["//visibility:public"],
)
Due to the ban of includes = ["."] I had to lower the target definition into the //libxslt package, which resulted in issues setting up the proper prefixes for the headers. I ended up resolving it by using copy_file targets for all the sources and headers to arrange them the way they expected to be arranged, but none of this would be necessary if we could specify this target at the repository root.
@hvadehra @comius
@pzembrod
Not much to add, mostly just looking to +1 this. I've also found this to be a fairly common issue when providing build files for external dependencies
I think includes "." translating literally to -I. could be problematic as the includes are viral (i.e. they get added to all things which depend on this, but the . is not resolved).
I think you could achieve the same behavior by using a combination of strip_include_prefix and/or include_prefix to set this up via the virtual header symlink tree.
I ran into this, too, so came by to +1 this. Part of what makes the error annoying is that the workspace root is already added to the include search paths.
use strip_include_prefix, include_prefix
Feels rather awkward, but yeah, something like this should work?
# File: foo/BUILD
cc_library(
name = "foo",
strip_include_prefix = "/foo/",
include_prefix = "foo/"
)
use strip_include_prefix, include_prefix
Feels rather awkward, but yeah, something like this should work?
# File: foo/BUILD cc_library( name = "foo", strip_include_prefix = "/foo/", include_prefix = "foo/" )
I had tried that originally before settling on the "copy files" approach but it didn't quite work for the libxslr case that motivated this report, though I don't recall the details unfortunately.
So I don't think we want to allow literal -I. on the command-line, but if the [strip_]include_prefix combo worked I think we'd be open to making that easier to spell such that this would work in spirit.