When only a single platform is configured, e.g.:
# gazelle:cc_platform linux x86_64 @platforms//os:linux
and then we guard an #include directive with a platform-specific macro:
#ifdef __linux__
#include "lib.h"
#endif
then we would expect:
cc_library(
name = "my_library",
srcs = ["my_library.cc"],
implementation_deps = select({
"@platforms//os:linux": [
":lib",
],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
)
but we get:
cc_library(
name = "my_library",
srcs = ["my_library.cc"],
implementation_deps = [":lib"],
visibility = ["//visibility:public"],
)
The reason is how ccLanguage.getFileInfo() classifies a header as platform-specific:
isPlatformSpecific := len(usedByPlatforms) != len(platformEnvs)
Because there's only one platform and #include "lib.h" is actually reachable by it, then the expression above effectively evaluates to:
isPlatformSpecific := 1 != 1 // false
However, even if a directive is reachable on all configured platforms, it doesn't mean it isn't platform-specific.
When only a single platform is configured, e.g.:
and then we guard an
#includedirective with a platform-specific macro:then we would expect:
but we get:
The reason is how
ccLanguage.getFileInfo()classifies a header as platform-specific:Because there's only one platform and
#include "lib.h"is actually reachable by it, then the expression above effectively evaluates to:However, even if a directive is reachable on all configured platforms, it doesn't mean it isn't platform-specific.